diff --git a/src/mathed/InsetMath.cpp b/src/mathed/InsetMath.cpp index 8706001d61..8228153b95 100644 --- a/src/mathed/InsetMath.cpp +++ b/src/mathed/InsetMath.cpp @@ -153,13 +153,13 @@ void InsetMath::mathematica(MathematicaStream & os) const } -void InsetMath::mathmlize(MathStream & os) const +void InsetMath::mathmlize(MathStream & ms) const { - os << ""; - os << MTag("mi"); - NormalStream ns(os.os()); + ms << ""; + ms << MTag("mi"); + NormalStream ns(ms.os()); normalize(ns); - os << ETag("mi"); + ms << ETag("mi"); } diff --git a/src/mathed/InsetMathBig.cpp b/src/mathed/InsetMathBig.cpp index 889f8d4f97..5e89d4e79c 100644 --- a/src/mathed/InsetMathBig.cpp +++ b/src/mathed/InsetMathBig.cpp @@ -135,11 +135,12 @@ void InsetMathBig::normalize(NormalStream & os) const } -void InsetMathBig::mathmlize(MathStream & os) const +void InsetMathBig::mathmlize(MathStream & ms) const { - os << "" + ms << "<" << from_ascii(ms.namespacedTag("mo")) + << " form='prefix' fence='true' stretchy='true' symmetric='true'>" << convertDelimToXMLEscape(delim_) - << ""; + << ""; } diff --git a/src/mathed/InsetMathBoldSymbol.cpp b/src/mathed/InsetMathBoldSymbol.cpp index 62f8098fa1..5dbe1fda28 100644 --- a/src/mathed/InsetMathBoldSymbol.cpp +++ b/src/mathed/InsetMathBoldSymbol.cpp @@ -107,9 +107,11 @@ void InsetMathBoldSymbol::write(WriteStream & os) const } -void InsetMathBoldSymbol::mathmlize(MathStream & os) const +void InsetMathBoldSymbol::mathmlize(MathStream & ms) const { - os << "" << cell(0) << ""; + ms << "<" << from_ascii(ms.namespacedTag("mstyle")) << " mathvariant='bold'>" + << cell(0) + << ""; } diff --git a/src/mathed/InsetMathBrace.cpp b/src/mathed/InsetMathBrace.cpp index 3a452c0386..a31a759a41 100644 --- a/src/mathed/InsetMathBrace.cpp +++ b/src/mathed/InsetMathBrace.cpp @@ -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"); } diff --git a/src/mathed/InsetMathCancel.cpp b/src/mathed/InsetMathCancel.cpp index 25728a3680..ee82d0c378 100644 --- a/src/mathed/InsetMathCancel.cpp +++ b/src/mathed/InsetMathCancel.cpp @@ -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") diff --git a/src/mathed/InsetMathCases.cpp b/src/mathed/InsetMathCases.cpp index 0a5fa332b1..5ddb9d015e 100644 --- a/src/mathed/InsetMathCases.cpp +++ b/src/mathed/InsetMathCases.cpp @@ -145,7 +145,10 @@ void InsetMathCases::maple(MapleStream & os) const void InsetMathCases::mathmlize(MathStream & ms) const { - ms << "{"; + ms << "<" << from_ascii(ms.namespacedTag("mo")) + << " form='prefix' fence='true' stretchy='true' symmetric='true'>" + << "{" + << ""; InsetMathGrid::mathmlize(ms); } diff --git a/src/mathed/InsetMathChar.cpp b/src/mathed/InsetMathChar.cpp index 1137c95e75..7069bdcd5f 100644 --- a/src/mathed/InsetMathChar.cpp +++ b/src/mathed/InsetMathChar.cpp @@ -239,15 +239,18 @@ void InsetMathChar::mathmlize(MathStream & ms) const } if (!entity.empty()) { - ms << "" << from_ascii(entity) << ""; + ms << "<" << from_ascii(ms.namespacedTag("mo")) << ">" + << from_ascii(entity) + << ""; 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_) << ""; + // 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_) << ""; } diff --git a/src/mathed/InsetMathComment.cpp b/src/mathed/InsetMathComment.cpp index ea502d1aa2..1a248ebfaa 100644 --- a/src/mathed/InsetMathComment.cpp +++ b/src/mathed/InsetMathComment.cpp @@ -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"); } diff --git a/src/mathed/InsetMathDecoration.cpp b/src/mathed/InsetMathDecoration.cpp index afb8228cb5..685e65d81f 100644 --- a/src/mathed/InsetMathDecoration.cpp +++ b/src/mathed/InsetMathDecoration.cpp @@ -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("" + cur->second.tag + "") - << ETag(outag); + ms << MTag(outag) + << MTag("mrow") << cell(0) << ETag("mrow") + << "<" << from_ascii(ms.namespacedTag("mo")) << " stretchy=\"true\">" + << from_ascii(cur->second.tag) + << "" + << ETag(outag); } diff --git a/src/mathed/InsetMathDelim.cpp b/src/mathed/InsetMathDelim.cpp index 1989d48dc2..95b533b4c7 100644 --- a/src/mathed/InsetMathDelim.cpp +++ b/src/mathed/InsetMathDelim.cpp @@ -179,19 +179,22 @@ void InsetMathDelim::mathematica(MathematicaStream & os) const } -void InsetMathDelim::mathmlize(MathStream & os) const +void InsetMathDelim::mathmlize(MathStream & ms) const { - os << "" - << "" + ms << "<" << from_ascii(ms.namespacedTag("mo")) << " form='prefix' fence='true' stretchy='true' symmetric='true'>" + << "<" << from_ascii(ms.namespacedTag("mrow")) << ">" << convertDelimToXMLEscape(left_) - << "" - << "\n" + << "" + << "" + << "\n" << cell(0) - << "\n" - << "" + << "\n" + << "<" << from_ascii(ms.namespacedTag("mo")) << " form='postfix' fence='true' stretchy='true' symmetric='true'>" + << "<" << from_ascii(ms.namespacedTag("mrow")) << ">" << convertDelimToXMLEscape(right_) - << "" - << "\n"; + << "" + << "" + << "\n"; } diff --git a/src/mathed/InsetMathDots.cpp b/src/mathed/InsetMathDots.cpp index 3679771745..6ec3661837 100644 --- a/src/mathed/InsetMathDots.cpp +++ b/src/mathed/InsetMathDots.cpp @@ -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 = "⋮"; else LASSERT(false, ent = "…"); - os << MTag("mi") << from_ascii(ent) << ETag("mi"); + ms << MTag("mi") << from_ascii(ent) << ETag("mi"); } diff --git a/src/mathed/InsetMathDots.h b/src/mathed/InsetMathDots.h index 8a84a22219..9155f7e11a 100644 --- a/src/mathed/InsetMathDots.h +++ b/src/mathed/InsetMathDots.h @@ -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: diff --git a/src/mathed/InsetMathEnsureMath.cpp b/src/mathed/InsetMathEnsureMath.cpp index 8bd685c5a0..55c7be78a9 100644 --- a/src/mathed/InsetMathEnsureMath.cpp +++ b/src/mathed/InsetMathEnsureMath.cpp @@ -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"); } diff --git a/src/mathed/InsetMathExFunc.cpp b/src/mathed/InsetMathExFunc.cpp index e4e1f10c2e..9782e25cf3 100644 --- a/src/mathed/InsetMathExFunc.cpp +++ b/src/mathed/InsetMathExFunc.cpp @@ -122,10 +122,15 @@ void InsetMathExFunc::mathematica(MathematicaStream & os) const } -void InsetMathExFunc::mathmlize(MathStream & os) const +void InsetMathExFunc::mathmlize(MathStream & ms) const { - os << "" << name_ << ""; - os << cell(0); + ms << "<" << from_ascii(ms.namespacedTag("mi")) << ">" + << name_ + << "" + << "<" << from_ascii(ms.namespacedTag("mo")) << ">" + << "⁡" + << "" + << cell(0); } diff --git a/src/mathed/InsetMathExInt.cpp b/src/mathed/InsetMathExInt.cpp index 35bee0ef08..537870fd91 100644 --- a/src/mathed/InsetMathExInt.cpp +++ b/src/mathed/InsetMathExInt.cpp @@ -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) << "" - << MTag("mrow") << "" - << cell(1) << ETag("mrow"); + ms << ETag("msup"); + ms << cell(0) + << "<" << from_ascii(ms.namespacedTag("mo")) << "> " + << " ⁢ " + << "" + << MTag("mrow") + << "<" << from_ascii(ms.namespacedTag("mo")) << "> " + << " ⅆ " + << "" + << cell(1) + << ETag("mrow"); } diff --git a/src/mathed/InsetMathFont.cpp b/src/mathed/InsetMathFont.cpp index 6611590a47..f199ee5bcf 100644 --- a/src/mathed/InsetMathFont.cpp +++ b/src/mathed/InsetMathFont.cpp @@ -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); } diff --git a/src/mathed/InsetMathFrac.cpp b/src/mathed/InsetMathFrac.cpp index 7a281a33e4..90d507cfbe 100644 --- a/src/mathed/InsetMathFrac.cpp +++ b/src/mathed/InsetMathFrac.cpp @@ -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 << "" << ldelim << "" - << "" + ms << "<" << from_ascii(ms.namespacedTag("mo")) << " fence='true' stretchy='true' form='prefix'>" + << ldelim + << "" + << "<" << from_ascii(ms.namespacedTag("mfrac")) << " linethickness='0'>" << cell(0) << cell(1) - << "" - << "" << rdelim << ""; + << "" + << "<" << from_ascii(ms.namespacedTag("mo")) << " fence='true' stretchy='true' form='postfix'>" + << rdelim + << ""; } diff --git a/src/mathed/InsetMathGrid.cpp b/src/mathed/InsetMathGrid.cpp index b6d90eed16..d6f275a3aa 100644 --- a/src/mathed/InsetMathGrid.cpp +++ b/src/mathed/InsetMathGrid.cpp @@ -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"); } diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp index a117af6cdc..465ba6466b 100644 --- a/src/mathed/InsetMathHull.cpp +++ b/src/mathed/InsetMathHull.cpp @@ -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"); } diff --git a/src/mathed/InsetMathMacro.cpp b/src/mathed/InsetMathMacro.cpp index bdf86258c7..3cabf6a818 100644 --- a/src/mathed/InsetMathMacro.cpp +++ b/src/mathed/InsetMathMacro.cpp @@ -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 << " '; + ms << "<" << from_ascii(ms.namespacedTag(type)) << ">" + << xmlname + << ""; 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_; } diff --git a/src/mathed/InsetMathMatrix.cpp b/src/mathed/InsetMathMatrix.cpp index b13d00677f..a4999039e8 100644 --- a/src/mathed/InsetMathMatrix.cpp +++ b/src/mathed/InsetMathMatrix.cpp @@ -92,14 +92,14 @@ void InsetMathMatrix::mathematica(MathematicaStream & os) const } -void InsetMathMatrix::mathmlize(MathStream & os) const +void InsetMathMatrix::mathmlize(MathStream & ms) const { - os << "" - << convertDelimToXMLEscape(left_) - << "" + ms << "<" << from_ascii(ms.namespacedTag("mo")) << " form='prefix' fence='true' stretchy='true' symmetric='true' lspace='thinmathspace'>" + << convertDelimToXMLEscape(left_) + << "" << 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 << "" - << convertDelimToXMLEscape(right_) - << ""; + ms << ETag("mtable") + << "<" << from_ascii(ms.namespacedTag("mo")) << " form='postfix' fence='true' stretchy='true' symmetric='true' lspace='thinmathspace'>" + << convertDelimToXMLEscape(right_) + << ""; } diff --git a/src/mathed/InsetMathNumber.cpp b/src/mathed/InsetMathNumber.cpp index 5237cebab6..5a35415786 100644 --- a/src/mathed/InsetMathNumber.cpp +++ b/src/mathed/InsetMathNumber.cpp @@ -69,9 +69,11 @@ void InsetMathNumber::octave(OctaveStream & os) const } -void InsetMathNumber::mathmlize(MathStream & os) const +void InsetMathNumber::mathmlize(MathStream & ms) const { - os << "" << str_ << ""; + ms << "<" << from_ascii(ms.namespacedTag("mn")) << ">" + << str_ + << ""; } diff --git a/src/mathed/InsetMathOverset.cpp b/src/mathed/InsetMathOverset.cpp index 3d36218d63..2db26cf4c0 100644 --- a/src/mathed/InsetMathOverset.cpp +++ b/src/mathed/InsetMathOverset.cpp @@ -105,16 +105,18 @@ void InsetMathOverset::normalize(NormalStream & os) const void InsetMathOverset::mathmlize(MathStream & ms) const { - ms << "" << cell(0) << cell(1) << ""; + ms << "<" << from_ascii(ms.namespacedTag("mover")) << " accent='false'>" + << cell(0) << cell(1) + << ""; } 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"); } diff --git a/src/mathed/InsetMathRoot.cpp b/src/mathed/InsetMathRoot.cpp index 6661d85555..de4253e808 100644 --- a/src/mathed/InsetMathRoot.cpp +++ b/src/mathed/InsetMathRoot.cpp @@ -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"); } diff --git a/src/mathed/InsetMathScript.cpp b/src/mathed/InsetMathScript.cpp index 2f66b0f06e..bc1986858d 100644 --- a/src/mathed/InsetMathScript.cpp +++ b/src/mathed/InsetMathScript.cpp @@ -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 << ""; + 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"); } diff --git a/src/mathed/InsetMathSideset.cpp b/src/mathed/InsetMathSideset.cpp index ccbab52a80..642e07c16a 100644 --- a/src/mathed/InsetMathSideset.cpp +++ b/src/mathed/InsetMathSideset.cpp @@ -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 << ""; + ms << "<" << from_ascii(ms.namespacedTag("mrow")) << " />"; else - os << MTag("mrow") << nuc() << ETag("mrow"); + ms << MTag("mrow") << nuc() << ETag("mrow"); if (br().empty() || !scriptr_) - os << ""; + ms << "<" << from_ascii(ms.namespacedTag("none")) << " />"; else - os << MTag("mrow") << br() << ETag("mrow"); + ms << MTag("mrow") << br() << ETag("mrow"); if (tr().empty() || !scriptr_) - os << ""; + ms << "<" << from_ascii(ms.namespacedTag("none")) << " />"; else - os << MTag("mrow") << tr() << ETag("mrow"); + ms << MTag("mrow") << tr() << ETag("mrow"); if (bl().empty() || !scriptl_) - os << ""; + ms << "<" << from_ascii(ms.namespacedTag("none")) << " />"; else - os << MTag("mrow") << bl() << ETag("mrow"); + ms << MTag("mrow") << bl() << ETag("mrow"); if (tl().empty() || !scriptl_) - os << ""; + 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"); } diff --git a/src/mathed/InsetMathSpace.cpp b/src/mathed/InsetMathSpace.cpp index db096092b8..8e764868eb 100644 --- a/src/mathed/InsetMathSpace.cpp +++ b/src/mathed/InsetMathSpace.cpp @@ -209,7 +209,7 @@ void InsetMathSpace::mathmlize(MathStream & ms) const l = ss.str() + "px"; } - ms << ""; diff --git a/src/mathed/InsetMathSqrt.cpp b/src/mathed/InsetMathSqrt.cpp index 7416c332f1..23d28e8029 100644 --- a/src/mathed/InsetMathSqrt.cpp +++ b/src/mathed/InsetMathSqrt.cpp @@ -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"); } diff --git a/src/mathed/InsetMathStackrel.cpp b/src/mathed/InsetMathStackrel.cpp index 430d8f1ad2..53e3075714 100644 --- a/src/mathed/InsetMathStackrel.cpp +++ b/src/mathed/InsetMathStackrel.cpp @@ -144,9 +144,13 @@ void InsetMathStackrel::normalize(NormalStream & os) const void InsetMathStackrel::mathmlize(MathStream & ms) const { if (nargs() > 2) - ms << "" << cell(0) << cell(2) << cell(1) << ""; + ms << "<" << from_ascii(ms.namespacedTag("munderover")) << ">" + << cell(0) << cell(2) << cell(1) + << ""; else - ms << "" << cell(0) << cell(1) << ""; + ms << "<" << from_ascii(ms.namespacedTag("mover")) << " accent='false'>" + << cell(0) << cell(1) + << ""; } diff --git a/src/mathed/InsetMathSubstack.cpp b/src/mathed/InsetMathSubstack.cpp index fb29077067..f9dfb01821 100644 --- a/src/mathed/InsetMathSubstack.cpp +++ b/src/mathed/InsetMathSubstack.cpp @@ -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"); } diff --git a/src/mathed/InsetMathSymbol.cpp b/src/mathed/InsetMathSymbol.cpp index b3b44bffdc..4a7a338fd7 100644 --- a/src/mathed/InsetMathSymbol.cpp +++ b/src/mathed/InsetMathSymbol.cpp @@ -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 << " '; + ms << sym_->xmlname; + ms << "'; } diff --git a/src/mathed/InsetMathUnderset.cpp b/src/mathed/InsetMathUnderset.cpp index 832631dfa3..2c38e3065f 100644 --- a/src/mathed/InsetMathUnderset.cpp +++ b/src/mathed/InsetMathUnderset.cpp @@ -94,7 +94,9 @@ void InsetMathUnderset::normalize(NormalStream & os) const void InsetMathUnderset::mathmlize(MathStream & ms) const { - ms << "" << cell(0) << cell(1) << ""; + ms << "<" << from_ascii(ms.namespacedTag("munder")) << " accent='false'>" + << cell(0) << cell(1) + << ""; } diff --git a/src/mathed/InsetMathXArrow.cpp b/src/mathed/InsetMathXArrow.cpp index 55f2665dad..2ea3b71b50 100644 --- a/src/mathed/InsetMathXArrow.cpp +++ b/src/mathed/InsetMathXArrow.cpp @@ -123,9 +123,9 @@ void InsetMathXArrow::mathmlize(MathStream & ms) const lyxerr << "mathmlize conversion for '" << name_ << "' not implemented" << endl; LASSERT(false, arrow = "→"); } - ms << "" + ms << "<" << from_ascii(ms.namespacedTag("munderover")) << " accent='false' accentunder='false'>" << arrow << cell(1) << cell(0) - << ""; + << ""; } diff --git a/src/mathed/MathExtern.cpp b/src/mathed/MathExtern.cpp index 504fab717b..46c544847a 100644 --- a/src/mathed/MathExtern.cpp +++ b/src/mathed/MathExtern.cpp @@ -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 << ""; + 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"); } } diff --git a/src/mathed/MathStream.cpp b/src/mathed/MathStream.cpp index 9a6c32ca21..6cf1a99d39 100644 --- a/src/mathed/MathStream.cpp +++ b/src/mathed/MathStream.cpp @@ -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() << "'; + ms.os() << ""; + 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_); } diff --git a/src/mathed/MathStream.h b/src/mathed/MathStream.h index df9d61088f..f6f6e7525d 100644 --- a/src/mathed/MathStream.h +++ b/src/mathed/MathStream.h @@ -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_; };