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 "LaTeXFeatures.h"
14 #include "InsetMathArray.h"
16 #include "MathParser.h"
17 #include "MathStream.h"
19 #include "support/lstrings.h"
28 using std::istringstream;
29 using std::istream_iterator;
34 InsetMathArray::InsetMathArray(docstring const & name, int m, int n)
35 : InsetMathGrid(m, n), name_(name)
39 InsetMathArray::InsetMathArray(docstring const & name, int m, int n,
40 char valign, docstring const & halign)
41 : InsetMathGrid(m, n, valign, halign), name_(name)
45 InsetMathArray::InsetMathArray(docstring const & name, char valign,
46 docstring const & halign)
47 : InsetMathGrid(valign, halign), name_(name)
51 InsetMathArray::InsetMathArray(docstring const & name, docstring const & str)
52 : InsetMathGrid(1, 1), name_(name)
54 vector< vector<string> > dat;
55 istringstream is(to_utf8(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)), from_utf8(dat[row][col]));
75 Inset * InsetMathArray::clone() const
77 return new InsetMathArray(*this);
81 bool InsetMathArray::metrics(MetricsInfo & mi, Dimension & dim) const
83 ArrayChanger dummy(mi.base);
84 InsetMathGrid::metrics(mi, dim);
86 bool const changed = dim_ != dim;
92 void InsetMathArray::draw(PainterInfo & pi, int x, int y) const
94 setPosCache(pi, x, y);
95 ArrayChanger dummy(pi.base);
96 InsetMathGrid::drawWithMargin(pi, x, y, 4, 2);
100 void InsetMathArray::write(WriteStream & os) const
104 os << "\\begin{" << name_ << '}';
106 if (v_align_ == 't' || v_align_ == 'b')
107 os << '[' << char(v_align_) << ']';
108 os << '{' << halign() << "}\n";
110 InsetMathGrid::write(os);
114 os << "\\end{" << name_ << '}';
115 // adding a \n here is bad if the array is the last item
116 // in an \eqnarray...
120 void InsetMathArray::infoize(odocstream & os) const
122 docstring name = name_;
123 name[0] = support::uppercase(name[0]);
128 void InsetMathArray::normalize(NormalStream & os) const
130 os << '[' << name_ << ' ';
131 InsetMathGrid::normalize(os);
136 void InsetMathArray::maple(MapleStream & os) const
139 InsetMathGrid::maple(os);
144 void InsetMathArray::validate(LaTeXFeatures & features) const
146 if (name_ == "subarray")
147 features.require("amsmath");
148 InsetMathGrid::validate(features);