2001-12-05 08:04:20 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "math_arrayinset.h"
|
2001-11-07 13:15:59 +00:00
|
|
|
#include "math_parser.h"
|
2001-11-08 12:06:56 +00:00
|
|
|
#include "math_mathmlstream.h"
|
2002-08-02 14:04:16 +00:00
|
|
|
#include "math_metricsinfo.h"
|
2001-12-05 08:04:20 +00:00
|
|
|
#include "math_streamstr.h"
|
2001-11-09 08:35:57 +00:00
|
|
|
#include "Lsstream.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-12-05 08:04:20 +00:00
|
|
|
#include <iterator>
|
|
|
|
|
2001-11-08 06:42:20 +00:00
|
|
|
using std::vector;
|
2001-11-09 08:35:57 +00:00
|
|
|
using std::istringstream;
|
2001-11-20 16:05:17 +00:00
|
|
|
using std::getline;
|
2002-02-16 15:59:55 +00:00
|
|
|
using std::istream_iterator;
|
2001-11-08 06:42:20 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2002-02-14 14:52:23 +00:00
|
|
|
MathArrayInset::MathArrayInset(string const & name, int m, int n)
|
|
|
|
: MathGridInset(m, n), name_(name)
|
2001-06-25 00:06:33 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2002-02-14 14:52:23 +00:00
|
|
|
MathArrayInset::MathArrayInset(string const & name, int m, int n,
|
|
|
|
char valign, string const & halign)
|
|
|
|
: MathGridInset(m, n, valign, halign), name_(name)
|
2001-10-12 12:02:49 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2002-02-14 14:52:23 +00:00
|
|
|
MathArrayInset::MathArrayInset(string const & name, char valign,
|
|
|
|
string const & halign)
|
|
|
|
: MathGridInset(valign, halign), name_(name)
|
2001-11-28 13:09:40 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2002-02-14 14:52:23 +00:00
|
|
|
MathArrayInset::MathArrayInset(string const & name, string const & str)
|
|
|
|
: MathGridInset(1, 1), name_(name)
|
2001-11-07 13:15:59 +00:00
|
|
|
{
|
|
|
|
vector< vector<string> > dat;
|
2001-11-08 15:12:33 +00:00
|
|
|
istringstream is(str.c_str());
|
2002-04-26 06:13:30 +00:00
|
|
|
string line;
|
|
|
|
while (getline(is, line)) {
|
2001-11-08 15:12:33 +00:00
|
|
|
istringstream ls(line.c_str());
|
2002-02-16 15:59:55 +00:00
|
|
|
typedef istream_iterator<string> iter;
|
2001-11-07 13:15:59 +00:00
|
|
|
vector<string> v = vector<string>(iter(ls), iter());
|
|
|
|
if (v.size())
|
|
|
|
dat.push_back(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (row_type row = 1; row < dat.size(); ++row)
|
|
|
|
addRow(0);
|
|
|
|
for (col_type col = 1; col < dat[0].size(); ++col)
|
|
|
|
addCol(0);
|
|
|
|
for (row_type row = 0; row < dat.size(); ++row)
|
2002-04-25 05:58:55 +00:00
|
|
|
for (col_type col = 0; col < dat[0].size(); ++col)
|
2001-11-07 13:15:59 +00:00
|
|
|
mathed_parse_cell(cell(index(row, col)), dat[row][col]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
MathInset * MathArrayInset::clone() const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
return new MathArrayInset(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-30 07:09:54 +00:00
|
|
|
void MathArrayInset::metrics(MathMetricsInfo & mi) const
|
2001-11-09 08:35:57 +00:00
|
|
|
{
|
2002-05-30 07:09:54 +00:00
|
|
|
MathMetricsInfo m = mi;
|
|
|
|
if (m.base.style == LM_ST_DISPLAY)
|
|
|
|
m.base.style = LM_ST_TEXT;
|
|
|
|
MathGridInset::metrics(m);
|
2001-11-09 08:35:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathArrayInset::write(WriteStream & os) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-12-03 16:24:50 +00:00
|
|
|
if (os.fragile())
|
2001-06-25 00:06:33 +00:00
|
|
|
os << "\\protect";
|
2002-02-14 14:52:23 +00:00
|
|
|
os << "\\begin{" << name_ << "}";
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2002-03-21 17:42:56 +00:00
|
|
|
if (v_align_ == 't' || v_align_ == 'b')
|
2001-06-25 00:06:33 +00:00
|
|
|
os << '[' << char(v_align_) << ']';
|
2001-12-05 08:04:20 +00:00
|
|
|
os << '{' << halign() << "}\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-10-19 11:25:48 +00:00
|
|
|
MathGridInset::write(os);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-12-03 16:24:50 +00:00
|
|
|
if (os.fragile())
|
2001-06-25 00:06:33 +00:00
|
|
|
os << "\\protect";
|
2002-09-25 12:49:55 +00:00
|
|
|
os << "\\end{" << name_ << "}";
|
|
|
|
// adding a \n here is bad if the array is the last item
|
|
|
|
// in an \eqnarray...
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
2001-09-10 09:35:12 +00:00
|
|
|
|
|
|
|
|
2001-11-09 08:35:57 +00:00
|
|
|
void MathArrayInset::normalize(NormalStream & os) const
|
2001-11-07 08:51:35 +00:00
|
|
|
{
|
2002-02-14 14:52:23 +00:00
|
|
|
os << "[" << name_ << " ";
|
2001-11-09 08:35:57 +00:00
|
|
|
MathGridInset::normalize(os);
|
2001-11-07 08:51:35 +00:00
|
|
|
os << "]";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-09 08:35:57 +00:00
|
|
|
void MathArrayInset::maplize(MapleStream & os) const
|
2001-09-10 09:35:12 +00:00
|
|
|
{
|
2001-11-09 08:35:57 +00:00
|
|
|
os << "array(";
|
|
|
|
MathGridInset::maplize(os);
|
|
|
|
os << ")";
|
2001-09-10 09:35:12 +00:00
|
|
|
}
|