]> git.lyx.org Git - features.git/commitdiff
Fix bug #11552
authorEnrico Forestieri <forenr@lyx.org>
Tue, 25 Jun 2019 20:09:12 +0000 (22:09 +0200)
committerEnrico Forestieri <forenr@lyx.org>
Tue, 25 Jun 2019 20:09:12 +0000 (22:09 +0200)
Do not write supefluous braces in optionals of a macro when saving.

src/mathed/InsetMathMacro.cpp
src/mathed/MathStream.cpp
src/mathed/MathStream.h
status.23x

index 1164abf06fb0f8acfab3daa682370a43bf974fb6..5e72eecdc27850b4737e833593b420df9f9f4bdb 100644 (file)
@@ -1082,15 +1082,6 @@ void InsetMathMacro::write(WriteStream & os) const
        // we should be ok to continue even if this fails.
        LATTEST(d->macro_);
 
-       // We may already be in the argument of a macro
-       bool const inside_macro = os.insideMacro();
-       os.insideMacro(true);
-
-       // Enclose in braces to avoid latex errors with xargs if we have
-       // optional arguments and are in the optional argument of a macro
-       if (d->optionals_ && inside_macro)
-               os << '{';
-
        // Always protect macros in a fragile environment
        if (os.fragile())
                os << "\\protect";
@@ -1113,14 +1104,24 @@ void InsetMathMacro::write(WriteStream & os) const
                // For correctly parsing it when a document is reloaded, we
                // need to enclose an optional argument in braces if it starts
                // with a script inset with empty nucleus or ends with a
-               // delimiter-size-modifier macro (see #10497 and #11346)
+               // delimiter-size-modifier macro (see #10497 and #11346).
+               // We also need to do that when the optional argument
+               // contains macros with optionals.
                bool braced = false;
                size_type last = cell(i).size() - 1;
-               if (cell(i).size() && cell(i)[last].nucleus()->asUnknownInset()) {
-                       latexkeys const * l = in_word_set(cell(i)[last].nucleus()->name());
+               if (cell(i).size() && cell(i)[last]->asUnknownInset()) {
+                       latexkeys const * l = in_word_set(cell(i)[last]->name());
                        braced = (l && l->inset == "big");
-               } else if (cell(i).size() && cell(i)[0].nucleus()->asScriptInset()) {
-                       braced = cell(i)[0].nucleus()->asScriptInset()->nuc().empty();
+               } else if (cell(i).size() && cell(i)[0]->asScriptInset()) {
+                       braced = cell(i)[0]->asScriptInset()->nuc().empty();
+               } else {
+                       for (size_type j = 0; j < cell(i).size(); ++j) {
+                               InsetMathMacro const * ma = cell(i)[j]->asMacro();
+                               if (ma && ma->optionals()) {
+                                       braced = true;
+                                       break;
+                               }
+                       }
                }
                if (braced)
                        os << "[{" << cell(i) << "}]";
@@ -1144,13 +1145,9 @@ void InsetMathMacro::write(WriteStream & os) const
                first = false;
        }
 
-       // Close the opened brace or add space if there was no argument
-       if (d->optionals_ && inside_macro)
-               os << '}';
-       else if (first)
+       // add space if there was no argument
+       if (first)
                os.pendingSpace(true);
-
-       os.insideMacro(inside_macro);
 }
 
 
index b2d01cfb688612637c0f27f16abad0cd2355353c..acb7ee76a81c144d873efc49f469cc696bbbb983 100644 (file)
@@ -128,10 +128,10 @@ WriteStream & operator<<(WriteStream & ws, docstring const & s)
 WriteStream::WriteStream(otexrowstream & os, bool fragile, bool latex,
                                                 OutputType output, Encoding const * encoding)
        : os_(os), fragile_(fragile), firstitem_(false), latex_(latex),
-         output_(output), insidemacro_(false), pendingspace_(false),
-         pendingbrace_(false), textmode_(false), locked_(0), ascii_(0),
-         canbreakline_(true), mathsout_(false), ulemcmd_(NONE), line_(0),
-         encoding_(encoding), row_entry_(TexRow::row_none)
+         output_(output), pendingspace_(false), pendingbrace_(false),
+         textmode_(false), locked_(0), ascii_(0), canbreakline_(true),
+         mathsout_(false), ulemcmd_(NONE), line_(0), encoding_(encoding),
+         row_entry_(TexRow::row_none)
 {}
 
 
index 19da27640afd9e820c70d2f72c14d423a8ebfff1..b7e79434af1c02bea66f460abc4b39e215fe7648 100644 (file)
@@ -81,10 +81,6 @@ public:
        void ulemCmd(UlemCmdType ulemcmd) { ulemcmd_ = ulemcmd; }
        /// tell which ulem command type we are inside
        UlemCmdType ulemCmd() const { return ulemcmd_; }
-       /// record whether we are in the argument of a math macro
-       void insideMacro(bool insidemacro) { insidemacro_ = insidemacro; }
-       /// tell whether we are in the argument of a math macro
-       bool insideMacro() const { return insidemacro_; }
        /// writes space if next thing is isalpha()
        void pendingSpace(bool how);
        /// writes space if next thing is isalpha()
@@ -124,8 +120,6 @@ private:
        int latex_;
        /// output type (default, source preview, instant preview)?
        OutputType output_;
-       /// are we in the argument of a math macro?
-       bool insidemacro_;
        /// do we have a space pending?
        bool pendingspace_;
        /// do we have a brace pending?
index 91ca6df1deaa715c9bed02ef193623dcf6147568..964a5397a5a4492cf546f9b072ce38388630be1c 100644 (file)
@@ -52,6 +52,8 @@ Avoid using text mode for unicode symbols representable in math mode (bug 9616).
 
 - Avoid adding spaces when parsing an array in a macro template (bug 10499).
 
+- Avoid superfluous braces in the optional argument of a macro (bug 11552).
+
 
 * USER INTERFACE