When a macro with optionals appeared inside the optional argument of
another one, the onscreen display and latex output were wrong. This
issue was addressed at [
e8f480e7/lyxgit] by enclosing in braces macros
with optional arguments. However, this was done even when the macro
with optionals was in a non-optional argument of another macro.
This commit limits the bracing to the cases where it is really needed
and allows to address some particular issues evidenced in #11552.
// 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);
-
// Optional arguments:
// First find last non-empty optional argument
idx_type emptyOptFrom = 0;
// 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 && emptyOptFrom)
+ if (d->optionals_ && os.insideMacroOpt() && emptyOptFrom)
os << '{';
// Always protect macros in a fragile environment
} 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
}
// Close the opened brace or add space if there was no argument
- if (d->optionals_ && inside_macro && emptyOptFrom)
+ if (d->optionals_ && os.insideMacroOpt() && emptyOptFrom)
os << '}';
else if (first)
os.pendingSpace(true);
-
- os.insideMacro(inside_macro);
}
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),
+ 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)
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_; }
+ /// 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()
int latex_;
/// output type (default, source preview, instant preview)?
OutputType output_;
- /// are we in the argument of a math macro?
- bool insidemacro_;
+ /// 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?