]> git.lyx.org Git - features.git/commitdiff
Use SetMode() to manage text and math mode.
authorRichard Heck <rgheck@comcast.net>
Thu, 31 Dec 2009 18:38:01 +0000 (18:38 +0000)
committerRichard Heck <rgheck@comcast.net>
Thu, 31 Dec 2009 18:38:01 +0000 (18:38 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@32703 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/InsetMathChar.cpp
src/mathed/InsetMathFont.cpp

index 7949c230991a1ea4de5310d8fefeca36103984cd..8832a751a87e0ca43c2163a40b92f16568f57c65 100644 (file)
@@ -167,13 +167,27 @@ void InsetMathChar::octave(OctaveStream & os) const
 // Worst case: We get bad spacing, or bad italics.
 void InsetMathChar::mathmlize(MathStream & ms) const
 {
+       std::string entity;
        switch (char_) {
-               case '<': ms << "<mo>&lt;</mo>"; return;
-               case '>': ms << "<mo>&gt;</mo>"; return;
-               case '&': ms << "<mo>&amp;</mo>"; return;
+               case '<': entity = "&lt;"; break;
+               case '>': entity = "&gt;"; break;
+               case '&': entity = "&amp;"; break;
                default: break;
        }
        
+       if (ms.inText()) {
+               if (entity.empty())
+                       ms << char_type(char_);
+               else 
+                       ms << from_ascii(entity);
+               return;
+       }
+       
+       if (!entity.empty()) {
+               ms << "<mo>" << from_ascii(entity) << "</mo>";
+               return;
+       }               
+
        char const * type = 
                (isalpha(char_) || Encodings::isMathAlpha(char_))
                        ? "mi" : "mo";
index 344e586ff1c2f403e21ec1904dc37ec0d12433f4..5909c14c9bd630e8d153b8814fcc3ec8b4f1198c 100644 (file)
@@ -113,33 +113,39 @@ void InsetMathFont::mathmlize(MathStream & os) const
        // correctly. A proper fix would presumably involve tracking
        // the fonts already in effect.
        std::string variant;
-       if (key_->name == "mathnormal" || key_->name == "mathrm"
-           || key_->name == "text" || key_->name == "textnormal"
-           || key_->name == "textrm" || key_->name == "textup"
-           || key_->name == "textmd")
+       docstring const & tag = key_->name;
+       if (tag == "mathnormal" || tag == "mathrm"
+           || tag == "text" || tag == "textnormal"
+           || tag == "textrm" || tag == "textup"
+           || tag == "textmd")
                variant = "normal";
-       else if (key_->name == "frak" || key_->name == "mathfrak")
+       else if (tag == "frak" || tag == "mathfrak")
                variant = "fraktur";
-       else if (key_->name == "mathbb" || key_->name == "mathbf"
-                || key_->name == "textbf")
+       else if (tag == "mathbb" || tag == "mathbf"
+                || tag == "textbf")
                variant = "bold";
-       else if (key_->name == "mathcal")
+       else if (tag == "mathcal")
                variant == "script";
-       else if (key_->name == "mathit" || key_->name == "textsl"
-                || key_->name == "emph")
+       else if (tag == "mathit" || tag == "textsl"
+                || tag == "emph")
                variant = "italic";
-       else if (key_->name == "mathsf" || key_->name == "textit"
-                || key_->name == "textsf")
+       else if (tag == "mathsf" || tag == "textit"
+                || tag == "textsf")
                variant = "sans-serif";
-       else if (key_->name == "mathtt" || key_->name == "texttt")
+       else if (tag == "mathtt" || tag == "texttt")
                variant = "monospace";
        // no support at present for textipa, textsc, noun
        
        // FIXME We need some kind of "mode tracker", so we can
        // just output verbatim text in some cases.
-       if (!variant.empty())
-               os << "<mstyle mathvariant='" << from_utf8(variant) << "'>"
-                  << cell(0) << "</mstyle>";
+       docstring const beg = (tag.size() < 4) ? from_ascii("") : tag.substr(0, 4);
+       bool const textmode = (beg == "text");
+       if (!variant.empty()) {
+               os << "<mstyle mathvariant='" << from_utf8(variant) << "'>";
+               SetMode sm(os, textmode);
+               os << cell(0);
+               os << "</mstyle>";
+       }
 }