MathML stream allows for name spaces.

This commit is contained in:
Thibaut Cuvelier 2019-05-10 01:52:07 +02:00 committed by Pavel Sanda
parent ef65414d25
commit 054bdc5d18
36 changed files with 265 additions and 188 deletions

View File

@ -153,13 +153,13 @@ void InsetMath::mathematica(MathematicaStream & os) const
}
void InsetMath::mathmlize(MathStream & os) const
void InsetMath::mathmlize(MathStream & ms) const
{
os << "<!-- " << from_utf8(insetName(lyxCode())) << " -->";
os << MTag("mi");
NormalStream ns(os.os());
ms << "<!-- " << from_utf8(insetName(lyxCode())) << " -->";
ms << MTag("mi");
NormalStream ns(ms.os());
normalize(ns);
os << ETag("mi");
ms << ETag("mi");
}

View File

@ -135,11 +135,12 @@ void InsetMathBig::normalize(NormalStream & os) const
}
void InsetMathBig::mathmlize(MathStream & os) const
void InsetMathBig::mathmlize(MathStream & ms) const
{
os << "<mo form='prefix' fence='true' stretchy='true' symmetric='true'>"
ms << "<" << from_ascii(ms.namespacedTag("mo"))
<< " form='prefix' fence='true' stretchy='true' symmetric='true'>"
<< convertDelimToXMLEscape(delim_)
<< "</mo>";
<< "</" << from_ascii(ms.namespacedTag("mo")) << ">";
}

View File

@ -107,9 +107,11 @@ void InsetMathBoldSymbol::write(WriteStream & os) const
}
void InsetMathBoldSymbol::mathmlize(MathStream & os) const
void InsetMathBoldSymbol::mathmlize(MathStream & ms) const
{
os << "<mstyle mathvariant='bold'>" << cell(0) << "</mstyle>";
ms << "<" << from_ascii(ms.namespacedTag("mstyle")) << " mathvariant='bold'>"
<< cell(0)
<< "</" << from_ascii(ms.namespacedTag("mstyle")) << ">";
}

View File

@ -96,9 +96,9 @@ void InsetMathBrace::octave(OctaveStream & os) const
}
void InsetMathBrace::mathmlize(MathStream & os) const
void InsetMathBrace::mathmlize(MathStream & ms) const
{
os << MTag("mrow") << cell(0) << ETag("mrow");
ms << MTag("mrow") << cell(0) << ETag("mrow");
}

View File

@ -138,21 +138,21 @@ void InsetMathCancel::htmlize(HtmlStream & os) const
}
void InsetMathCancel::mathmlize(MathStream & os) const
void InsetMathCancel::mathmlize(MathStream & ms) const
{
switch (kind_) {
case cancel:
os << MTag("menclose", "notation='updiagonalstrike'")
ms << MTag("menclose", "notation='updiagonalstrike'")
<< cell(0)
<< ETag("menclose");
break;
case bcancel:
os << MTag("menclose", "notation='downdiagonalstrike'")
ms << MTag("menclose", "notation='downdiagonalstrike'")
<< cell(0)
<< ETag("menclose");
break;
case xcancel:
os << MTag("menclose", "notation='updiagonalstrike'")
ms << MTag("menclose", "notation='updiagonalstrike'")
<< MTag("menclose", "notation='downdiagonalstrike'")
<< cell(0)
<< ETag("menclose")

View File

@ -145,7 +145,10 @@ void InsetMathCases::maple(MapleStream & os) const
void InsetMathCases::mathmlize(MathStream & ms) const
{
ms << "<mo form='prefix' fence='true' stretchy='true' symmetric='true'>{</mo>";
ms << "<" << from_ascii(ms.namespacedTag("mo"))
<< " form='prefix' fence='true' stretchy='true' symmetric='true'>"
<< "{"
<< "</" << from_ascii(ms.namespacedTag("mo")) << ">";
InsetMathGrid::mathmlize(ms);
}

View File

@ -239,15 +239,18 @@ void InsetMathChar::mathmlize(MathStream & ms) const
}
if (!entity.empty()) {
ms << "<mo>" << from_ascii(entity) << "</mo>";
ms << "<" << from_ascii(ms.namespacedTag("mo")) << ">"
<< from_ascii(entity)
<< "</" << from_ascii(ms.namespacedTag("mo")) << ">";
return;
}
char const * type =
(isAlphaASCII(char_) || Encodings::isMathAlpha(char_))
? "mi" : "mo";
// we don't use MTag and ETag because we do not want the spacing
ms << "<" << type << ">" << char_type(char_) << "</" << type << ">";
// we don't use MTag and ETag because we do not want the spacing before the end tag.
docstring tag = from_ascii(ms.namespacedTag(type));
ms << "<" << tag << ">" << char_type(char_) << "</" << tag << ">";
}

View File

@ -83,9 +83,9 @@ void InsetMathComment::maple(MapleStream & os) const
}
void InsetMathComment::mathmlize(MathStream & os) const
void InsetMathComment::mathmlize(MathStream & ms) const
{
os << MTag("comment") << cell(0) << ETag("comment");
ms << MTag("comment") << cell(0) << ETag("comment");
}

View File

@ -218,16 +218,18 @@ namespace {
}
} // namespace
void InsetMathDecoration::mathmlize(MathStream & os) const
void InsetMathDecoration::mathmlize(MathStream & ms) const
{
TranslationMap const & t = translationMap();
TranslationMap::const_iterator cur = t.find(to_utf8(key_->name));
LASSERT(cur != t.end(), return);
char const * const outag = cur->second.over ? "mover" : "munder";
os << MTag(outag)
<< MTag("mrow") << cell(0) << ETag("mrow")
<< from_ascii("<mo stretchy=\"true\">" + cur->second.tag + "</mo>")
<< ETag(outag);
ms << MTag(outag)
<< MTag("mrow") << cell(0) << ETag("mrow")
<< "<" << from_ascii(ms.namespacedTag("mo")) << " stretchy=\"true\">"
<< from_ascii(cur->second.tag)
<< "</" << from_ascii(ms.namespacedTag("mo")) << ">"
<< ETag(outag);
}

View File

@ -179,19 +179,22 @@ void InsetMathDelim::mathematica(MathematicaStream & os) const
}
void InsetMathDelim::mathmlize(MathStream & os) const
void InsetMathDelim::mathmlize(MathStream & ms) const
{
os << "<mo form='prefix' fence='true' stretchy='true' symmetric='true'>"
<< "<mrow>"
ms << "<" << from_ascii(ms.namespacedTag("mo")) << " form='prefix' fence='true' stretchy='true' symmetric='true'>"
<< "<" << from_ascii(ms.namespacedTag("mrow")) << ">"
<< convertDelimToXMLEscape(left_)
<< "</mrow>"
<< "</mo>\n"
<< "</" << from_ascii(ms.namespacedTag("mrow")) << ">"
<< "</" << from_ascii(ms.namespacedTag("mo")) << ">"
<< "\n"
<< cell(0)
<< "\n<mo form='postfix' fence='true' stretchy='true' symmetric='true'>"
<< "<mrow>"
<< "\n"
<< "<" << from_ascii(ms.namespacedTag("mo")) << " form='postfix' fence='true' stretchy='true' symmetric='true'>"
<< "<" << from_ascii(ms.namespacedTag("mrow")) << ">"
<< convertDelimToXMLEscape(right_)
<< "</mrow>"
<< "</mo>\n";
<< "</" << from_ascii(ms.namespacedTag("mrow")) << ">"
<< "</" << from_ascii(ms.namespacedTag("mo")) << ">"
<< "\n";
}

View File

@ -85,7 +85,7 @@ void InsetMathDots::validate(LaTeXFeatures & features) const
}
void InsetMathDots::mathmlize(MathStream & os) const
void InsetMathDots::mathmlize(MathStream & ms) const
{
// which symbols we support is decided by what is listed in
// lib/symbols as generating a dots inset
@ -103,7 +103,7 @@ void InsetMathDots::mathmlize(MathStream & os) const
ent = "&vellip;";
else
LASSERT(false, ent = "&hellip;");
os << MTag("mi") << from_ascii(ent) << ETag("mi");
ms << MTag("mi") << from_ascii(ent) << ETag("mi");
}

View File

@ -35,7 +35,7 @@ public:
///
InsetCode lyxCode() const { return MATH_DOTS_CODE; }
///
void mathmlize(MathStream & os) const;
void mathmlize(MathStream & ms) const;
///
void htmlize(HtmlStream & os) const;
protected:

View File

@ -69,10 +69,10 @@ void InsetMathEnsureMath::write(WriteStream & os) const
}
void InsetMathEnsureMath::mathmlize(MathStream & os) const
void InsetMathEnsureMath::mathmlize(MathStream & ms) const
{
SetMode mathmode(os, false);
os << MTag("mstyle", "class='math'")
SetMode mathmode(ms, false);
ms << MTag("mstyle", "class='math'")
<< cell(0)
<< ETag("mstyle");
}

View File

@ -122,10 +122,15 @@ void InsetMathExFunc::mathematica(MathematicaStream & os) const
}
void InsetMathExFunc::mathmlize(MathStream & os) const
void InsetMathExFunc::mathmlize(MathStream & ms) const
{
os << "<mi>" << name_ << "</mi><mo>&af;</mo>";
os << cell(0);
ms << "<" << from_ascii(ms.namespacedTag("mi")) << ">"
<< name_
<< "</" << from_ascii(ms.namespacedTag("mi")) << ">"
<< "<" << from_ascii(ms.namespacedTag("mo")) << ">"
<< "&af;"
<< "</" << from_ascii(ms.namespacedTag("mo")) << ">"
<< cell(0);
}

View File

@ -124,7 +124,7 @@ void InsetMathExInt::mathematica(MathematicaStream & os) const
}
void InsetMathExInt::mathmlize(MathStream & os) const
void InsetMathExInt::mathmlize(MathStream & ms) const
{
// At the moment, we are not extracting sums and the like for MathML.
// If we should decide to do so later, then we'll need to re-merge
@ -134,27 +134,34 @@ void InsetMathExInt::mathmlize(MathStream & os) const
bool const lower = !cell(2).empty();
bool const upper = !cell(3).empty();
if (lower && upper)
os << MTag("msubsup");
ms << MTag("msubsup");
else if (lower)
os << MTag("msub");
ms << MTag("msub");
else if (upper)
os << MTag("msup");
os << MTag("mrow");
sym.mathmlize(os);
os << ETag("mrow");
ms << MTag("msup");
ms << MTag("mrow");
sym.mathmlize(ms);
ms << ETag("mrow");
if (lower)
os << MTag("mrow") << cell(2) << ETag("mrow");
ms << MTag("mrow") << cell(2) << ETag("mrow");
if (upper)
os << MTag("mrow") << cell(3) << ETag("mrow");
ms << MTag("mrow") << cell(3) << ETag("mrow");
if (lower && upper)
os << ETag("msubsup");
ms << ETag("msubsup");
else if (lower)
os << ETag("msub");
ms << ETag("msub");
else if (upper)
os << ETag("msup");
os << cell(0) << "<mo> &InvisibleTimes; </mo>"
<< MTag("mrow") << "<mo> &DifferentialD; </mo>"
<< cell(1) << ETag("mrow");
ms << ETag("msup");
ms << cell(0)
<< "<" << from_ascii(ms.namespacedTag("mo")) << "> "
<< " &InvisibleTimes; "
<< "</" << from_ascii(ms.namespacedTag("mo")) << ">"
<< MTag("mrow")
<< "<" << from_ascii(ms.namespacedTag("mo")) << "> "
<< " &DifferentialD; "
<< "</" << from_ascii(ms.namespacedTag("mo")) << ">"
<< cell(1)
<< ETag("mrow");
}

View File

@ -193,7 +193,7 @@ void InsetMathFont::htmlize(HtmlStream & os) const
// The fonts we want to support are listed in lib/symbols
void InsetMathFont::mathmlize(MathStream & os) const
void InsetMathFont::mathmlize(MathStream & ms) const
{
// FIXME These are not quite right, because they do not nest
// correctly. A proper fix would presumably involve tracking
@ -224,11 +224,11 @@ void InsetMathFont::mathmlize(MathStream & os) const
// no support at present for textipa, textsc, noun
if (!variant.empty())
os << MTag("mstyle", "mathvariant='" + variant + "'")
ms << MTag("mstyle", "mathvariant='" + variant + "'")
<< cell(0)
<< ETag("mstyle");
else
os << cell(0);
ms << cell(0);
}

View File

@ -491,14 +491,14 @@ void InsetMathFrac::octave(OctaveStream & os) const
}
void InsetMathFrac::mathmlize(MathStream & os) const
void InsetMathFrac::mathmlize(MathStream & ms) const
{
switch (kind_) {
case ATOP:
os << MTag("mfrac", "linethickeness='0'")
ms << MTag("mfrac", "linethickness='0'")
<< MTag("mrow") << cell(0) << ETag("mrow")
<< MTag("mrow") << cell(1) << ETag("mrow")
<< ETag("mfrac");
<< MTag("mrow") << cell(1) << ETag("mrow")
<< ETag("mfrac");
break;
// we do not presently distinguish these
@ -509,38 +509,38 @@ void InsetMathFrac::mathmlize(MathStream & os) const
case CFRAC:
case CFRACLEFT:
case CFRACRIGHT:
os << MTag("mfrac")
ms << MTag("mfrac")
<< MTag("mrow") << cell(0) << ETag("mrow")
<< MTag("mrow") << cell(1) << ETag("mrow")
<< ETag("mfrac");
<< MTag("mrow") << cell(1) << ETag("mrow")
<< ETag("mfrac");
break;
case NICEFRAC:
os << MTag("mfrac", "bevelled='true'")
ms << MTag("mfrac", "bevelled='true'")
<< MTag("mrow") << cell(0) << ETag("mrow")
<< MTag("mrow") << cell(1) << ETag("mrow")
<< ETag("mfrac");
<< MTag("mrow") << cell(1) << ETag("mrow")
<< ETag("mfrac");
break;
case UNITFRAC:
if (nargs() == 3)
os << cell(2);
os << MTag("mfrac", "bevelled='true'")
ms << cell(2);
ms << MTag("mfrac", "bevelled='true'")
<< MTag("mrow") << cell(0) << ETag("mrow")
<< MTag("mrow") << cell(1) << ETag("mrow")
<< ETag("mfrac");
<< MTag("mrow") << cell(1) << ETag("mrow")
<< ETag("mfrac");
break;
case UNIT:
// FIXME This is not right, because we still output mi, etc,
// when we output the cell. So we need to prevent that somehow.
if (nargs() == 2)
os << cell(0)
<< MTag("mstyle mathvariant='normal'")
<< cell(1)
ms << cell(0)
<< MTag("mstyle mathvariant='normal'")
<< cell(1)
<< ETag("mstyle");
else
os << MTag("mstyle mathvariant='normal'")
ms << MTag("mstyle mathvariant='normal'")
<< cell(0)
<< ETag("mstyle");
}
@ -730,7 +730,7 @@ void InsetMathBinom::normalize(NormalStream & os) const
}
void InsetMathBinom::mathmlize(MathStream & os) const
void InsetMathBinom::mathmlize(MathStream & ms) const
{
char ldelim = ' ';
char rdelim = ' ';
@ -751,11 +751,15 @@ void InsetMathBinom::mathmlize(MathStream & os) const
rdelim = ']';
break;
}
os << "<mo fence='true' stretchy='true' form='prefix'>" << ldelim << "</mo>"
<< "<mfrac linethickness='0'>"
ms << "<" << from_ascii(ms.namespacedTag("mo")) << " fence='true' stretchy='true' form='prefix'>"
<< ldelim
<< "</" << from_ascii(ms.namespacedTag("mo")) << ">"
<< "<" << from_ascii(ms.namespacedTag("mfrac")) << " linethickness='0'>"
<< cell(0) << cell(1)
<< "</mfrac>"
<< "<mo fence='true' stretchy='true' form='postfix'>" << rdelim << "</mo>";
<< "</" << from_ascii(ms.namespacedTag("mfrac")) << ">"
<< "<" << from_ascii(ms.namespacedTag("mo")) << " fence='true' stretchy='true' form='postfix'>"
<< rdelim
<< "</" << from_ascii(ms.namespacedTag("mo")) << ">";
}

View File

@ -1184,15 +1184,15 @@ void InsetMathGrid::normalize(NormalStream & os) const
}
void InsetMathGrid::mathmlize(MathStream & os) const
void InsetMathGrid::mathmlize(MathStream & ms) const
{
bool const havetable = nrows() > 1 || ncols() > 1;
if (havetable)
os << MTag("mtable");
ms << MTag("mtable");
char const * const celltag = havetable ? "mtd" : "mrow";
for (row_type row = 0; row < nrows(); ++row) {
if (havetable)
os << MTag("mtr");
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) {
@ -1200,16 +1200,16 @@ void InsetMathGrid::mathmlize(MathStream & os) const
ostringstream attr;
if (havetable && cellcols > 1)
attr << "colspan='" << cellcols << '\'';
os << MTag(celltag, attr.str());
os << cell(index(row, col));
os << ETag(celltag);
ms << MTag(celltag, attr.str());
ms << cell(index(row, col));
ms << ETag(celltag);
}
}
if (havetable)
os << ETag("mtr");
ms << ETag("mtr");
}
if (havetable)
os << ETag("mtable");
ms << ETag("mtable");
}

View File

@ -2517,13 +2517,13 @@ void InsetMathHull::htmlize(HtmlStream & os) const
// this duplicates code from InsetMathGrid, but
// we need access here to number information,
// and we simply do not have that in InsetMathGrid.
void InsetMathHull::mathmlize(MathStream & os) const
void InsetMathHull::mathmlize(MathStream & ms) const
{
bool const havenumbers = haveNumbers();
bool const havetable = havenumbers || nrows() > 1 || ncols() > 1;
if (havetable)
os << MTag("mtable");
ms << MTag("mtable");
char const * const celltag = havetable ? "mtd" : "mrow";
// FIXME There does not seem to be wide support at the moment
// for mlabeledtr, so we have to use just mtr for now.
@ -2531,25 +2531,25 @@ void InsetMathHull::mathmlize(MathStream & os) const
char const * const rowtag = "mtr";
for (row_type row = 0; row < nrows(); ++row) {
if (havetable)
os << MTag(rowtag);
ms << MTag(rowtag);
for (col_type col = 0; col < ncols(); ++col) {
os << MTag(celltag)
ms << MTag(celltag)
<< cell(index(row, col))
<< ETag(celltag);
}
// fleqn?
if (havenumbers) {
os << MTag("mtd");
ms << MTag("mtd");
docstring const & num = numbers_[row];
if (!num.empty())
os << '(' << num << ')';
os << ETag("mtd");
ms << '(' << num << ')';
ms << ETag("mtd");
}
if (havetable)
os << ETag(rowtag);
ms << ETag(rowtag);
}
if (havetable)
os << ETag("mtable");
ms << ETag("mtable");
}

View File

@ -1176,7 +1176,7 @@ void InsetMathMacro::mathematica(MathematicaStream & os) const
}
void InsetMathMacro::mathmlize(MathStream & os) const
void InsetMathMacro::mathmlize(MathStream & ms) const
{
// macro_ is 0 if this is an unknown macro
LATTEST(d->macro_ || d->displayMode_ != DISPLAY_NORMAL);
@ -1184,8 +1184,9 @@ void InsetMathMacro::mathmlize(MathStream & os) const
docstring const xmlname = d->macro_->xmlname();
if (!xmlname.empty()) {
char const * type = d->macro_->MathMLtype();
os << '<' << type << "> " << xmlname << " </"
<< type << '>';
ms << "<" << from_ascii(ms.namespacedTag(type)) << ">"
<< xmlname
<< "</" << from_ascii(ms.namespacedTag(type)) << ">";
return;
}
}
@ -1193,7 +1194,7 @@ void InsetMathMacro::mathmlize(MathStream & os) const
// this means that we do not recognize the macro
throw MathExportException();
}
os << d->expanded_;
ms << d->expanded_;
}

View File

@ -92,14 +92,14 @@ void InsetMathMatrix::mathematica(MathematicaStream & os) const
}
void InsetMathMatrix::mathmlize(MathStream & os) const
void InsetMathMatrix::mathmlize(MathStream & ms) const
{
os << "<mo form='prefix' fence='true' stretchy='true' symmetric='true' lspace='thinmathspace'>"
<< convertDelimToXMLEscape(left_)
<< "</mo>"
ms << "<" << from_ascii(ms.namespacedTag("mo")) << " form='prefix' fence='true' stretchy='true' symmetric='true' lspace='thinmathspace'>"
<< convertDelimToXMLEscape(left_)
<< "</" << from_ascii(ms.namespacedTag("mo")) << ">"
<< MTag("mtable");
for (row_type row = 0; row < nrows(); ++row) {
os << MTag("mtr");
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) {
@ -107,15 +107,15 @@ void InsetMathMatrix::mathmlize(MathStream & os) const
ostringstream attr;
if (cellcols > 1)
attr << "columnspan='" << cellcols << '\'';
os << MTag("mtd", attr.str()) << cell(i) << ETag("mtd");
ms << MTag("mtd", attr.str()) << cell(i) << ETag("mtd");
}
}
os << ETag("mtr");
ms << ETag("mtr");
}
os << ETag("mtable");
os << "<mo form='postfix' fence='true' stretchy='true' symmetric='true' lspace='thinmathspace'>"
<< convertDelimToXMLEscape(right_)
<< "</mo>";
ms << ETag("mtable")
<< "<" << from_ascii(ms.namespacedTag("mo")) << " form='postfix' fence='true' stretchy='true' symmetric='true' lspace='thinmathspace'>"
<< convertDelimToXMLEscape(right_)
<< "</" << from_ascii(ms.namespacedTag("mo")) << ">";
}

View File

@ -69,9 +69,11 @@ void InsetMathNumber::octave(OctaveStream & os) const
}
void InsetMathNumber::mathmlize(MathStream & os) const
void InsetMathNumber::mathmlize(MathStream & ms) const
{
os << "<mn>" << str_ << "</mn>";
ms << "<" << from_ascii(ms.namespacedTag("mn")) << ">"
<< str_
<< "</" << from_ascii(ms.namespacedTag("mn")) << ">";
}

View File

@ -105,16 +105,18 @@ void InsetMathOverset::normalize(NormalStream & os) const
void InsetMathOverset::mathmlize(MathStream & ms) const
{
ms << "<mover accent='false'>" << cell(0) << cell(1) << "</mover>";
ms << "<" << from_ascii(ms.namespacedTag("mover")) << " accent='false'>"
<< cell(0) << cell(1)
<< "</" << from_ascii(ms.namespacedTag("mover")) << ">";
}
void InsetMathOverset::htmlize(HtmlStream & os) const
{
os << MTag("span", "class='overset'")
<< MTag("span", "class='top'") << cell(1) << ETag("span")
<< MTag("span") << cell(0) << ETag("span")
<< ETag("span");
<< MTag("span", "class='top'") << cell(1) << ETag("span")
<< MTag("span") << cell(0) << ETag("span")
<< ETag("span");
}

View File

@ -216,9 +216,9 @@ void InsetMathRoot::octave(OctaveStream & os) const
}
void InsetMathRoot::mathmlize(MathStream & os) const
void InsetMathRoot::mathmlize(MathStream & ms) const
{
os << MTag("mroot") << cell(0) << cell(1) << ETag("mroot");
ms << MTag("mroot") << cell(0) << cell(1) << ETag("mroot");
}

View File

@ -612,32 +612,32 @@ void InsetMathScript::mathematica(MathematicaStream & os) const
}
void InsetMathScript::mathmlize(MathStream & os) const
void InsetMathScript::mathmlize(MathStream & ms) const
{
bool d = hasDown() && !down().empty();
bool u = hasUp() && !up().empty();
bool l = hasLimits();
if (u && d)
os << MTag(l ? "munderover" : "msubsup");
ms << MTag(l ? "munderover" : "msubsup");
else if (u)
os << MTag(l ? "mover" : "msup");
ms << MTag(l ? "mover" : "msup");
else if (d)
os << MTag(l ? "munder" : "msub");
ms << MTag(l ? "munder" : "msub");
if (!nuc().empty())
os << MTag("mrow") << nuc() << ETag("mrow");
ms << MTag("mrow") << nuc() << ETag("mrow");
else
os << "<mrow />";
ms << "<" << from_ascii(ms.namespacedTag("mrow")) << " />";
if (u && d)
os << MTag("mrow") << down() << ETag("mrow")
ms << MTag("mrow") << down() << ETag("mrow")
<< MTag("mrow") << up() << ETag("mrow")
<< ETag(l ? "munderover" : "msubsup");
else if (u)
os << MTag("mrow") << up() << ETag("mrow") << ETag(l ? "mover" : "msup");
ms << MTag("mrow") << up() << ETag("mrow") << ETag(l ? "mover" : "msup");
else if (d)
os << MTag("mrow") << down() << ETag("mrow") << ETag(l ? "munder" : "msub");
ms << MTag("mrow") << down() << ETag("mrow") << ETag(l ? "munder" : "msub");
}

View File

@ -385,41 +385,41 @@ void InsetMathSideset::normalize(NormalStream & os) const
}
void InsetMathSideset::mathmlize(MathStream & os) const
void InsetMathSideset::mathmlize(MathStream & ms) const
{
// FIXME This is only accurate if both scriptl_ and scriptr_ are true
if (!scriptl_)
os << MTag("mrow") << bl() << ETag("mrow");
ms << MTag("mrow") << bl() << ETag("mrow");
if (scriptl_ || scriptr_) {
os << MTag("mmultiscripts");
ms << MTag("mmultiscripts");
if (nuc().empty())
os << "<mrow />";
ms << "<" << from_ascii(ms.namespacedTag("mrow")) << " />";
else
os << MTag("mrow") << nuc() << ETag("mrow");
ms << MTag("mrow") << nuc() << ETag("mrow");
if (br().empty() || !scriptr_)
os << "<none />";
ms << "<" << from_ascii(ms.namespacedTag("none")) << " />";
else
os << MTag("mrow") << br() << ETag("mrow");
ms << MTag("mrow") << br() << ETag("mrow");
if (tr().empty() || !scriptr_)
os << "<none />";
ms << "<" << from_ascii(ms.namespacedTag("none")) << " />";
else
os << MTag("mrow") << tr() << ETag("mrow");
ms << MTag("mrow") << tr() << ETag("mrow");
if (bl().empty() || !scriptl_)
os << "<none />";
ms << "<" << from_ascii(ms.namespacedTag("none")) << " />";
else
os << MTag("mrow") << bl() << ETag("mrow");
ms << MTag("mrow") << bl() << ETag("mrow");
if (tl().empty() || !scriptl_)
os << "<none />";
ms << "<" << from_ascii(ms.namespacedTag("none")) << " />";
else
os << MTag("mrow") << tl() << ETag("mrow");
ms << MTag("mrow") << tl() << ETag("mrow");
os << ETag("mmultiscripts");
ms << ETag("mmultiscripts");
}
if (!scriptr_)
os << MTag("mrow") << br() << ETag("mrow");
ms << MTag("mrow") << br() << ETag("mrow");
}

View File

@ -209,7 +209,7 @@ void InsetMathSpace::mathmlize(MathStream & ms) const
l = ss.str() + "px";
}
ms << "<mspace";
ms << "<" << from_ascii(ms.namespacedTag("mspace"));
if (!l.empty())
ms << " width=\"" << from_ascii(l) << "\"";
ms << " />";

View File

@ -98,9 +98,9 @@ void InsetMathSqrt::octave(OctaveStream & os) const
}
void InsetMathSqrt::mathmlize(MathStream & os) const
void InsetMathSqrt::mathmlize(MathStream & ms) const
{
os << MTag("msqrt") << cell(0) << ETag("msqrt");
ms << MTag("msqrt") << cell(0) << ETag("msqrt");
}

View File

@ -144,9 +144,13 @@ void InsetMathStackrel::normalize(NormalStream & os) const
void InsetMathStackrel::mathmlize(MathStream & ms) const
{
if (nargs() > 2)
ms << "<munderover>" << cell(0) << cell(2) << cell(1) << "</munderover>";
ms << "<" << from_ascii(ms.namespacedTag("munderover")) << ">"
<< cell(0) << cell(2) << cell(1)
<< "</" << from_ascii(ms.namespacedTag("munderover")) << ">";
else
ms << "<mover accent='false'>" << cell(0) << cell(1) << "</mover>";
ms << "<" << from_ascii(ms.namespacedTag("mover")) << " accent='false'>"
<< cell(0) << cell(1)
<< "</" << from_ascii(ms.namespacedTag("mover")) << ">";
}

View File

@ -125,19 +125,19 @@ void InsetMathSubstack::maple(MapleStream & os) const
}
void InsetMathSubstack::mathmlize(MathStream & os) const
void InsetMathSubstack::mathmlize(MathStream & ms) const
{
int movers = 0;
row_type const numrows = nrows();
for (row_type row = 0; row < nrows(); ++row) {
if (row < numrows - 1) {
movers ++;
os << MTag("munder");
ms << MTag("munder");
}
os << MTag("mrow") << cell(index(row, 0)) << ETag("mrow");
ms << MTag("mrow") << cell(index(row, 0)) << ETag("mrow");
}
for (int i = 1; i <= movers; ++i)
os << ETag("munder");
ms << ETag("munder");
}

View File

@ -162,18 +162,18 @@ void InsetMathSymbol::mathematica(MathematicaStream & os) const
}
void InsetMathSymbol::mathmlize(MathStream & os) const
void InsetMathSymbol::mathmlize(MathStream & ms) const
{
// FIXME We may need to do more interesting things
// with MathMLtype.
char const * type = sym_->MathMLtype();
os << '<' << type << "> ";
docstring tag = from_ascii(ms.namespacedTag(sym_->MathMLtype()));
ms << '<' << tag << ">";
if (sym_->xmlname == "x")
// unknown so far
os << name();
ms << name();
else
os << sym_->xmlname;
os << " </" << type << '>';
ms << sym_->xmlname;
ms << "</" << tag << '>';
}

View File

@ -94,7 +94,9 @@ void InsetMathUnderset::normalize(NormalStream & os) const
void InsetMathUnderset::mathmlize(MathStream & ms) const
{
ms << "<munder accent='false'>" << cell(0) << cell(1) << "</munder>";
ms << "<" << from_ascii(ms.namespacedTag("munder")) << " accent='false'>"
<< cell(0) << cell(1)
<< "</" << from_ascii(ms.namespacedTag("munder")) << ">";
}

View File

@ -123,9 +123,9 @@ void InsetMathXArrow::mathmlize(MathStream & ms) const
lyxerr << "mathmlize conversion for '" << name_ << "' not implemented" << endl;
LASSERT(false, arrow = "&rarr;");
}
ms << "<munderover accent='false' accentunder='false'>"
ms << "<" << from_ascii(ms.namespacedTag("munderover")) << " accent='false' accentunder='false'>"
<< arrow << cell(1) << cell(0)
<< "</munderover>";
<< "</" << from_ascii(ms.namespacedTag("munderover"))<< ">";
}

View File

@ -1586,19 +1586,19 @@ void mathematica(MathData const & dat, MathematicaStream & os)
}
void mathmlize(MathData const & dat, MathStream & os)
void mathmlize(MathData const & dat, MathStream & ms)
{
MathData ar = dat;
extractStructure(ar, MATHML);
if (ar.empty())
os << "<mrow/>";
ms << "<" << from_ascii(ms.namespacedTag("mrow")) << "/>";
else if (ar.size() == 1)
os << ar.front();
ms << ar.front();
else {
os << MTag("mrow");
ms << MTag("mrow");
for (MathData::const_iterator it = ar.begin(); it != ar.end(); ++it)
(*it)->mathmlize(os);
os << ETag("mrow");
(*it)->mathmlize(ms);
ms << ETag("mrow");
}
}

View File

@ -269,8 +269,8 @@ WriteStream & operator<<(WriteStream & ws, unsigned int i)
//////////////////////////////////////////////////////////////////////
MathStream::MathStream(odocstream & os)
: os_(os), tab_(0), line_(0), in_text_(false)
MathStream::MathStream(odocstream & os, std::string xmlns)
: os_(os), tab_(0), line_(0), in_text_(false), xmlns_(xmlns)
{}
@ -339,10 +339,10 @@ MathStream & operator<<(MathStream & ms, MTag const & t)
{
++ms.tab();
ms.cr();
ms.os() << '<' << from_ascii(t.tag_);
ms.os() << '<' << from_ascii(ms.namespacedTag(t.tag_));
if (!t.attr_.empty())
ms.os() << " " << from_ascii(t.attr_);
ms << '>';
ms << ">";
return ms;
}
@ -352,7 +352,18 @@ MathStream & operator<<(MathStream & ms, ETag const & t)
ms.cr();
if (ms.tab() > 0)
--ms.tab();
ms.os() << "</" << from_ascii(t.tag_) << '>';
ms.os() << "</" << from_ascii(ms.namespacedTag(t.tag_)) << ">";
return ms;
}
MathStream & operator<<(MathStream & ms, CTag const & t)
{
ms.cr();
ms.os() << "<" << from_ascii(ms.namespacedTag(t.tag_));
if (!t.attr_.empty())
ms.os() << " " << from_utf8(t.attr_);
ms.os() << "/>";
return ms;
}
@ -452,17 +463,17 @@ HtmlStream & operator<<(HtmlStream & ms, docstring const & s)
//////////////////////////////////////////////////////////////////////
SetMode::SetMode(MathStream & os, bool text)
: os_(os)
SetMode::SetMode(MathStream & ms, bool text)
: ms_(ms)
{
was_text_ = os_.inText();
os_.setTextMode(text);
was_text_ = ms_.inText();
ms_.setTextMode(text);
}
SetMode::~SetMode()
{
os_.setTextMode(was_text_);
ms_.setTextMode(was_text_);
}

View File

@ -293,6 +293,8 @@ private:
// MathML
//
/// Start tag.
class MTag {
public:
///
@ -304,6 +306,8 @@ public:
std::string attr_;
};
/// End tag.
class ETag {
public:
///
@ -313,6 +317,19 @@ public:
};
/// Compound tag (no content, directly closed).
class CTag {
public:
///
CTag(char const * const tag, std::string attr = "")
: tag_(tag), attr_(attr) {}
///
char const * const tag_;
///
std::string attr_;
};
/// Throw MathExportException to signal that the attempt to export
/// some math in the current format did not succeed. E.g., we can't
/// export xymatrix as MathML, so that will throw, and we'll fall back
@ -322,8 +339,8 @@ class MathExportException : public std::exception {};
class MathStream {
public:
///
explicit MathStream(odocstream & os);
/// Builds a stream proxy for os; the MathML namespace is given by xmlns (supposed to be already defined elsewhere in the document).
explicit MathStream(odocstream & os, std::string xmlns="");
///
void cr();
///
@ -342,6 +359,10 @@ public:
docstring deferred() const;
///
bool inText() const { return in_text_; }
///
std::string xmlns() const { return xmlns_; }
/// Returns the tag name prefixed by the name space if needed.
std::string namespacedTag(std::string tag) const { return ((xmlns().empty()) ? "" : xmlns() + ":") + tag; }
private:
///
void setTextMode(bool t) { in_text_ = t; }
@ -356,6 +377,8 @@ private:
///
odocstringstream deferred_;
///
std::string xmlns_;
///
friend class SetMode;
};
@ -375,18 +398,20 @@ MathStream & operator<<(MathStream &, char_type);
MathStream & operator<<(MathStream &, MTag const &);
///
MathStream & operator<<(MathStream &, ETag const &);
///
MathStream & operator<<(MathStream &, CTag const &);
/// A simpler version of ModeSpecifier, for MathML
class SetMode {
public:
///
explicit SetMode(MathStream & os, bool text);
explicit SetMode(MathStream & ms, bool text);
///
~SetMode();
private:
///
MathStream & os_;
MathStream & ms_;
///
bool was_text_;
};