commit 3cf5a7146359e00203344c5fb72551fdfb4b11e9
Author: Enrico Forestieri <for...@lyx.org>
Date:   Sat Feb 6 20:07:31 2021 +0100

    Amend [5ed01cd6/lyxgit]
    
    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 |    9 +++++++--
 src/mathed/MathStream.cpp      |    8 ++++++++
 src/mathed/MathStream.h        |    5 ++++-
 3 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/src/mathed/InsetMathScript.cpp b/src/mathed/InsetMathScript.cpp
index 5d522bb..c06291e 100644
--- a/src/mathed/InsetMathScript.cpp
+++ b/src/mathed/InsetMathScript.cpp
@@ -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())
diff --git a/src/mathed/MathStream.cpp b/src/mathed/MathStream.cpp
index 6f4da39..e14e850 100644
--- a/src/mathed/MathStream.cpp
+++ b/src/mathed/MathStream.cpp
@@ -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')
diff --git a/src/mathed/MathStream.h b/src/mathed/MathStream.h
index 153e7df..c2dadf2 100644
--- a/src/mathed/MathStream.h
+++ b/src/mathed/MathStream.h
@@ -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;
-- 
lyx-cvs mailing list
lyx-cvs@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to