2 * \file InsetMathArray.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 "InsetMathArray.h"
16 #include "MathParser.h"
17 #include "MathMLStream.h"
18 #include "MathStream.h"
20 #include "support/lstrings.h"
29 using std::istringstream;
30 using std::istream_iterator;
34 InsetMathArray::InsetMathArray(string const & name, int m, int n)
35 : InsetMathGrid(m, n), name_(name)
39 InsetMathArray::InsetMathArray(string const & name, int m, int n,
40 char valign, string const & halign)
41 : InsetMathGrid(m, n, valign, halign), name_(name)
45 InsetMathArray::InsetMathArray(string const & name, char valign,
46 string const & halign)
47 : InsetMathGrid(valign, halign), name_(name)
51 InsetMathArray::InsetMathArray(string const & name, string const & str)
52 : InsetMathGrid(1, 1), name_(name)
54 vector< vector<string> > dat;
55 istringstream is(str);
57 while (getline(is, line)) {
58 istringstream ls(line);
59 typedef istream_iterator<string> iter;
60 vector<string> v = vector<string>(iter(ls), iter());
65 for (row_type row = 1; row < dat.size(); ++row)
67 for (col_type col = 1; col < dat[0].size(); ++col)
69 for (row_type row = 0; row < dat.size(); ++row)
70 for (col_type col = 0; col < dat[0].size(); ++col)
71 mathed_parse_cell(cell(index(row, col)), dat[row][col]);
75 auto_ptr<InsetBase> InsetMathArray::doClone() const
77 return auto_ptr<InsetBase>(new InsetMathArray(*this));
81 void InsetMathArray::metrics(MetricsInfo & mi, Dimension & dim) const
83 ArrayChanger dummy(mi.base);
84 InsetMathGrid::metrics(mi, dim);
90 void InsetMathArray::draw(PainterInfo & pi, int x, int y) const
92 setPosCache(pi, x, y);
93 ArrayChanger dummy(pi.base);
94 InsetMathGrid::drawWithMargin(pi, x, y, 4, 2);
98 void InsetMathArray::write(WriteStream & os) const
102 os << "\\begin{" << name_ << '}';
104 if (v_align_ == 't' || v_align_ == 'b')
105 os << '[' << char(v_align_) << ']';
106 os << '{' << halign() << "}\n";
108 InsetMathGrid::write(os);
112 os << "\\end{" << name_ << '}';
113 // adding a \n here is bad if the array is the last item
114 // in an \eqnarray...
118 void InsetMathArray::infoize(std::ostream & os) const
121 name[0] = lyx::support::uppercase(name[0]);
126 void InsetMathArray::normalize(NormalStream & os) const
128 os << '[' << name_ << ' ';
129 InsetMathGrid::normalize(os);
134 void InsetMathArray::maple(MapleStream & os) const
137 InsetMathGrid::maple(os);
142 void InsetMathArray::validate(LaTeXFeatures & features) const
144 if (name_ == "subarray")
145 features.require("amsmath");
146 InsetMathGrid::validate(features);