2 * \file math_arrayinset.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "LaTeXFeatures.h"
14 #include "math_arrayinset.h"
15 #include "math_data.h"
16 #include "math_parser.h"
17 #include "math_mathmlstream.h"
18 #include "math_streamstr.h"
27 using std::istringstream;
28 using std::istream_iterator;
32 MathArrayInset::MathArrayInset(string const & name, int m, int n)
33 : MathGridInset(m, n), name_(name)
37 MathArrayInset::MathArrayInset(string const & name, int m, int n,
38 char valign, string const & halign)
39 : MathGridInset(m, n, valign, halign), name_(name)
43 MathArrayInset::MathArrayInset(string const & name, char valign,
44 string const & halign)
45 : MathGridInset(valign, halign), name_(name)
49 MathArrayInset::MathArrayInset(string const & name, string const & str)
50 : MathGridInset(1, 1), name_(name)
52 vector< vector<string> > dat;
53 istringstream is(str);
55 while (getline(is, line)) {
56 istringstream ls(line);
57 typedef istream_iterator<string> iter;
58 vector<string> v = vector<string>(iter(ls), iter());
63 for (row_type row = 1; row < dat.size(); ++row)
65 for (col_type col = 1; col < dat[0].size(); ++col)
67 for (row_type row = 0; row < dat.size(); ++row)
68 for (col_type col = 0; col < dat[0].size(); ++col)
69 mathed_parse_cell(cell(index(row, col)), dat[row][col]);
73 auto_ptr<InsetBase> MathArrayInset::doClone() const
75 return auto_ptr<InsetBase>(new MathArrayInset(*this));
79 void MathArrayInset::metrics(MetricsInfo & mi, Dimension & dim) const
81 ArrayChanger dummy(mi.base);
82 MathGridInset::metrics(mi, dim);
86 void MathArrayInset::draw(PainterInfo & pi, int x, int y) const
88 setPosCache(pi, x, y);
89 ArrayChanger dummy(pi.base);
90 MathGridInset::draw(pi, x + 1, y);
94 void MathArrayInset::write(WriteStream & os) const
98 os << "\\begin{" << name_ << '}';
100 if (v_align_ == 't' || v_align_ == 'b')
101 os << '[' << char(v_align_) << ']';
102 os << '{' << halign() << "}\n";
104 MathGridInset::write(os);
108 os << "\\end{" << name_ << '}';
109 // adding a \n here is bad if the array is the last item
110 // in an \eqnarray...
114 void MathArrayInset::infoize(std::ostream & os) const
120 void MathArrayInset::normalize(NormalStream & os) const
122 os << '[' << name_ << ' ';
123 MathGridInset::normalize(os);
128 void MathArrayInset::maple(MapleStream & os) const
131 MathGridInset::maple(os);
136 void MathArrayInset::validate(LaTeXFeatures & features) const
138 if (name_ == "subarray")
139 features.require("amsmath");
140 MathGridInset::validate(features);