2 * \file InsetMathArray.cpp
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 "InsetMathArray.h"
15 #include "LaTeXFeatures.h"
17 #include "MathParser.h"
18 #include "MathStream.h"
19 #include "MetricsInfo.h"
21 #include "support/lstrings.h"
31 InsetMathArray::InsetMathArray(Buffer * buf, docstring const & name, int m,
33 : InsetMathGrid(buf, m, n), name_(name)
37 InsetMathArray::InsetMathArray(Buffer * buf, docstring const & name, int m,
38 int n, char valign, docstring const & halign)
39 : InsetMathGrid(buf, m, n, valign, halign), name_(name)
43 InsetMathArray::InsetMathArray(Buffer * buf, docstring const & name,
44 docstring const & str)
45 : InsetMathGrid(buf, 1, 1), name_(name)
47 vector< vector<string> > dat;
48 istringstream is(to_utf8(str));
50 while (getline(is, line)) {
51 istringstream ls(line);
52 typedef istream_iterator<string> iter;
53 vector<string> v = vector<string>(iter(ls), iter());
58 for (row_type row = 1; row < dat.size(); ++row)
60 for (col_type col = 1; col < dat[0].size(); ++col)
62 for (row_type row = 0; row < dat.size(); ++row)
63 for (col_type col = 0; col < dat[0].size(); ++col)
64 mathed_parse_cell(cell(index(row, col)),
65 from_utf8(dat[row][col]), Parse::NORMAL);
69 Inset * InsetMathArray::clone() const
71 return new InsetMathArray(*this);
75 void InsetMathArray::metrics(MetricsInfo & mi, Dimension & dim) const
78 mi.base.changeStyle(LM_ST_TEXT, mi.base.style == LM_ST_DISPLAY);
79 InsetMathGrid::metrics(mi, dim);
83 void InsetMathArray::draw(PainterInfo & pi, int x, int y) const
85 setPosCache(pi, x, y);
87 pi.base.changeStyle(LM_ST_TEXT, pi.base.style == LM_ST_DISPLAY);
88 InsetMathGrid::draw(pi, x, y);
92 void InsetMathArray::write(WriteStream & os) const
94 MathEnsurer ensurer(os);
98 os << "\\begin{" << name_ << '}';
99 bool open = os.startOuterRow();
101 char const v = verticalAlignment();
102 if (v == 't' || v == 'b')
103 os << '[' << v << ']';
104 os << '{' << horizontalAlignments() << "}\n";
106 InsetMathGrid::write(os);
110 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(odocstream & os) const
120 docstring name = name_;
121 name[0] = 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);