]> git.lyx.org Git - features.git/commitdiff
Revert [60ac25a4/lyxgit], [30f16463/lyxgit], and part of [e8f480e7/lyxgit]
authorEnrico Forestieri <forenr@lyx.org>
Fri, 26 Apr 2019 10:21:38 +0000 (12:21 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Jun 2020 13:48:27 +0000 (15:48 +0200)
As evidenced in #11552, at loading time there is no way to tell
whether braces were added by LyX with certainty. However, after
[503f7db2/lyxgit], LyX does not automatically removes brace insets.
So, in case one faces the problems mentioned in [e8f480e7/lyxgit],
the workaround of adding a brace inset now will not be frustrated.
In essence, after [503f7db2/lyxgit], the real fix for #11552 would
have been reverting the part in [e8f480e7/lyxgit] that was adding
the braces on output.

src/Buffer.h
src/mathed/InsetMathMacro.cpp
src/mathed/MathParser.cpp
src/mathed/MathStream.cpp
src/mathed/MathStream.h

index 7fc9e4808c386324c88b9bd16aecfe73501f9fa7..f1bd1f5e795ee7d85513c1217fda43971d8f875a 100644 (file)
@@ -621,9 +621,6 @@ public:
        typedef std::set<docstring> UserMacroSet;
        mutable UserMacroSet usermacros;
 
-       /// Collect user macro names with optional parameters at loading time
-       mutable UserMacroSet usermacros_with_opts;
-
        /// Replace the inset contents for insets which InsetCode is equal
        /// to the passed \p inset_code.
        void changeRefsIfUnique(docstring const & from, docstring const & to);
index 296876b764ce038742db4c8da28eaacf7f56595a..4b5242e5fc93f23e66584bdcc7c8e91fc06cea23 100644 (file)
@@ -1079,6 +1079,13 @@ void InsetMathMacro::write(WriteStream & os) const
        // we should be ok to continue even if this fails.
        LATTEST(d->macro_);
 
+       // Always protect macros in a fragile environment
+       if (os.fragile())
+               os << "\\protect";
+
+       os << "\\" << name();
+       bool first = true;
+
        // Optional arguments:
        // First find last non-empty optional argument
        idx_type emptyOptFrom = 0;
@@ -1088,18 +1095,6 @@ void InsetMathMacro::write(WriteStream & os) const
                        emptyOptFrom = i + 1;
        }
 
-       // 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_ && os.insideMacroOpt() && emptyOptFrom)
-               os << '{';
-
-       // Always protect macros in a fragile environment
-       if (os.fragile())
-               os << "\\protect";
-
-       os << "\\" << name();
-       bool first = true;
-
        // print out optionals
        for (i=0; i < cells_.size() && i < emptyOptFrom; ++i) {
                first = false;
@@ -1115,16 +1110,10 @@ void InsetMathMacro::write(WriteStream & os) const
                } else if (cell(i).size() && cell(i)[0].nucleus()->asScriptInset()) {
                        braced = cell(i)[0].nucleus()->asScriptInset()->nuc().empty();
                }
-               // We may already be in the optional argument of a macro
-               bool const inside_macro = os.insideMacroOpt();
-               os.insideMacroOpt(true);
-
                if (braced)
                        os << "[{" << cell(i) << "}]";
                else
                        os << "[" << cell(i) << "]";
-
-               os.insideMacroOpt(inside_macro);
        }
 
        // skip the tailing empty optionals
@@ -1143,10 +1132,8 @@ void InsetMathMacro::write(WriteStream & os) const
                first = false;
        }
 
-       // Close the opened brace or add space if there was no argument
-       if (d->optionals_ && os.insideMacroOpt() && emptyOptFrom)
-               os << '}';
-       else if (first)
+       // add space if there was no argument
+       if (first)
                os.pendingSpace(true);
 }
 
index 8539ab66194dd9121d983c642ef207dfd664defa..436f022e2523b5dbf32b7377035ff61f2a3095b3 100644 (file)
@@ -942,27 +942,11 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
                        cell->push_back(MathAtom(new InsetMathSpace(string(1, t.character()), "")));
 
                else if (t.cat() == catBegin) {
-                       bool const inbraces = nextToken().cat() == catBegin ||
-                               (!cell->empty() && cell->back()->asMacro());
                        MathData ar;
                        parse(ar, FLAG_BRACE_LAST, mode);
                        // do not create a BraceInset if they were written by LyX
                        // this helps to keep the annoyance of  "a choose b"  to a minimum
-                       InsetMathMacro const * ma = !inbraces && ar.size() ? ar[0]->asMacro() : 0;
-                       InsetMathChar const * mc = ma && ar.size() > 1 ? ar[1]->asCharInset(): 0;
-                       bool braced = mc && mc->getChar() == '[';
-                       // If this is a macro, it may have optional
-                       // arguments, even if only defaults are used.
-                       // In this case, there is no following '['.
-                       if (!inbraces && !braced && ma && buf) {
-                               if (mode_ & Parse::TRACKMACRO)
-                                       braced = buf->usermacros_with_opts.count(ma->name());
-                               else {
-                                       MacroData const * md = buf->getMacro(ma->name(), false);
-                                       braced = md && md->optionals();
-                               }
-                       }
-                       if ((ar.size() == 1 && ar[0]->extraBraces()) || braced)
+                       if (ar.size() == 1 && ar[0]->extraBraces())
                                cell->append(ar);
                        else
                                cell->push_back(MathAtom(new InsetMathBrace(ar)));
@@ -1150,11 +1134,8 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
                                name, nargs, optionals, MacroTypeNewcommand,
                                optionalValues, def, display)));
 
-                       if (buf && (mode_ & Parse::TRACKMACRO)) {
+                       if (buf && (mode_ & Parse::TRACKMACRO))
                                buf->usermacros.insert(name);
-                               if (optionals)
-                                       buf->usermacros_with_opts.insert(name);
-                       }
                }
 
                else if (t.cs() == "newcommandx" ||
@@ -1274,11 +1255,8 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
                                name, nargs, optionals, MacroTypeNewcommandx,
                                optionalValues, def, display)));
 
-                       if (buf && (mode_ & Parse::TRACKMACRO)) {
+                       if (buf && (mode_ & Parse::TRACKMACRO))
                                buf->usermacros.insert(name);
-                               if (optionals)
-                                       buf->usermacros_with_opts.insert(name);
-                       }
                }
 
                else if (t.cs() == "(") {
index dd274e8b8f1ff66874eeb393c636e4dd8dcbbb9a..9a6c32ca219f087a91ad0e2ad1d16c05877cb579 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_opt_(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 c70d3b1f39c5c95339367b22b508daac6164409e..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 optional argument of a math macro
-       void insideMacroOpt(bool inopt) { insidemacro_opt_ = inopt; }
-       /// tell whether we are in the optional argument of a math macro
-       bool insideMacroOpt() const { return insidemacro_opt_; }
        /// 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 optional argument of a math macro?
-       bool insidemacro_opt_;
        /// do we have a space pending?
        bool pendingspace_;
        /// do we have a brace pending?