]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathScript.cpp
typo
[lyx.git] / src / mathed / InsetMathScript.cpp
index 0b82d05c12ed7c86613fed7cfea3bafaec8bec85..9f391f66f93e03dfb428a0f0f9eb00624ac9d939 100644 (file)
@@ -289,7 +289,7 @@ MathClass InsetMathScript::mathClass() const
 void InsetMathScript::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        // we store this, because it is much easier
-       has_limits_ = hasLimits(mi.base.font);
+       has_limits_ = hasLimits(mi.base.font.style());
 
        // Compute metrics of the available cells
        Dimension dim0;
@@ -385,13 +385,13 @@ void InsetMathScript::drawT(TextPainter & pain, int x, int y) const
 }
 
 
-bool InsetMathScript::hasLimits(FontInfo const & font) const
+bool InsetMathScript::hasLimits(MathStyle const & style) const
 {
        if (nuc().empty())
                return false;
 
        Limits const lim = nuc().back()->limits() == AUTO_LIMITS
-               ? nuc().back()->defaultLimits(font.style() == DISPLAY_STYLE)
+               ? nuc().back()->defaultLimits(style == DISPLAY_STYLE)
                : nuc().back()->limits();
        LASSERT(lim != AUTO_LIMITS, return false);
        return lim == LIMITS;
@@ -505,13 +505,16 @@ bool InsetMathScript::idxUpDown(Cursor & cur, bool up) const
 }
 
 
-void InsetMathScript::write(WriteStream & os) const
+void InsetMathScript::write(TeXMathStream & os) const
 {
        MathEnsurer ensurer(os);
 
-       if (!nuc().empty())
+       if (!nuc().empty()) {
                os << nuc();
-       else if (os.firstitem())
+               // Avoid double superscript errors (bug 1633)
+               if (os.latex() && hasUp() && nuc().back()->getChar() == '\'')
+                       os << "{}";
+       } else if (os.firstitem())
                LYXERR(Debug::MATHED, "suppressing {} when writing");
        else
                os << "{}";
@@ -526,8 +529,13 @@ void InsetMathScript::write(WriteStream & os) const
                    (up().size() == 1 && up().back()->asBraceInset() &&
                     up().back()->asBraceInset()->cell(0).empty())))
                        os << "^ {}";
-               else
+               else {
                        os << "^{" << up() << '}';
+                       // Avoid double superscript errors by writing an
+                       // empty group {} when a prime immediately follows
+                       if (os.latex())
+                               os.useBraces(true);
+               }
        }
 
        if (lock_ && !os.latex())
@@ -598,29 +606,32 @@ void InsetMathScript::mathmlize(MathMLStream & ms) const
 {
        bool d = hasDown() && !down().empty();
        bool u = hasUp() && !up().empty();
-       // FIXME: the MathMLStream should be able to give us this information
-       bool l = has_limits_;
+       bool has_limits = hasLimits(ms.getFontMathStyle());
+
+       if (!d && !u)
+               return;
 
+       const char * tag;
        if (u && d)
-               ms << MTag(l ? "munderover" : "msubsup");
+               tag = has_limits ? "munderover" : "msubsup";
        else if (u)
-               ms << MTag(l ? "mover" : "msup");
+               tag = has_limits ? "mover" : "msup";
        else if (d)
-               ms << MTag(l ? "munder" : "msub");
+               tag = has_limits ? "munder" : "msub";
+
+       ms << MTag(tag);
 
        if (!nuc().empty())
-               ms << MTag("mrow") << nuc() << ETag("mrow");
+               ms << nuc();
        else
-               ms << "<" << from_ascii(ms.namespacedTag("mrow")) << " />";
+               ms << CTag("mrow");
 
-       if (u && d)
-               ms << MTag("mrow") << down() << ETag("mrow")
-                  << MTag("mrow") << up() << ETag("mrow")
-                  << ETag(l ? "munderover" : "msubsup");
-       else if (u)
-               ms << MTag("mrow") << up() << ETag("mrow") << ETag(l ? "mover" : "msup");
-       else if (d)
-               ms << MTag("mrow") << down() << ETag("mrow") << ETag(l ? "munder" : "msub");
+       if (d)
+               ms << MTag("mrow") << down() << ETag("mrow");
+       if (u)
+               ms << MTag("mrow") << up() << ETag("mrow");
+
+       ms << ETag(tag);
 }