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);
// 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;
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;
} 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
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);
}
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)));
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" ||
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() == "(") {
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)
{}
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()
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?