[LyX/master] Add EscapeChars layout tag
Juergen Spitzmueller
spitz at lyx.org
Mon Aug 12 10:35:45 UTC 2024
commit 8847651623ba4536428551423c5ed02ee6357790
Author: Juergen Spitzmueller <spitz at lyx.org>
Date: Mon Aug 12 12:25:31 2024 +0200
Add EscapeChars layout tag
This allows to define chars to be escape and an escape character
Needed in index and nomenclature
---
lib/doc/Customization.lyx | 218 +++++++++++++++++++++++++++++++
lib/doc/de/Customization.lyx | 297 +++++++++++++++++++++++++++++++++++++++++++
lib/scripts/layout2layout.py | 7 +-
src/Layout.cpp | 13 ++
src/Layout.h | 3 +
src/OutputParams.h | 3 +
src/Paragraph.cpp | 11 ++
src/TextClass.cpp | 2 +-
src/insets/InsetArgument.cpp | 7 +-
src/insets/InsetArgument.h | 2 +
src/insets/InsetLayout.cpp | 8 ++
src/insets/InsetLayout.h | 4 +
src/insets/InsetText.cpp | 2 +
13 files changed, 572 insertions(+), 5 deletions(-)
diff --git a/lib/doc/Customization.lyx b/lib/doc/Customization.lyx
index 5c1dbafc5e..cef51f803b 100644
--- a/lib/doc/Customization.lyx
+++ b/lib/doc/Customization.lyx
@@ -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
diff --git a/lib/doc/de/Customization.lyx b/lib/doc/de/Customization.lyx
index 18e3a342bd..7932ef56bf 100644
--- a/lib/doc/de/Customization.lyx
+++ b/lib/doc/de/Customization.lyx
@@ -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
diff --git a/lib/scripts/layout2layout.py b/lib/scripts/layout2layout.py
index 428cf709a4..b90350e109 100644
--- a/lib/scripts/layout2layout.py
+++ b/lib/scripts/layout2layout.py
@@ -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
diff --git a/src/Layout.cpp b/src/Layout.cpp
index e531fab362..fa5ab4b7ae 100644
--- a/src/Layout.cpp
+++ b/src/Layout.cpp
@@ -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';
diff --git a/src/Layout.h b/src/Layout.h
index eef0bee290..c8f08439f5 100644
--- a/src/Layout.h
+++ b/src/Layout.h
@@ -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
diff --git a/src/OutputParams.h b/src/OutputParams.h
index 306087dfdf..b063653b8a 100644
--- a/src/OutputParams.h
+++ b/src/OutputParams.h
@@ -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;
diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index 9d8acf84e0..e485c1a852 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -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))
diff --git a/src/TextClass.cpp b/src/TextClass.cpp
index 933489743d..8600b64d66 100644
--- a/src/TextClass.cpp
+++ b/src/TextClass.cpp
@@ -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
diff --git a/src/insets/InsetArgument.cpp b/src/insets/InsetArgument.cpp
index c4708c8d42..90886e43d3 100644
--- a/src/insets/InsetArgument.cpp
+++ b/src/insets/InsetArgument.cpp
@@ -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())
diff --git a/src/insets/InsetArgument.h b/src/insets/InsetArgument.h
index a3dd7d05bf..0bf1887662 100644
--- a/src/insets/InsetArgument.h
+++ b/src/insets/InsetArgument.h
@@ -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_;
diff --git a/src/insets/InsetLayout.cpp b/src/insets/InsetLayout.cpp
index 024c81e40b..61e574a9ac 100644
--- a/src/insets/InsetLayout.cpp
+++ b/src/insets/InsetLayout.cpp
@@ -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();
diff --git a/src/insets/InsetLayout.h b/src/insets/InsetLayout.h
index a426a4ca86..be9aabfafe 100644
--- a/src/insets/InsetLayout.h
+++ b/src/insets/InsetLayout.h
@@ -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_;
diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp
index 8a3109947f..907530b22b 100644
--- a/src/insets/InsetText.cpp
+++ b/src/insets/InsetText.cpp
@@ -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())
More information about the lyx-cvs
mailing list