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 MathEnsurer ensurer(os);
102 os << "\\begin{" << name_ << '}';
104 char const v = verticalAlignment();
105 if (v == 't' || v == 'b')
106 os << '[' << v << ']';
107 os << '{' << horizontalAlignments() << "}\n";
109 InsetMathGrid::write(os);
113 os << "\\end{" << name_ << '}';
114 // adding a \n here is bad if the array is the last item
115 // in an \eqnarray...
119 void InsetMathArray::infoize(odocstream & os) const
121 docstring name = name_;
122 name[0] = support::uppercase(name[0]);
127 void InsetMathArray::normalize(NormalStream & os) const
129 os << '[' << name_ << ' ';
130 InsetMathGrid::normalize(os);
135 void InsetMathArray::maple(MapleStream & os) const
138 InsetMathGrid::maple(os);
143 void InsetMathArray::validate(LaTeXFeatures & features) const
145 if (name_ == "subarray")
146 features.require("amsmath");
147 InsetMathGrid::validate(features);