2003-08-19 13:00:56 +00:00
|
|
|
/**
|
2007-04-25 03:01:35 +00:00
|
|
|
* \file InsetMathMatrix.cpp
|
2003-08-19 13:00:56 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author André Pönitz
|
2003-08-19 13:00:56 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "InsetMathMatrix.h"
|
2007-04-26 16:05:57 +00:00
|
|
|
#include "MathData.h"
|
2006-10-22 10:15:23 +00:00
|
|
|
#include "MathStream.h"
|
2001-11-09 08:35:57 +00:00
|
|
|
|
2010-03-31 19:59:09 +00:00
|
|
|
#include "support/convert.h"
|
|
|
|
|
|
|
|
using namespace std;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
2017-07-03 17:53:14 +00:00
|
|
|
InsetMathMatrix::InsetMathMatrix(InsetMathGrid const & p,
|
2009-12-16 17:01:09 +00:00
|
|
|
docstring const & left, docstring const & right)
|
|
|
|
: InsetMathGrid(p), left_(left), right_(right)
|
2001-11-09 08:35:57 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2007-08-30 18:03:17 +00:00
|
|
|
Inset * InsetMathMatrix::clone() const
|
2001-11-09 08:35:57 +00:00
|
|
|
{
|
2007-08-30 18:03:17 +00:00
|
|
|
return new InsetMathMatrix(*this);
|
2001-11-09 08:35:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-26 19:04:36 +00:00
|
|
|
void InsetMathMatrix::write(TeXMathStream & os) const
|
2001-11-09 08:35:57 +00:00
|
|
|
{
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::write(os);
|
2001-11-09 08:35:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathMatrix::normalize(NormalStream & os) const
|
2001-11-09 08:35:57 +00:00
|
|
|
{
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::normalize(os);
|
2001-11-09 08:35:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathMatrix::maple(MapleStream & os) const
|
2001-11-09 08:35:57 +00:00
|
|
|
{
|
|
|
|
os << "matrix(" << int(nrows()) << ',' << int(ncols()) << ",[";
|
|
|
|
for (idx_type idx = 0; idx < nargs(); ++idx) {
|
|
|
|
if (idx)
|
|
|
|
os << ',';
|
|
|
|
os << cell(idx);
|
|
|
|
}
|
|
|
|
os << "])";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathMatrix::maxima(MaximaStream & os) const
|
2002-10-28 17:15:19 +00:00
|
|
|
{
|
|
|
|
os << "matrix(";
|
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
|
|
|
if (row)
|
|
|
|
os << ',';
|
|
|
|
os << '[';
|
|
|
|
for (col_type col = 0; col < ncols(); ++col) {
|
|
|
|
if (col)
|
|
|
|
os << ',';
|
|
|
|
os << cell(index(row, col));
|
|
|
|
}
|
|
|
|
os << ']';
|
|
|
|
}
|
|
|
|
os << ')';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathMatrix::mathematica(MathematicaStream & os) const
|
2006-09-02 01:57:36 +00:00
|
|
|
{
|
|
|
|
os << '{';
|
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
|
|
|
if (row)
|
|
|
|
os << ',';
|
|
|
|
os << '{';
|
|
|
|
for (col_type col = 0; col < ncols(); ++col) {
|
|
|
|
if (col)
|
|
|
|
os << ',';
|
|
|
|
os << cell(index(row, col));
|
|
|
|
}
|
|
|
|
os << '}';
|
|
|
|
}
|
|
|
|
os << '}';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-26 19:02:46 +00:00
|
|
|
void InsetMathMatrix::mathmlize(MathMLStream & ms) const
|
2001-11-09 08:35:57 +00:00
|
|
|
{
|
2023-01-20 01:21:27 +00:00
|
|
|
// lspace='3/18em', but fractions are not allowed.
|
|
|
|
ms << MTagInline("mo", "form='prefix' fence='true' stretchy='true' symmetric='true' lspace='0.1666em'")
|
2022-12-23 01:16:08 +00:00
|
|
|
<< convertDelimToXMLEscape(left_)
|
2023-01-20 01:21:27 +00:00
|
|
|
<< ETagInline("mo")
|
2016-06-30 02:52:27 +00:00
|
|
|
<< MTag("mtable");
|
2009-12-16 16:43:26 +00:00
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
2019-05-09 23:52:07 +00:00
|
|
|
ms << MTag("mtr");
|
2015-05-17 11:43:37 +00:00
|
|
|
for (col_type col = 0; col < ncols(); ++col) {
|
|
|
|
idx_type const i = index(row, col);
|
2019-07-14 15:18:56 +00:00
|
|
|
if (cellinfo(i).multi != CELL_PART_OF_MULTICOLUMN) {
|
2015-05-17 11:43:37 +00:00
|
|
|
col_type const cellcols = ncellcols(i);
|
|
|
|
ostringstream attr;
|
|
|
|
if (cellcols > 1)
|
|
|
|
attr << "columnspan='" << cellcols << '\'';
|
2019-05-09 23:52:07 +00:00
|
|
|
ms << MTag("mtd", attr.str()) << cell(i) << ETag("mtd");
|
2015-05-17 11:43:37 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-09 23:52:07 +00:00
|
|
|
ms << ETag("mtr");
|
2009-12-16 16:43:26 +00:00
|
|
|
}
|
2019-05-09 23:52:07 +00:00
|
|
|
ms << ETag("mtable")
|
2023-01-20 01:21:27 +00:00
|
|
|
<< MTagInline("mo", "form='postfix' fence='true' stretchy='true' symmetric='true' lspace='0.1666em'")
|
2022-12-23 01:16:08 +00:00
|
|
|
<< convertDelimToXMLEscape(right_)
|
2023-01-20 01:21:27 +00:00
|
|
|
<< ETagInline("mo");
|
2001-11-09 08:35:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-31 19:59:09 +00:00
|
|
|
void InsetMathMatrix::htmlize(HtmlStream & os) const
|
|
|
|
{
|
|
|
|
os << MTag("table", "class='matrix'") << '\n';
|
|
|
|
|
|
|
|
// we do not print the delimiters but instead try to hack them
|
|
|
|
string const rows = convert<string>(nrows());
|
2017-07-03 17:53:14 +00:00
|
|
|
string const lattrib =
|
2010-03-31 19:59:09 +00:00
|
|
|
"class='ldelim' rowspan='" + rows + "'";
|
2017-07-03 17:53:14 +00:00
|
|
|
string const rattrib =
|
2010-03-31 19:59:09 +00:00
|
|
|
"class='rdelim' rowspan='" + rows + "'";
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2010-03-31 19:59:09 +00:00
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
|
|
|
os << MTag("tr") << '\n';
|
|
|
|
if (row == 0)
|
|
|
|
os << MTag("td", lattrib) << ETag("td") << '\n';
|
2015-05-17 11:43:37 +00:00
|
|
|
for (col_type col = 0; col < ncols(); ++col) {
|
|
|
|
idx_type const i = index(row, col);
|
2019-07-14 15:18:56 +00:00
|
|
|
if (cellinfo(i).multi != CELL_PART_OF_MULTICOLUMN) {
|
2015-05-17 11:43:37 +00:00
|
|
|
col_type const cellcols = ncellcols(i);
|
|
|
|
ostringstream attr;
|
|
|
|
if (cellcols > 1)
|
|
|
|
attr << "colspan='" << cellcols
|
|
|
|
<< '\'';
|
|
|
|
os << MTag("td", attr.str()) << cell(i)
|
|
|
|
<< ETag("td") << '\n';
|
|
|
|
}
|
|
|
|
}
|
2010-03-31 19:59:09 +00:00
|
|
|
if (row == 0)
|
|
|
|
os << MTag("td", rattrib) << ETag("td") << '\n';
|
|
|
|
os << ETag("tr") << '\n';
|
|
|
|
}
|
|
|
|
os << ETag("table") << '\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathMatrix::octave(OctaveStream & os) const
|
2001-11-09 08:35:57 +00:00
|
|
|
{
|
|
|
|
os << '[';
|
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
|
|
|
if (row)
|
|
|
|
os << ';';
|
|
|
|
os << '[';
|
2002-03-21 17:42:56 +00:00
|
|
|
for (col_type col = 0; col < ncols(); ++col)
|
2001-11-09 08:35:57 +00:00
|
|
|
os << cell(index(row, col)) << ' ';
|
|
|
|
os << ']';
|
|
|
|
}
|
|
|
|
os << ']';
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|