]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathChar.cpp
g-brief loads babel internally. So don't load it ourselves.
[lyx.git] / src / mathed / InsetMathChar.cpp
index decfac2d59ec8c073c0c16846c7be5dc877240ba..a642a5e6da14e8b02f16f9fbf1efbd9c71be8d95 100644 (file)
@@ -26,7 +26,6 @@
 #include "frontends/FontMetrics.h"
 
 #include "support/debug.h"
-#include "support/lstrings.h"
 #include "support/textutils.h"
 
 #include <algorithm>
@@ -36,8 +35,6 @@ using namespace std;
 
 namespace lyx {
 
-extern bool has_math_fonts;
-
 
 namespace {
 latexkeys const * makeSubstitute(char_type c)
@@ -195,8 +192,13 @@ void InsetMathChar::drawT(TextPainter & pain, int x, int y) const
 }
 
 
-void InsetMathChar::write(WriteStream & os) const
+void InsetMathChar::write(TeXMathStream & os) const
 {
+       if (os.latex() && os.pendingSpace()) {
+               if (isAlphaASCII(char_))
+                       os.os() << ' ';
+               os.pendingSpace(false);
+       }
        os.os().put(char_);
 }
 
@@ -228,7 +230,9 @@ void InsetMathChar::octave(OctaveStream & os) const
 // mathalpha, then we'll treat it as an identifier, otherwise as an
 // operator.
 // Worst case: We get bad spacing, or bad italics.
-void InsetMathChar::mathmlize(MathStream & ms) const
+// In any case, never let MathML stretch a single character when it
+// is recognised as an operator, to match TeX' behaviour.
+void InsetMathChar::mathmlize(MathMLStream & ms) const
 {
        std::string entity;
        switch (char_) {
@@ -236,10 +240,7 @@ void InsetMathChar::mathmlize(MathStream & ms) const
                case '>': entity = "&gt;"; break;
                case '&': entity = "&amp;"; break;
                case ' ': {
-                       if (ms.xmlMode())
-                               ms << from_ascii("&#0160;");
-                       else
-                               ms << from_ascii("&nbsp;");
+                       ms << from_ascii("&#0160;");
                        return;
                }
                default: break;
@@ -254,18 +255,18 @@ void InsetMathChar::mathmlize(MathStream & ms) const
        }
 
        if (!entity.empty()) {
-               ms << "<" << from_ascii(ms.namespacedTag("mo")) << ">"
+               ms << MTagInline("mo", "stretchy='false'")
                   << from_ascii(entity)
-                  << "</" << from_ascii(ms.namespacedTag("mo")) << ">";
+                  << ETagInline("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 before the end tag.
-       docstring tag = from_ascii(ms.namespacedTag(type));
-       ms << "<" << tag << ">" << char_type(char_) << "</" << tag << ">";
+       ms << MTagInline(type, std::string(type) == "mo" ? "stretchy='false'" : "")
+          << char_type(char_)
+          << ETagInline(type);
 }
 
 
@@ -278,7 +279,7 @@ void InsetMathChar::htmlize(HtmlStream & ms) const
                case '<': entity = "&lt;"; break;
                case '>': entity = "&gt;"; break;
                case '&': entity = "&amp;"; break;
-               case ' ': entity = "&nbsp;"; break;
+               case ' ': entity = "&#160;"; break;
                default: break;
        }
 
@@ -310,16 +311,27 @@ void InsetMathChar::htmlize(HtmlStream & ms) const
 MathClass InsetMathChar::mathClass() const
 {
        // this information comes from fontmath.ltx in LaTeX source.
-       char const ch = static_cast<char>(char_);
        if (subst_)
                return string_to_class(subst_->extra);
-       else if (support::contains(",;", ch))
+
+       if (!isASCII(char_))
+               return MC_ORD;
+
+       switch (static_cast<char>(char_)) {
+       case ',':
+       case ';':
                return MC_PUNCT;
-       else if (support::contains("([", ch))
+       case '(':
+       case '[':
                return MC_OPEN;
-       else if (support::contains(")]!?", ch))
+       case ')':
+       case ']':
+       case '!':
+       case '?':
                return MC_CLOSE;
-       else return MC_ORD;
+       default:
+               return MC_ORD;
+       }
 }