- switch (handling) {
- case ParamInfo::HANDLING_LATEXIFY: {
- docstring uncodable;
- for (size_t n = 0; n < command.size(); ++n) {
- try {
- char_type const c = command[n];
- docstring const latex = runparams.encoding->latexChar(c).first;
- result += latex;
- if (latex.length() > 1 && latex[latex.length() - 1] != '}') {
- // Prevent eating of a following
- // space or command corruption by
- // following characters
- result += "{}";
- }
- } catch (EncodingException & /* e */) {
- LYXERR0("Uncodable character in command inset!");
- if (runparams.dryrun) {
- result += "<" + _("LyX Warning: ")
- + _("uncodable character") + " '";
- result += docstring(1, command[n]);
- result += "'>";
- } else
- uncodable += command[n];
- }
- }
- if (!uncodable.empty()) {
- // issue a warning about omitted characters
+ bool ltrimmed = false;
+ // Trimming can be done on top of any of the other handlings
+ // We check this here since handling might be changed below.
+ if (handling & ParamInfo::HANDLING_LTRIM) {
+ // this is used if no other handling is done
+ result = command;
+ ltrimmed = true;
+ }
+ if (handling & ParamInfo::HANDLING_LATEXIFY
+ || handling & ParamInfo::HANDLING_INDEX_ESCAPE)
+ if ((*this)["literal"] == "true")
+ handling = ParamInfo::HANDLING_NONE;
+
+ // LATEXIFY, ESCAPE and NONE are mutually exclusive
+ if (handling & ParamInfo::HANDLING_LATEXIFY) {
+ // First handle backslash
+ result = subst(command, from_ascii("\\"), from_ascii("\\textbackslash{}"));
+ // Then get LaTeX macros
+ pair<docstring, docstring> command_latexed =
+ runparams.encoding->latexString(result, runparams.dryrun);
+ result = command_latexed.first;
+ if (!command_latexed.second.empty()) {
+ // Issue a warning about omitted characters