From b68701c4da93a6f0ff618f5554b76c48373a3ac8 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Fri, 1 Dec 2017 13:39:38 +0100 Subject: [PATCH] Escape (makeindex) special chars in nomencl if !literate Fixes: #10825 --- src/insets/InsetCommandParams.cpp | 19 ++++++++++++++++++- src/insets/InsetCommandParams.h | 3 ++- src/insets/InsetNomencl.cpp | 6 ++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/insets/InsetCommandParams.cpp b/src/insets/InsetCommandParams.cpp index aa2458ce87..cae982782c 100644 --- a/src/insets/InsetCommandParams.cpp +++ b/src/insets/InsetCommandParams.cpp @@ -441,7 +441,8 @@ docstring InsetCommandParams::prepareCommand(OutputParams const & runparams, result = command; ltrimmed = true; } - if (handling & ParamInfo::HANDLING_LATEXIFY) + if (handling & ParamInfo::HANDLING_LATEXIFY + || handling & ParamInfo::HANDLING_INDEX_ESCAPE) if ((*this)["literal"] == "true") handling = ParamInfo::HANDLING_NONE; @@ -490,6 +491,22 @@ docstring InsetCommandParams::prepareCommand(OutputParams const & runparams, result = escape(command); else if (handling & ParamInfo::HANDLING_NONE) 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; } diff --git a/src/insets/InsetCommandParams.h b/src/insets/InsetCommandParams.h index e82320583f..eb976c28d7 100644 --- a/src/insets/InsetCommandParams.h +++ b/src/insets/InsetCommandParams.h @@ -45,7 +45,8 @@ public: HANDLING_NONE = 1, /// no special handling HANDLING_ESCAPE = 2, /// escape special characters 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 { diff --git a/src/insets/InsetNomencl.cpp b/src/insets/InsetNomencl.cpp index 2869722fb8..e4394f460c 100644 --- a/src/insets/InsetNomencl.cpp +++ b/src/insets/InsetNomencl.cpp @@ -65,9 +65,11 @@ ParamInfo const & InsetNomencl::findInfo(string const & /* cmdName */) if (param_info_.empty()) { param_info_.add("prefix", ParamInfo::LATEX_OPTIONAL); 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, - ParamInfo::HANDLING_LATEXIFY); + ParamInfo::ParamHandling(ParamInfo::HANDLING_ESCAPE + | ParamInfo::HANDLING_INDEX_ESCAPE)); param_info_.add("literal", ParamInfo::LYX_INTERNAL); } return param_info_; -- 2.39.2