Escape (makeindex) special chars in nomencl if !literate

Fixes: #10825
(cherry picked from commit b68701c4da)
This commit is contained in:
Juergen Spitzmueller 2017-12-01 13:39:38 +01:00
parent f97832ba5f
commit a4aee2a090
3 changed files with 24 additions and 4 deletions

View File

@ -441,7 +441,8 @@ docstring InsetCommandParams::prepareCommand(OutputParams const & runparams,
result = command; result = command;
ltrimmed = true; ltrimmed = true;
} }
if (handling & ParamInfo::HANDLING_LATEXIFY) if (handling & ParamInfo::HANDLING_LATEXIFY
|| handling & ParamInfo::HANDLING_INDEX_ESCAPE)
if ((*this)["literal"] == "true") if ((*this)["literal"] == "true")
handling = ParamInfo::HANDLING_NONE; handling = ParamInfo::HANDLING_NONE;
@ -490,6 +491,22 @@ docstring InsetCommandParams::prepareCommand(OutputParams const & runparams,
result = escape(command); result = escape(command);
else if (handling & ParamInfo::HANDLING_NONE) else if (handling & ParamInfo::HANDLING_NONE)
result = command; result = command;
// INDEX_ESCAPE is independent of the others
if (handling & ParamInfo::HANDLING_INDEX_ESCAPE) {
// Now escape special commands
static docstring const quote = from_ascii("\"");
static char_type const chars_escape[4] = { '"', '@', '|', '!' };
if (!result.empty()) {
// The characters in chars_name[] need to be changed to a command when
// they are LaTeXified.
for (int k = 0; k < 4; k++)
for (size_t i = 0, pos;
(pos = result.find(chars_escape[k], i)) != string::npos;
i = pos + 2)
result.replace(pos, 1, quote + chars_escape[k]);
}
}
return ltrimmed ? ltrim(result) : result; return ltrimmed ? ltrim(result) : result;
} }

View File

@ -45,7 +45,8 @@ public:
HANDLING_NONE = 1, /// no special handling HANDLING_NONE = 1, /// no special handling
HANDLING_ESCAPE = 2, /// escape special characters HANDLING_ESCAPE = 2, /// escape special characters
HANDLING_LATEXIFY = 4, /// transform special characters to LaTeX macros HANDLING_LATEXIFY = 4, /// transform special characters to LaTeX macros
HANDLING_LTRIM = 8 /// trim blanks on the left HANDLING_LTRIM = 8, /// trim blanks on the left
HANDLING_INDEX_ESCAPE = 16, /// escape makeindex special chars
}; };
/// ///
class ParamData { class ParamData {

View File

@ -65,9 +65,11 @@ ParamInfo const & InsetNomencl::findInfo(string const & /* cmdName */)
if (param_info_.empty()) { if (param_info_.empty()) {
param_info_.add("prefix", ParamInfo::LATEX_OPTIONAL); param_info_.add("prefix", ParamInfo::LATEX_OPTIONAL);
param_info_.add("symbol", ParamInfo::LATEX_REQUIRED, param_info_.add("symbol", ParamInfo::LATEX_REQUIRED,
ParamInfo::HANDLING_LATEXIFY); ParamInfo::ParamHandling(ParamInfo::HANDLING_ESCAPE
| ParamInfo::HANDLING_INDEX_ESCAPE));
param_info_.add("description", ParamInfo::LATEX_REQUIRED, param_info_.add("description", ParamInfo::LATEX_REQUIRED,
ParamInfo::HANDLING_LATEXIFY); ParamInfo::ParamHandling(ParamInfo::HANDLING_ESCAPE
| ParamInfo::HANDLING_INDEX_ESCAPE));
param_info_.add("literal", ParamInfo::LYX_INTERNAL); param_info_.add("literal", ParamInfo::LYX_INTERNAL);
} }
return param_info_; return param_info_;