diff --git a/src/Buffer.h b/src/Buffer.h index 7fc9e4808c..f1bd1f5e79 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -621,9 +621,6 @@ public: typedef std::set 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); diff --git a/src/mathed/InsetMathMacro.cpp b/src/mathed/InsetMathMacro.cpp index 296876b764..4b5242e5fc 100644 --- a/src/mathed/InsetMathMacro.cpp +++ b/src/mathed/InsetMathMacro.cpp @@ -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); } diff --git a/src/mathed/MathParser.cpp b/src/mathed/MathParser.cpp index 8539ab6619..436f022e25 100644 --- a/src/mathed/MathParser.cpp +++ b/src/mathed/MathParser.cpp @@ -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() == "(") { diff --git a/src/mathed/MathStream.cpp b/src/mathed/MathStream.cpp index dd274e8b8f..9a6c32ca21 100644 --- a/src/mathed/MathStream.cpp +++ b/src/mathed/MathStream.cpp @@ -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) {} diff --git a/src/mathed/MathStream.h b/src/mathed/MathStream.h index c70d3b1f39..b7e79434af 100644 --- a/src/mathed/MathStream.h +++ b/src/mathed/MathStream.h @@ -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?