// LATEXIFY, ESCAPE and NONE are mutually exclusive
if (handling & ParamInfo::HANDLING_LATEXIFY) {
// First handle backslash
- result = subst(command, from_ascii("\\"), from_ascii("\\textbackslash{}"));
+ // we cannot replace yet with \textbackslash{}
+ // as the braces would be erroneously escaped
+ // in the following routines ("\textbackslash\{\}").
+ // So create a unique placeholder which is replaced
+ // in the end.
+ docstring bs = from_ascii("@LyXBackslash@");
+ // We are super-careful and assure the placeholder
+ // does not exist in the string
+ for (int i = 0; ; ++i) {
+ if (!contains(command, bs)) {
+ result = subst(command, from_ascii("\\"), bs);
+ break;
+ }
+ bs = from_ascii("@LyXBackslash") + i + '@';
+ }
// Then get LaTeX macros
pair<docstring, docstring> command_latexed =
runparams.encoding->latexString(result, runparams.dryrun);
result.replace(pos, 1, backslash + chars_escape[k] + term);
}
}
+ // set in real backslash now
+ result = subst(result, bs, from_ascii("\\textbackslash{}"));
}
else if (handling & ParamInfo::HANDLING_ESCAPE)
result = escape(command);