Add EscapeChars layout tag

This allows to define chars to be escape and an escape character

Needed in index and nomenclature
This commit is contained in:
Juergen Spitzmueller 2024-08-12 12:25:31 +02:00
parent 603e9a8164
commit 8847651623
13 changed files with 572 additions and 5 deletions

View 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

View 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

View 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

View 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';

View 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

View 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;

View 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))

View 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

View 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())

View 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_;

View 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();

View 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_;

View 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())