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(docstring const & name, int m, int n)
32 : InsetMathGrid(m, n), name_(name)
36 InsetMathArray::InsetMathArray(docstring const & name, int m, int n,
37 char valign, docstring const & halign)
38 : InsetMathGrid(m, n, valign, halign), name_(name)
42 InsetMathArray::InsetMathArray(docstring const & name, docstring const & str)
43 : InsetMathGrid(1, 1), name_(name)
45 vector< vector<string> > dat;
46 istringstream is(to_utf8(str));
48 while (getline(is, line)) {
49 istringstream ls(line);
50 typedef istream_iterator<string> iter;
51 vector<string> v = vector<string>(iter(ls), iter());
56 for (row_type row = 1; row < dat.size(); ++row)
58 for (col_type col = 1; col < dat[0].size(); ++col)
60 for (row_type row = 0; row < dat.size(); ++row)
61 for (col_type col = 0; col < dat[0].size(); ++col)
62 mathed_parse_cell(cell(index(row, col)), from_utf8(dat[row][col]));
66 Inset * InsetMathArray::clone() const
68 return new InsetMathArray(*this);
72 void InsetMathArray::metrics(MetricsInfo & mi, Dimension & dim) const
74 ArrayChanger dummy(mi.base);
75 InsetMathGrid::metrics(mi, dim);
80 Dimension const InsetMathArray::dimension(BufferView const & bv) const
82 Dimension dim = InsetMathGrid::dimension(bv);
88 void InsetMathArray::draw(PainterInfo & pi, int x, int y) const
90 setPosCache(pi, x, y);
91 ArrayChanger dummy(pi.base);
92 InsetMathGrid::drawWithMargin(pi, x, y, 4, 2);
96 void InsetMathArray::write(WriteStream & os) const
98 bool brace = os.pendingBrace();
99 os.pendingBrace(false);
100 if (os.latex() && os.textMode()) {
101 os << "\\ensuremath{";
108 os << "\\begin{" << name_ << '}';
110 char const v = verticalAlignment();
111 if (v == 't' || v == 'b')
112 os << '[' << v << ']';
113 os << '{' << horizontalAlignments() << "}\n";
115 InsetMathGrid::write(os);
119 os << "\\end{" << name_ << '}';
120 // adding a \n here is bad if the array is the last item
121 // in an \eqnarray...
123 os.pendingBrace(brace);
127 void InsetMathArray::infoize(odocstream & os) const
129 docstring name = name_;
130 name[0] = support::uppercase(name[0]);
135 void InsetMathArray::normalize(NormalStream & os) const
137 os << '[' << name_ << ' ';
138 InsetMathGrid::normalize(os);
143 void InsetMathArray::maple(MapleStream & os) const
146 InsetMathGrid::maple(os);
151 void InsetMathArray::validate(LaTeXFeatures & features) const
153 if (name_ == "subarray")
154 features.require("amsmath");
155 InsetMathGrid::validate(features);