]> git.lyx.org Git - features.git/commitdiff
Amend [5ed01cd6/lyxgit]
authorEnrico Forestieri <forenr@lyx.org>
Sat, 6 Feb 2021 19:07:31 +0000 (20:07 +0100)
committerEnrico Forestieri <forenr@lyx.org>
Sat, 6 Feb 2021 19:07:31 +0000 (20:07 +0100)
This commit takes into account also the case in which a prime follows
a superscript, a case not explicitly mentioned in bug 1633.
This case has to be accounted for in a different way. We cannot look
ahead when exporting, so we simply tell TeXMathStream to output an
empty group if we just output a superscript and a prime comes next.

src/mathed/InsetMathScript.cpp
src/mathed/MathStream.cpp
src/mathed/MathStream.h

index 5d522bb9d38a4482aaf9d76704a8dac889cae9aa..c06291e31da6b888834c185b70a19d49b67c3bb3 100644 (file)
@@ -511,7 +511,7 @@ void InsetMathScript::write(TeXMathStream & os) const
 
        if (!nuc().empty()) {
                os << nuc();
-               // Avoid double superscript errors (bug #1633)
+               // Avoid double superscript errors (bug 1633)
                if (os.latex() && hasUp() && nuc().back()->getChar() == '\'')
                        os << "{}";
        } else if (os.firstitem())
@@ -529,8 +529,13 @@ void InsetMathScript::write(TeXMathStream & 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())
index 6f4da39bf71b097f80089e87e565317462cce925..e14e850e1805fa7f8a85471f18ba283e7128871b 100644 (file)
@@ -111,6 +111,10 @@ TeXMathStream & operator<<(TeXMathStream & ws, docstring const & s)
                else if (s[first] == ' ' && ws.textMode())
                        ws.os() << '\\';
                ws.pendingSpace(false);
+       } else if (ws.useBraces()) {
+               if (s[first] == '\'')
+                       ws.os() << "{}";
+               ws.useBraces(false);
        }
        ws.os() << s.substr(first);
        int lf = 0;
@@ -241,6 +245,10 @@ TeXMathStream & operator<<(TeXMathStream & ws, char c)
                else if (c == ' ' && ws.textMode())
                        ws.os() << '\\';
                ws.pendingSpace(false);
+       } else if (ws.useBraces()) {
+               if (c == '\'')
+                       ws.os() << "{}";
+               ws.useBraces(false);
        }
        ws.os() << c;
        if (c == '\n')
index 153e7df3c584404a43b68ebae48db36a6ba2edce..c2dadf243a59d5c09453042ddb01b8248392b74c 100644 (file)
@@ -84,8 +84,10 @@ public:
        /// writes space if next thing is isalpha()
        bool pendingSpace() const { return pendingspace_; }
        /// write braces if a space is pending and next char is [
+       /// or when a prime immediately follows a superscript
        void useBraces(bool braces);
        /// write braces if a space is pending and next char is [
+       /// or when a prime immediately follows a superscript
        bool useBraces() const { return usebraces_; }
        /// tell whether to write the closing brace of \ensuremath
        void pendingBrace(bool brace);
@@ -128,7 +130,8 @@ private:
        OutputType output_ = wsDefault;
        /// do we have a space pending?
        bool pendingspace_ = false;
-       /// do we have to write braces when a space is pending and [ follows?
+       /// do we have to write braces when a space is pending and [ follows,
+       /// or when a prime immediately follows a superscript?
        bool usebraces_ = false;
        /// do we have a brace pending?
        bool pendingbrace_ = false;