lyx_mirror/src/mathed/InsetMathMatrix.cpp

173 lines
3.9 KiB
C++
Raw Normal View History

/**
* \file InsetMathMatrix.cpp
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author André Pönitz
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "InsetMathMatrix.h"
#include "MathData.h"
#include "MathStream.h"
#include "support/convert.h"
using namespace std;
namespace lyx {
2017-07-03 17:53:14 +00:00
InsetMathMatrix::InsetMathMatrix(InsetMathGrid const & p,
docstring const & left, docstring const & right)
: InsetMathGrid(p), left_(left), right_(right)
{}
Inset * InsetMathMatrix::clone() const
{
return new InsetMathMatrix(*this);
}
2020-12-26 19:04:36 +00:00
void InsetMathMatrix::write(TeXMathStream & os) const
{
InsetMathGrid::write(os);
}
void InsetMathMatrix::normalize(NormalStream & os) const
{
InsetMathGrid::normalize(os);
}
void InsetMathMatrix::maple(MapleStream & os) const
{
os << "matrix(" << int(nrows()) << ',' << int(ncols()) << ",[";
for (idx_type idx = 0; idx < nargs(); ++idx) {
if (idx)
os << ',';
os << cell(idx);
}
os << "])";
}
void InsetMathMatrix::maxima(MaximaStream & os) const
{
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 << ')';
}
void InsetMathMatrix::mathematica(MathematicaStream & os) const
Improve Computer Algebra System, from Enrico Forestieri <forenr@tlc.unipr.it> * src/mathed/math_symbolinset.C (void MathSymbolInset::maxima): - newer maxima versions use inf instead of INF - add support for greek pi (void MathSymbolInset::mathematica): - add support for \cdot * src/mathed/math_stringinset.h - account for the const version of asStringInset() * src/mathed/math_extern.C (bool extractScript): - added bool superscript to formal parameters in order to only extract superscripts (MathArray::iterator extractArgument): - leave out delimiters and a possible superscript for function arguments (bool isKnownFunction): (bool extractFunctionName): - recognize standard and user defined function names (void splitScripts): - correctly split scripts as expected by other functions (MathAtom replaceDelims): - ranamed as replaceParenDelims (bool testOpenBracket): (bool testCloseBracket): - test for "[" and "]", respectively (MathAtom replaceBracketDelims): - replace something delimited by "[" and "]" with a proper DelimInset (void extractDelims): - create a DelimInset for "[" and "]" delimiters, too (void extractFunctions): - improved recognition of function names (bool testTermDelimiter): - test for '+' or '-' as term delimiters (MathArray::iterator extractTerm): - extract a "term", i.e., something delimited by '+' or '-' (bool testDiffItem): - improved recognition of a "differential fraction" (void extractDiff): - call splitScripts() on numerator and denominator of a differential fraction before analyzing them (void extractLims): - improved recognition of a limit function (void extractStructure): - reorganized order of searches (MathArray pipeThroughMaxima): - newer versions of maxima use simpsum instead of SIMPSUM (string fromMathematicaName): - translates from mathematica names (MathArray pipeThroughMathematica): - calls mathematica and collects its output (MathArray pipeThroughExtern): - add support for mathematica * src/mathed/math_numberinset.C * src/mathed/math_numberinset.h (void MathNumberInset::mathematica): - add support for mathematica * src/mathed/math_matrixinset.C * src/mathed/math_matrixinset.h (void MathMatrixInset::mathematica): - add support for mathematica * src/mathed/math_diffinset.C * src/mathed/math_diffinset.h (void MathDiffInset::maxima): - add support for maxima (void MathDiffInset::mathematica): - mathematica uses "D" and not "Dt" for normal derivatives * src/mathed/math_liminset.C * src/mathed/math_liminset.h (void MathLimInset::maxima): - add support for maxima (void MathLimInset::mathematica): - mathematica uses "Limit" and not "Lim" for limits * src/mathed/math_exfuncinset.C (string asMathematicaName): - added some more function names git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14865 a592a061-630c-0410-9148-cb99ea01b6c8
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
{
2019-05-09 23:52:07 +00:00
ms << "<" << from_ascii(ms.namespacedTag("mo")) << " form='prefix' fence='true' stretchy='true' symmetric='true' lspace='thinmathspace'>"
<< convertDelimToXMLEscape(left_, ms.xmlMode())
2019-05-09 23:52:07 +00:00
<< "</" << from_ascii(ms.namespacedTag("mo")) << ">"
<< MTag("mtable");
for (row_type row = 0; row < nrows(); ++row) {
2019-05-09 23:52:07 +00:00
ms << MTag("mtr");
for (col_type col = 0; col < ncols(); ++col) {
idx_type const i = index(row, col);
if (cellinfo(i).multi != CELL_PART_OF_MULTICOLUMN) {
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");
}
}
2019-05-09 23:52:07 +00:00
ms << ETag("mtr");
}
2019-05-09 23:52:07 +00:00
ms << ETag("mtable")
<< "<" << from_ascii(ms.namespacedTag("mo")) << " form='postfix' fence='true' stretchy='true' symmetric='true' lspace='thinmathspace'>"
<< convertDelimToXMLEscape(right_, ms.xmlMode())
2019-05-09 23:52:07 +00:00
<< "</" << from_ascii(ms.namespacedTag("mo")) << ">";
}
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 =
"class='ldelim' rowspan='" + rows + "'";
2017-07-03 17:53:14 +00:00
string const rattrib =
"class='rdelim' rowspan='" + rows + "'";
2017-07-03 17:53:14 +00:00
for (row_type row = 0; row < nrows(); ++row) {
os << MTag("tr") << '\n';
if (row == 0)
os << MTag("td", lattrib) << ETag("td") << '\n';
for (col_type col = 0; col < ncols(); ++col) {
idx_type const i = index(row, col);
if (cellinfo(i).multi != CELL_PART_OF_MULTICOLUMN) {
col_type const cellcols = ncellcols(i);
ostringstream attr;
if (cellcols > 1)
attr << "colspan='" << cellcols
<< '\'';
os << MTag("td", attr.str()) << cell(i)
<< ETag("td") << '\n';
}
}
if (row == 0)
os << MTag("td", rattrib) << ETag("td") << '\n';
os << ETag("tr") << '\n';
}
os << ETag("table") << '\n';
}
void InsetMathMatrix::octave(OctaveStream & os) const
{
os << '[';
for (row_type row = 0; row < nrows(); ++row) {
if (row)
os << ';';
os << '[';
for (col_type col = 0; col < ncols(); ++col)
os << cell(index(row, col)) << ' ';
os << ']';
}
os << ']';
}
} // namespace lyx