]> git.lyx.org Git - lyx.git/commitdiff
Add EscapeChars layout tag
authorJuergen Spitzmueller <spitz@lyx.org>
Mon, 12 Aug 2024 10:25:31 +0000 (12:25 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Mon, 12 Aug 2024 10:25:31 +0000 (12:25 +0200)
This allows to define chars to be escape and an escape character

Needed in index and nomenclature

13 files changed:
lib/doc/Customization.lyx
lib/doc/de/Customization.lyx
lib/scripts/layout2layout.py
src/Layout.cpp
src/Layout.h
src/OutputParams.h
src/Paragraph.cpp
src/TextClass.cpp
src/insets/InsetArgument.cpp
src/insets/InsetArgument.h
src/insets/InsetLayout.cpp
src/insets/InsetLayout.h
src/insets/InsetText.cpp

index 5c1dbafc5edc41a5fbcc86f26973b7182a72c631..cef51f803b9264ec89c71116166c1dcfb5010fa9 100644 (file)
@@ -13040,6 +13040,97 @@ EndLabelType
  
 \end_layout
 
+\begin_layout Description
+
+\change_inserted -712698321 1723455721
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1723455730
+EscapeChars
+\end_layout
+
+\end_inset
+
+ [
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1723455616
+string
+\end_layout
+
+\end_inset
+
+]
+\family typewriter
+\family default
+Defines individual characters that should be escaped in the context of this paragraph.
+ Not that the first character in the string denotes the escape character,
+ so 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1723455696
+%!@
+\change_unchanged
+
+\end_layout
+
+\end_inset
+
+ will escape 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1723455704
+!
+\change_unchanged
+
+\end_layout
+
+\end_inset
+
+ and 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1723455712
+@
+\change_unchanged
+
+\end_layout
+
+\end_inset
+
+ with 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1723455721
+%
+\change_unchanged
+
+\end_layout
+
+\end_inset
+
+.
+\end_layout
+
 \begin_layout Description
 \begin_inset Flex Code
 status collapsed
@@ -19671,6 +19762,43 @@ InsetLayout
 \end_inset
 
  declarations.
+\change_inserted -712698321 1723455878
+
+\end_layout
+
+\begin_layout Description
+
+\change_inserted -712698321 1723455890
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1723455884
+EscapeChars
+\end_layout
+
+\end_inset
+
+ [
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1723455884
+string
+\end_layout
+
+\end_inset
+
+]
+\family typewriter
+\family default
+Defines individual characters that should be escaped in the context of this inset.
+\change_unchanged
+
 \end_layout
 
 \begin_layout Description
@@ -22645,6 +22773,96 @@ Classic
 \end_inset
 
 ] describes the rendering style used for the inset's frame and buttons.
+\change_inserted -712698321 1723455759
+
+\end_layout
+
+\begin_layout Itemize
+
+\change_inserted -712698321 1723455909
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1723455760
+EscapeChars
+\end_layout
+
+\end_inset
+
+ [
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1723455760
+string
+\end_layout
+
+\end_inset
+
+]
+\family typewriter
+\family default
+Defines individual characters that should be escaped in the context of this paragraph.
+ Note that the first character in the string denotes the escape character,
+ so 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1723455760
+%!@
+\end_layout
+
+\end_inset
+
+ will escape 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1723455760
+!
+\end_layout
+
+\end_inset
+
+ and 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1723455760
+@
+\end_layout
+
+\end_inset
+
+ with 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1723455760
+%
+\end_layout
+
+\end_inset
+
+.
+ Note that this needs to be explicitly defined for arguments.
+ That is,
+ arguments do not inherit EscapeChars from their parent inset or layout.
+\change_unchanged
+
 \end_layout
 
 \begin_layout Itemize
index 18e3a342bd510e3046b537ba21a77ae52a97edc4..7932ef56bfeb2eb8ac445e4df1071b935cd146a0 100644 (file)
@@ -11504,6 +11504,78 @@ EndLabelType
 \begin_inset Flex Code
 status collapsed
 
+\begin_layout Plain Layout
+EscapeChars
+\end_layout
+
+\end_inset
+
+ [
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+string
+\end_layout
+
+\end_inset
+
+]
+\family typewriter
+\family default
+Definiert Zeichen,
+ die im Kontext dieses Absatzes maskiert werden müssen.
+ Beachten Sie,
+ dass das erste Zeichen in der Kette das Maskierungszeichen selbst ist.
+ Das heißt,
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+%!@
+\end_layout
+
+\end_inset
+
+ maskiert 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+!
+\end_layout
+
+\end_inset
+
+ und 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+@
+\end_layout
+
+\end_inset
+
+ mit 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+%
+\end_layout
+
+\end_inset
+
+.
+\end_layout
+
+\begin_layout Description
+\begin_inset Flex Code
+status collapsed
+
 \begin_layout Plain Layout
 Font
 \end_layout
@@ -18461,6 +18533,91 @@ InsetLayout
 \begin_inset Flex Code
 status collapsed
 
+\begin_layout Plain Layout
+EscapeChars
+\end_layout
+
+\end_inset
+
+ [
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+string
+\end_layout
+
+\end_inset
+
+]
+\family typewriter
+\family default
+Definiert Zeichen,
+ die im Kontext dieses Absatzes maskiert werden müssen.
+ Beachten Sie,
+ dass das erste Zeichen in der Kette das Maskierungszeichen selbst ist.
+ Das heißt,
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+%!@
+\end_layout
+
+\end_inset
+
+ maskiert 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+!
+\end_layout
+
+\end_inset
+
+ und 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+@
+\end_layout
+
+\end_inset
+
+ mit 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+%
+\end_layout
+
+\end_inset
+
+.
+ Beachten Sie,
+ dass ein Wert für Argumente explizit spezifiziert werden muss.
+ Argumente übernehmen also nicht die 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+EscapeChars
+\end_layout
+
+\end_inset
+
+ des zugehörigen Absatzstils oder der zugehörigen Einfügung.
+\end_layout
+
+\begin_layout Description
+\begin_inset Flex Code
+status collapsed
+
 \begin_layout Plain Layout
 Font
 \end_layout
@@ -20359,6 +20516,61 @@ nolink "false"
 \begin_inset Flex Code
 status collapsed
 
+\begin_layout Plain Layout
+PassThruChars
+\end_layout
+
+\end_inset
+
+ [
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+Buchstabenkette
+\end_layout
+
+\end_inset
+
+]
+\family typewriter
+\family default
+bestimmt einzelne Zeichen,
+ für die der Inhalt dieses Arguments in unbearbeiteter Form,
+ ohne spezifische Bearbeitung,
+ die \SpecialChar LaTeX
+ verlangen würde,
+ ausgegeben wird.
+ Beachten Sie,
+ dass anders als bei 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+PassThru
+\end_layout
+
+\end_inset
+
+ ein Wert für Argumente explizit spezifiziert werden muss.
+ Argumente übernehmen also nicht die 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+PassThruChars
+\end_layout
+
+\end_inset
+
+ des zugehörigen Absatzstils oder der zugehörigen Einfügung.
+\end_layout
+
+\begin_layout Description
+\begin_inset Flex Code
+status collapsed
+
 \begin_layout Plain Layout
 Preamble
 \end_layout
@@ -21555,6 +21767,91 @@ status collapsed
 \begin_inset Flex Code
 status collapsed
 
+\begin_layout Plain Layout
+EscapeChars
+\end_layout
+
+\end_inset
+
+ [
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+string
+\end_layout
+
+\end_inset
+
+]
+\family typewriter
+\family default
+Definiert Zeichen,
+ die im Kontext dieses Absatzes maskiert werden müssen.
+ Beachten Sie,
+ dass das erste Zeichen in der Kette das Maskierungszeichen selbst ist.
+ Das heißt,
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+%!@
+\end_layout
+
+\end_inset
+
+ maskiert 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+!
+\end_layout
+
+\end_inset
+
+ und 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+@
+\end_layout
+
+\end_inset
+
+ mit 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+%
+\end_layout
+
+\end_inset
+
+.
+ Beachten Sie,
+ dass ein Wert für Argumente explizit spezifiziert werden muss.
+ Argumente übernehmen also nicht die 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+EscapeChars
+\end_layout
+
+\end_inset
+
+ des zugehörigen Absatzstils oder der zugehörigen Einfügung.
+\end_layout
+
+\begin_layout Itemize
+\begin_inset Flex Code
+status collapsed
+
 \begin_layout Plain Layout
 PassThru
 \end_layout
index 428cf709a4ddc0d5c052e2c2af253a3ed1b9e93f..b90350e10984dbd019bc58711cd435f4446b5f94 100644 (file)
@@ -9,7 +9,7 @@
 # This script will update a .layout file to current format
 
 # The latest layout format is also defined in src/TextClass.cpp
-currentFormat = 106
+currentFormat = 107
 
 
 # Incremented to format 4, 6 April 2007, lasgouttes
@@ -355,6 +355,9 @@ currentFormat = 106
 # Incremented to format 106, 7 July 2024 by spitz
 # New CiteEngine type "notes"
 
+# Incremented to format 107, 12 August 2023 by spitz
+# New InsetLayout and Layout tags "EscapeChars"
+
 # Do not forget to document format change in Customization
 # Manual (section "Declaring a new text class").
 
@@ -589,7 +592,7 @@ def convert(lines, end_format):
                 i += 1
             continue
 
-        if 101 <= format <= 105:
+        if 101 <= format <= 106:
             # nothing to do.
             i += 1
             continue
index e531fab362f193e31bcf2a638be34f2c0600f7ab..fa5ab4b7ae8644513648b67262ef3b0d82e6db6d 100644 (file)
@@ -48,6 +48,7 @@ enum LayoutTags {
        LT_DEPENDSON,
        LT_OBSOLETEDBY,
        LT_END,
+       LT_ESCAPE_CHARS,
        LT_FONT,
        LT_FREE_SPACING,
        LT_PASS_THRU,
@@ -272,6 +273,7 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass,
                { "end",            LT_END },
                { "endlabelstring", LT_ENDLABELSTRING },
                { "endlabeltype",   LT_ENDLABELTYPE },
+               { "escapechars",    LT_ESCAPE_CHARS },
                { "font",           LT_FONT },
                { "forcelocal",     LT_FORCELOCAL },
                { "freespacing",    LT_FREE_SPACING },
@@ -667,6 +669,10 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass,
                        lex >> pass_thru;
                        break;
 
+               case LT_ESCAPE_CHARS:
+                       lex >> escape_chars;
+                       break;
+
                case LT_PASS_THRU_CHARS:
                        lex >> pass_thru_chars;
                        break;
@@ -1291,6 +1297,9 @@ void Layout::readArgument(Lexer & lex, bool validating)
                        arg.font = lyxRead(lex, arg.font);
                } else if (tok == "labelfont") {
                        arg.labelfont = lyxRead(lex, arg.labelfont);
+               } else if (tok == "escapechars") {
+                       lex.next();
+                       arg.escape_chars = lex.getDocString();
                } else if (tok == "passthruchars") {
                        lex.next();
                        arg.pass_thru_chars = lex.getDocString();
@@ -1385,6 +1394,8 @@ void writeArgument(ostream & os, string const & id, Layout::latexarg const & arg
                        os << "\t\tPassThru inherited\n";
                        break;
        }
+       if (!arg.escape_chars.empty())
+               os << "\t\tEscapeChars \"" << to_utf8(arg.escape_chars) << "\"\n";
        if (!arg.pass_thru_chars.empty())
                os << "\t\tPassThruChars \"" << to_utf8(arg.pass_thru_chars) << "\"\n";
        if (arg.free_spacing)
@@ -1638,6 +1649,8 @@ void Layout::write(ostream & os) const
                os << "\tLabelCounter \"" << to_utf8(counter) << "\"\n";
        os << "\tFreeSpacing " << free_spacing << '\n';
        os << "\tPassThru " << pass_thru << '\n';
+       if (!escape_chars.empty())
+               os << "\tEscapeChars " << to_utf8(escape_chars) << '\n';
        if (!pass_thru_chars.empty())
                os << "\tPassThruChars " << to_utf8(pass_thru_chars) << '\n';
        os << "\tParbreakIsNewline " << parbreak_is_newline << '\n';
index eef0bee2903c6b024f9eab60bd1690f5eb012326..c8f08439f577b022943adbc370e985ead887af03 100644 (file)
@@ -109,6 +109,7 @@ public:
                bool insertcotext = false;
                bool insertonnewline = false;
                ArgPassThru passthru = PT_INHERITED;
+               docstring escape_chars;
                docstring pass_thru_chars;
                bool is_toc_caption = false;
                bool free_spacing = false;
@@ -385,6 +386,8 @@ public:
        bool free_spacing;
        ///
        bool pass_thru;
+       /// Individual chars to be escaped
+       docstring escape_chars;
        /// Individual chars to be passed verbatim
        docstring pass_thru_chars;
        /// Individual characters that must not be
index 306087dfdfaa8264959a69e4397ae0a1e8abcc1c..b063653b8ad31130e505e9d9039441c6db2fb684 100644 (file)
@@ -379,6 +379,9 @@ public:
        /// Should we output verbatim or escape LaTeX's special chars?
        bool pass_thru = false;
 
+       /// Should we escape specific chars?
+       docstring escape_chars;
+
        /// Should we output verbatim specific chars?
        docstring pass_thru_chars;
 
index 9d8acf84e066a95eb92d3f2209a0e18a99649c72..e485c1a852da159ef1cee875b64e4e349c884b70 100644 (file)
@@ -1253,6 +1253,17 @@ void Paragraph::Private::latexSpecialChar(otexstream & os,
                return;
        }
 
+       if (!style.escape_chars.empty() && contains(style.escape_chars.substr(1), c)){
+               os << style.escape_chars.substr(0,1);
+               os.put(c);
+               return;
+       }
+       if (!runparams.escape_chars.empty() && contains(runparams.escape_chars.substr(1), c)){
+               os << runparams.escape_chars.substr(0,1);
+               os.put(c);
+               return;
+       }
+
        if ((style.pass_thru || runparams.pass_thru || runparams.find_effective()
            || contains(style.pass_thru_chars, c)
            || contains(runparams.pass_thru_chars, c))
index 933489743d9a4439f7ae4e79f68039ee1cccd18a..8600b64d660202a906b9248aaea5d6dd761a03ce 100644 (file)
@@ -59,7 +59,7 @@ namespace lyx {
 // You should also run the development/tools/updatelayouts.py script,
 // to update the format of all of our layout files.
 //
-int const LAYOUT_FORMAT = 106; // spitz: CiteEngineType notes
+int const LAYOUT_FORMAT = 107; // spitz: EscapeChars
 
 
 // Layout format for the current lyx file format. Controls which format is
index c4708c8d42f468be0222d07bd0249cc86942315f..90886e43d3340167ba6582f6b47d257d016a457f 100644 (file)
@@ -45,8 +45,8 @@ InsetArgument::InsetArgument(Buffer * buf, string const & name)
     : InsetCollapsible(buf), name_(name), labelstring_(docstring()),
       font_(inherit_font), labelfont_(inherit_font), decoration_(string()),
       pass_thru_context_(false), pass_thru_local_(false), pass_thru_(false),
-      free_spacing_(false), pass_thru_chars_(docstring()), is_toc_caption_(false),
-      newline_cmd_(string())
+      free_spacing_(false), escape_chars_(docstring()), pass_thru_chars_(docstring()),
+      is_toc_caption_(false), newline_cmd_(string())
 {}
 
 
@@ -120,6 +120,7 @@ void InsetArgument::init(Paragraph const & par)
                font_ = (*lait).second.font;
                labelfont_ = (*lait).second.labelfont;
                decoration_ = (*lait).second.decoration;
+               escape_chars_ = (*lait).second.escape_chars;
                pass_thru_chars_ = (*lait).second.pass_thru_chars;
                newline_cmd_ = (*lait).second.newlinecmd;
                free_spacing_ = (*lait).second.free_spacing;
@@ -342,6 +343,8 @@ void InsetArgument::latexArgument(otexstream & os,
 {
        otexstringstream ots;
        OutputParams runparams = runparams_in;
+       if (!escape_chars_.empty())
+               runparams.escape_chars = escape_chars_;
        if (!pass_thru_chars_.empty())
                runparams.pass_thru_chars += pass_thru_chars_;
        if (!newline_cmd_.empty())
index a3dd7d05bf77a82245a09978b063cd1a1737f631..0bf18876623599af2459f137edbf31d231d2cea9 100644 (file)
@@ -125,6 +125,8 @@ private:
        ///
        bool free_spacing_;
        ///
+       docstring escape_chars_;
+       ///
        docstring pass_thru_chars_;
        /// Does this argument provide content for the TOC?
        bool is_toc_caption_;
index 024c81e40b7f8211dc9f41f156b120166ace5ffc..61e574a9ac1bfa35f795635aad341b0bce749869 100644 (file)
@@ -123,6 +123,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass,
                IL_DOCBOOKINNERATTR,
                IL_DOCBOOKNOFONTINSIDE,
                IL_DOCBOOKRENDERASIMAGE,
+               IL_ESCAPE_CHARS,
                IL_INHERITFONT,
                IL_INTOC,
                IL_ISTOCCAPTION,
@@ -197,6 +198,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass,
                { "docbookwrappertagtype", IL_DOCBOOKWRAPPERTAGTYPE },
                { "editexternal", IL_EDITEXTERNAL },
                { "end", IL_END },
+               { "escapechars", IL_ESCAPE_CHARS },
                { "fixedwidthpreambleencoding", IL_FIXEDWIDTH_PREAMBLE_ENCODING },
                { "font", IL_FONT },
                { "forcelocalfontswitch", IL_FORCE_LOCAL_FONT_SWITCH },
@@ -384,6 +386,9 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass,
                        lex >> forceplain_;
                        readCustomOrPlain = true;
                        break;
+               case IL_ESCAPE_CHARS:
+                       lex >> escape_chars_;
+                       break;
                case IL_PASSTHRU:
                        lex >> passthru_;
                        break;
@@ -922,6 +927,9 @@ void InsetLayout::readArgument(Lexer & lex)
                        arg.font = lyxRead(lex, arg.font);
                } else if (tok == "labelfont") {
                        arg.labelfont = lyxRead(lex, arg.labelfont);
+               } else if (tok == "escapechars") {
+                       lex.next();
+                       arg.escape_chars = lex.getDocString();
                } else if (tok == "passthruchars") {
                        lex.next();
                        arg.pass_thru_chars = lex.getDocString();
index a426a4ca860f512d4b566bd3a30c6dace23588fd..be9aabfafe882bc6bfd7a6adfa3b42466fd50c46 100644 (file)
@@ -213,6 +213,8 @@ public:
        ///
        bool allowParagraphCustomization() const { return custompars_; }
        ///
+       docstring escapeChars() const { return escape_chars_; }
+       ///
        bool isPassThru() const { return passthru_; }
        ///
        docstring passThruChars() const { return passthru_chars_; }
@@ -402,6 +404,8 @@ private:
        ///
        bool forceplain_ = false;
        ///
+       docstring escape_chars_;
+       ///
        bool passthru_ = false;
        ///
        docstring passthru_chars_;
index 8a3109947fb55c047256ba6988b29b10638e1687..907530b22ba307cb212a029ee90765663631097f 100644 (file)
@@ -548,6 +548,8 @@ void InsetText::latex(otexstream & os, OutputParams const & runparams) const
                rp.moving_arg = true;
        if (il.isNeedMBoxProtect())
                ++rp.inulemcmd;
+       if (!il.escapeChars().empty())
+               rp.escape_chars = il.escapeChars();
        if (!il.passThruChars().empty())
                rp.pass_thru_chars += il.passThruChars();
        if (!il.noPassThruChars().empty())