+ int num_lines = 0;
+
+ if (os.latex()) {
+ if (optionals_ > 0) {
+ // macros with optionals use the xargs package, e.g.:
+ // \newcommandx{\foo}[2][usedefault, addprefix=\global,1=default]{#1,#2}
+ // \long is implicit by xargs
+ if (redefinition_ && !overwriteRedefinition)
+ os << "\\renewcommandx";
+ else
+ os << "\\newcommandx";
+
+ os << "\\" << name()
+ << "[" << numargs_ << "]"
+ << "[usedefault, addprefix=\\global";
+ for (int i = 0; i < optionals_; ++i) {
+ docstring optValue = asString(cell(optIdx(i)));
+ if (optValue.find(']') != docstring::npos
+ || optValue.find(',') != docstring::npos)
+ os << ", " << i + 1 << "="
+ << "{" << cell(optIdx(i)) << "}";
+ else
+ os << ", " << i + 1 << "="
+ << cell(optIdx(i));
+ }
+ os << "]";
+ } else {
+ // Macros without optionals use standard _global_ \def macros:
+ // \global\def\long\foo#1#2{#1,#2}
+ // We use the \long prefix as this is the equivalent to \newcommand.
+ // We cannot use \newcommand directly because \global does not work with it.
+ os << "\\global\\long\\def\\" << name();
+ docstring param = from_ascii("#0");
+ for (int i = 1; i <= numargs_; ++i) {
+ param[1] = '0' + i;
+ os << param;
+ }
+ }
+ } else {
+ // in LyX output we use some pseudo syntax which is implementation
+ // independent, e.g.
+ // \newcommand{\foo}[2][default]{#1,#2}