]> git.lyx.org Git - lyx.git/commitdiff
Escape (makeindex) special chars in nomencl if !literate
authorJuergen Spitzmueller <spitz@lyx.org>
Fri, 1 Dec 2017 12:39:38 +0000 (13:39 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Fri, 1 Dec 2017 12:39:38 +0000 (13:39 +0100)
Fixes: #10825
src/insets/InsetCommandParams.cpp
src/insets/InsetCommandParams.h
src/insets/InsetNomencl.cpp

index aa2458ce87100d2e16f614210f7f1f45f3c6caba..cae982782c6d50fc4038e4f89dfb79aa7bca68b5 100644 (file)
@@ -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;
 }
index e82320583fc4a39856bc4a3de62387ed2af3038b..eb976c28d7ce612ae5372bf2120d8400c0108ccf 100644 (file)
@@ -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 {
index 2869722fb81e066d4d183c4e36cacfff5badf063..e4394f460c98ccfa37307bc807c76c92a92e28b3 100644 (file)
@@ -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_;