2 * \file InsetMathMatrix.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 "InsetMathMatrix.h"
15 #include "MathStream.h"
17 #include "support/convert.h"
23 InsetMathMatrix::InsetMathMatrix(InsetMathGrid const & p,
24 docstring const & left, docstring const & right)
25 : InsetMathGrid(p), left_(left), right_(right)
29 Inset * InsetMathMatrix::clone() const
31 return new InsetMathMatrix(*this);
35 void InsetMathMatrix::write(TeXMathStream & os) const
37 InsetMathGrid::write(os);
41 void InsetMathMatrix::normalize(NormalStream & os) const
43 InsetMathGrid::normalize(os);
47 void InsetMathMatrix::maple(MapleStream & os) const
49 os << "matrix(" << int(nrows()) << ',' << int(ncols()) << ",[";
50 for (idx_type idx = 0; idx < nargs(); ++idx) {
59 void InsetMathMatrix::maxima(MaximaStream & os) const
62 for (row_type row = 0; row < nrows(); ++row) {
66 for (col_type col = 0; col < ncols(); ++col) {
69 os << cell(index(row, col));
77 void InsetMathMatrix::mathematica(MathematicaStream & os) const
80 for (row_type row = 0; row < nrows(); ++row) {
84 for (col_type col = 0; col < ncols(); ++col) {
87 os << cell(index(row, col));
95 void InsetMathMatrix::mathmlize(MathMLStream & ms) const
97 // lspace='3/18em', but fractions are not allowed.
98 ms << MTagInline("mo", "form='prefix' fence='true' stretchy='true' symmetric='true' lspace='0.1666em'")
99 << convertDelimToXMLEscape(left_)
102 for (row_type row = 0; row < nrows(); ++row) {
104 for (col_type col = 0; col < ncols(); ++col) {
105 idx_type const i = index(row, col);
106 if (cellinfo(i).multi != CELL_PART_OF_MULTICOLUMN) {
107 col_type const cellcols = ncellcols(i);
110 attr << "columnspan='" << cellcols << '\'';
111 ms << MTag("mtd", attr.str()) << cell(i) << ETag("mtd");
117 << MTagInline("mo", "form='postfix' fence='true' stretchy='true' symmetric='true' lspace='0.1666em'")
118 << convertDelimToXMLEscape(right_)
123 void InsetMathMatrix::htmlize(HtmlStream & os) const
125 os << MTag("table", "class='matrix'") << '\n';
127 // we do not print the delimiters but instead try to hack them
128 string const rows = convert<string>(nrows());
129 string const lattrib =
130 "class='ldelim' rowspan='" + rows + "'";
131 string const rattrib =
132 "class='rdelim' rowspan='" + rows + "'";
134 for (row_type row = 0; row < nrows(); ++row) {
135 os << MTag("tr") << '\n';
137 os << MTag("td", lattrib) << ETag("td") << '\n';
138 for (col_type col = 0; col < ncols(); ++col) {
139 idx_type const i = index(row, col);
140 if (cellinfo(i).multi != CELL_PART_OF_MULTICOLUMN) {
141 col_type const cellcols = ncellcols(i);
144 attr << "colspan='" << cellcols
146 os << MTag("td", attr.str()) << cell(i)
147 << ETag("td") << '\n';
151 os << MTag("td", rattrib) << ETag("td") << '\n';
152 os << ETag("tr") << '\n';
154 os << ETag("table") << '\n';
158 void InsetMathMatrix::octave(OctaveStream & os) const
161 for (row_type row = 0; row < nrows(); ++row) {
165 for (col_type col = 0; col < ncols(); ++col)
166 os << cell(index(row, col)) << ' ';