]> git.lyx.org Git - lyx.git/commitdiff
MathML stream allows for name spaces.
authorThibaut Cuvelier <cuvelier.thibaut@gmail.com>
Thu, 9 May 2019 23:52:07 +0000 (01:52 +0200)
committerPavel Sanda <sanda@lyx.org>
Thu, 18 Jun 2020 17:32:51 +0000 (19:32 +0200)
36 files changed:
src/mathed/InsetMath.cpp
src/mathed/InsetMathBig.cpp
src/mathed/InsetMathBoldSymbol.cpp
src/mathed/InsetMathBrace.cpp
src/mathed/InsetMathCancel.cpp
src/mathed/InsetMathCases.cpp
src/mathed/InsetMathChar.cpp
src/mathed/InsetMathComment.cpp
src/mathed/InsetMathDecoration.cpp
src/mathed/InsetMathDelim.cpp
src/mathed/InsetMathDots.cpp
src/mathed/InsetMathDots.h
src/mathed/InsetMathEnsureMath.cpp
src/mathed/InsetMathExFunc.cpp
src/mathed/InsetMathExInt.cpp
src/mathed/InsetMathFont.cpp
src/mathed/InsetMathFrac.cpp
src/mathed/InsetMathGrid.cpp
src/mathed/InsetMathHull.cpp
src/mathed/InsetMathMacro.cpp
src/mathed/InsetMathMatrix.cpp
src/mathed/InsetMathNumber.cpp
src/mathed/InsetMathOverset.cpp
src/mathed/InsetMathRoot.cpp
src/mathed/InsetMathScript.cpp
src/mathed/InsetMathSideset.cpp
src/mathed/InsetMathSpace.cpp
src/mathed/InsetMathSqrt.cpp
src/mathed/InsetMathStackrel.cpp
src/mathed/InsetMathSubstack.cpp
src/mathed/InsetMathSymbol.cpp
src/mathed/InsetMathUnderset.cpp
src/mathed/InsetMathXArrow.cpp
src/mathed/MathExtern.cpp
src/mathed/MathStream.cpp
src/mathed/MathStream.h

index 8706001d61dcabde80630d6a3763c7275e3cc388..8228153b95ceb99629481b0106cad0e3e76857e5 100644 (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");
 }
 
 
index 889f8d4f97842e2e926a43fca3e2272e15a0da96..5e89d4e79c720af3fe40c41bb64a8a58af9f30b0 100644 (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")) << ">";
 }
 
 
index 62f8098fa1c1ecf0ed8d8ff6c83cdb8295a6f234..5dbe1fda2859a0e7d0ae12865f0b781b288be64b 100644 (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")) << ">";
 }
 
 
index 3a452c03862a94f8763a218421994a1953324657..a31a759a419bce0a136ba8a3c4ea9de4e24b8276 100644 (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");
 }
 
 
index 25728a3680ac40e64a765b1e1d05ac1823779d2b..ee82d0c3787b76a478922bef220a0f3dc0bea1a7 100644 (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")
index 0a5fa332b1ab241b7c8a278d0534755f1c335e65..5ddb9d015e50b7f61b008c1585bf1e72f2e1eb3f 100644 (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);
 }
 
index 1137c95e75a8b0e709f91169b52465978ccc837d..7069bdcd5f0775cddcadca0d99af0dbf4c8e5d83 100644 (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 << ">";
 }
 
 
index ea502d1aa2ef1fd7a7ab504c3799f5dc49cc489e..1a248ebfaa56784dc7bd44ca94587e159d550521 100644 (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");
 }
 
 
index afb8228cb5be316def1b3882f728dfb5e78e75b9..685e65d81f540688019d5fd0888abca16112caab 100644 (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);
 }
 
 
index 1989d48dc2d9c6d840f810ba0a4123b80834ddb6..95b533b4c75a29456b0ed8c70099c70da3477dec 100644 (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";
 }
 
 
index 3679771745066e1c38e42911128e5b424a909fd5..6ec36618370cab330845419763a4d2090d6bd585 100644 (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");
 }
 
 
index 8a84a22219076e7ab8af84d11d296683bdba1e67..9155f7e11a0fa9513a324fdfeecf83d3dd124ebc 100644 (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:
index 8bd685c5a0c6181290d2261da91b7634439f5d81..55c7be78a9eb70e38e0428880ebee3732926a570 100644 (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");
 }
index e4e1f10c2e2b8daa099bcb490185c58828f1a798..9782e25cf3ff2aefdbe56b06d53aa1ca5fdf9cc1 100644 (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);
 }
 
 
index 35bee0ef08d0d61de65b77a9e3c4891bd1e8212c..537870fd9112ea3ded43d259d5a45bcca9b33cb3 100644 (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");
 }
 
 
index 6611590a4786b171f0f32b2c9f1344694ef2468e..f199ee5bcf8ad7f719c998539ae27919429a72d7 100644 (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);
 }
 
 
index 7a281a33e41819cb39d84ecaedbbd6b053825a6e..90d507cfbe38fdeee2fca069d312a29d0e6d51af 100644 (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")) << ">";
 }
 
 
index b6d90eed16b9a2081fe5d60cbc686478fb0ffe13..d6f275a3aaf518e6492af5e6f00d6e83190be159 100644 (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");
 }
 
 
index a117af6cdc2c2b7aa61b512213995dee590b8c27..465ba6466b73b46865f4e37edc2be7b221cab0db 100644 (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");
 }
 
 
index bdf86258c710a06bfef8a272fa24b8088a097333..3cabf6a818eea0136c9865e700da5cc1c999d0c2 100644 (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_;
 }
 
 
index b13d00677f37e8509f74b8e56e33bda81e2ca759..a4999039e8fb6a44798570a3e896afaff11e5f08 100644 (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")) << ">";
 }
 
 
index 5237cebab65a95747b5a67c1489950ee0e133ae7..5a35415786988fc0bbfcc06f9c4387784124775f 100644 (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")) << ">";
 }
 
 
index 3d36218d631eeabe09c99ea380aef70e4a5f4a35..2db26cf4c00983248fcaef9fdfdbf3b03b3bcc0b 100644 (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");
 }
 
 
index 6661d8555556074a8a013eed8845bfee10489251..de4253e808d5f7f05b34bc5184a8089429f50ed6 100644 (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");
 }
 
 
index 2f66b0f06e2a842331942ae3e47d49851aea5593..bc1986858d99d8426d4f07d72f5a20055d29fa57 100644 (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");
 }
 
 
index ccbab52a80ef30ad14d2bd19222c2a5be6db0c75..642e07c16a7c0d664143937ab51ad9f3693d2a32 100644 (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");
 }
 
 
index db096092b8e0d2b8767b0f960827bee9417b44ef..8e764868eb877dba43ec49667e024338318cb788 100644 (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 << " />";
index 7416c332f17593a6af750a8c903af1588ee03545..23d28e80293e7e799d3b2c122083f440dc9c63c0 100644 (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");
 }
 
 
index 430d8f1ad2e68923de318f130e7a5ce095017949..53e307571486e188ecbb4cac5e6f1291ffa7b43c 100644 (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")) << ">";
 }
 
 
index fb29077067d087d5467bb53c69651abd43379361..f9dfb01821e5bb6603a42c050cf05c75f61a1b56 100644 (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");
 }
 
 
index b3b44bffdcbf90bfa1f7195073dbace3c0f862ff..4a7a338fd70f237c2ed7c011f982f9697d425d6c 100644 (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 << '>';
 }
 
 
index 832631dfa3a8cdeb69f3c940428b80dd93398397..2c38e3065f2a2f5d054f0fbfacc870d5c796ffe8 100644 (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")) << ">";
 }
 
 
index 55f2665dad72dc7abc04a55f1f1fc0fedc66bc28..2ea3b71b5015f0c13730b3ffa806cb449c83d726 100644 (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"))<< ">";
 }
 
 
index 504fab717bee958d43df5b7802ee5277e86ef03c..46c544847a23c8fdf5bfc805422cd9315b6ab010 100644 (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");
        }
 }
 
index 9a6c32ca219f087a91ad0e2ad1d16c05877cb579..6cf1a99d398b3ecaece44ba775f0d895eba357a8 100644 (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_);
 }
 
 
index df9d61088f45b87d9d7ad018114babe6389569db..f6f6e7525d28665690814f60505288a53341740f 100644 (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_;
 };