commit a465e23bdd2df6a2c31e71b77ba2d99a93d65ddd
Author: Juergen Spitzmueller <[email protected]>
Date: Mon Nov 10 08:26:32 2025 +0100
Properly support multi-token special chars handled by InsetSpecialChar
---
src/tex2lyx/tex2lyx.cpp | 7 ++++++-
src/tex2lyx/tex2lyx.h | 7 ++++---
src/tex2lyx/text.cpp | 56 +++++++++++++++++++++++++++++++------------------
3 files changed, 46 insertions(+), 24 deletions(-)
diff --git a/src/tex2lyx/tex2lyx.cpp b/src/tex2lyx/tex2lyx.cpp
index a6b3cb0f07..0787c2bdec 100644
--- a/src/tex2lyx/tex2lyx.cpp
+++ b/src/tex2lyx/tex2lyx.cpp
@@ -492,9 +492,14 @@ bool isProvided(string const & name)
}
-bool isKnownSpecialChar(string const & latex, string & lyxname, bool const
only_protected)
+bool isKnownInsetSpecialChar(string const & latex, string & lyxname, bool
const only_protected,
+ bool const partof)
{
for (auto const & [name, sc] : textclass.specialChars()) {
+ if (partof && prefixIs(to_ascii(ltrim(sc.latex_output, "\\")),
latex)) {
+ lyxname = name;
+ return only_protected ? sc.need_protect : true;
+ }
if (to_ascii(ltrim(sc.latex_output, "\\")) == latex) {
lyxname = name;
return only_protected ? sc.need_protect : true;
diff --git a/src/tex2lyx/tex2lyx.h b/src/tex2lyx/tex2lyx.h
index fade5584dc..598923e4c3 100644
--- a/src/tex2lyx/tex2lyx.h
+++ b/src/tex2lyx/tex2lyx.h
@@ -128,9 +128,10 @@ extern InsetLayout const *
findInsetLayoutWithoutModule(TextClass const & tc, st
extern bool checkModule(std::string const & name, bool command);
/// Is this feature already provided e.g. by the document class?
extern bool isProvided(std::string const & name);
-/// Is this a known special character?
-extern bool isKnownSpecialChar(std::string const & latex, std::string &
lyxname,
- bool const only_protected = false);
+/// Is this a special character supported by InsetSpecialChar?
+extern bool isKnownInsetSpecialChar(std::string const & latex, std::string &
lyxname,
+ bool const only_protected = false,
+ bool const partof = false);
// Access to environment stack
extern std::vector<std::string> active_environments;
std::string active_environment();
diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp
index e7e35d0309..f8e19205d3 100644
--- a/src/tex2lyx/text.cpp
+++ b/src/tex2lyx/text.cpp
@@ -5483,7 +5483,9 @@ void parse_text(Parser & p, ostream & os, unsigned flags,
bool outer,
}
if (is_known(t.cs(), known_special_chars)) {
- // LyX sometimes puts a \protect in front, so we have
to ignore it
+ // These are special chars which are coded in LyX
+ // in a specific way. Note: InsetSpecialChar is handled
+ // separately (below)
where = is_known(t.cs(), known_special_chars);
context.check_layout(os);
os << known_coded_special_chars[where -
known_special_chars];
@@ -5491,22 +5493,6 @@ void parse_text(Parser & p, ostream & os, unsigned
flags, bool outer,
continue;
}
- if ((t.cs() == "nobreakdash" && p.next_token().asInput() ==
"-") ||
- (t.cs() == "protect" && p.next_token().asInput() ==
"\\nobreakdash" &&
- p.next_next_token().asInput() == "-") ||
- (t.cs() == "@" && p.next_token().asInput() == ".")) {
- // LyX sometimes puts a \protect in front, so we have
to ignore it
- if (t.cs() == "protect")
- p.get_token();
- context.check_layout(os);
- if (t.cs() == "nobreakdash")
- os << "\\SpecialChar nobreakdash\n";
- else
- os << "\\SpecialChar endofsentence\n";
- p.get_token();
- continue;
- }
-
if (t.cs() == "_" || t.cs() == "&" || t.cs() == "#"
|| t.cs() == "$" || t.cs() == "{" || t.cs() == "}"
|| t.cs() == "%" || t.cs() == "-") {
@@ -6702,12 +6688,12 @@ void parse_text(Parser & p, ostream & os, unsigned
flags, bool outer,
name += '{' + p.verbatim_item() + '}';
}
- // special chars
+ // (Single) special chars supported via InsetSpecialChar
string lyxname;
- if (isKnownSpecialChar(t.cs(), lyxname)
+ if (isKnownInsetSpecialChar(t.cs(), lyxname)
|| (t.cs() == "protect"
&& p.next_token().cat() == catEscape
- && isKnownSpecialChar(p.next_token().cs(), lyxname,
true))) {
+ && isKnownInsetSpecialChar(p.next_token().cs(),
lyxname, true))) {
// LyX sometimes puts a \protect in front, so we have
to ignore it
if (t.cs() == "protect")
p.get_token();
@@ -6716,6 +6702,36 @@ void parse_text(Parser & p, ostream & os, unsigned
flags, bool outer,
skip_spaces_braces(p);
continue;
}
+ // And multi-token special chars
+ if (isKnownInsetSpecialChar(t.cs(), lyxname, false, true)
+ || (t.cs() == "protect"
+ && p.next_token().cat() == catEscape
+ && isKnownInsetSpecialChar(p.next_token().cs(),
lyxname, true, true))) {
+ p.pushPosition();
+ string latex;
+ if (t.cs() == "protect") {
+ // ignore \protect
+ latex = p.next_token().cs();
+ p.get_token();
+ } else
+ latex = t.cs();
+ // Try to the complete token sequence as long as it is
known
+ // as part of a known special char sequence
+ while (isKnownInsetSpecialChar(latex +
p.next_token().cs(), lyxname, false, true)) {
+ latex += p.next_token().cs();
+ p.get_token();
+ }
+ // It this a known complete sequence?
+ if (isKnownInsetSpecialChar(latex, lyxname)) {
+ context.check_layout(os);
+ os << "\\SpecialChar " << lyxname << '\n';
+ skip_braces(p);
+ p.dropPosition();
+ continue;
+ }
+ // If not, go back and fall through
+ p.popPosition();
+ }
// now get the character from unicodesymbols
bool termination;
--
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs