commit e837fe8a4f56d069ec755709f248af073ad043e7
Author: Juergen Spitzmueller <[email protected]>
Date:   Wed Oct 29 13:05:52 2025 +0100

    tex2lyx: support all soecial chars
---
 src/tex2lyx/tex2lyx.cpp | 12 ++++++++++++
 src/tex2lyx/tex2lyx.h   |  3 +++
 src/tex2lyx/text.cpp    | 32 ++++++--------------------------
 3 files changed, 21 insertions(+), 26 deletions(-)

diff --git a/src/tex2lyx/tex2lyx.cpp b/src/tex2lyx/tex2lyx.cpp
index ee3b853e46..a6b3cb0f07 100644
--- a/src/tex2lyx/tex2lyx.cpp
+++ b/src/tex2lyx/tex2lyx.cpp
@@ -492,6 +492,18 @@ bool isProvided(string const & name)
 }
 
 
+bool isKnownSpecialChar(string const & latex, string & lyxname, bool const 
only_protected)
+{
+       for (auto const & [name, sc] : textclass.specialChars()) {
+               if (to_ascii(ltrim(sc.latex_output, "\\")) == latex) {
+                       lyxname = name;
+                       return only_protected ? sc.need_protect : true;
+               }
+       }
+       return false;
+}
+
+
 bool noweb_mode = false;
 bool pdflatex = false;
 bool xetex = false;
diff --git a/src/tex2lyx/tex2lyx.h b/src/tex2lyx/tex2lyx.h
index b8c9dad1dd..fade5584dc 100644
--- a/src/tex2lyx/tex2lyx.h
+++ b/src/tex2lyx/tex2lyx.h
@@ -128,6 +128,9 @@ 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);
 // 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 c5cfc2a6ac..8016c3cb2e 100644
--- a/src/tex2lyx/text.cpp
+++ b/src/tex2lyx/text.cpp
@@ -320,24 +320,6 @@ char const * const known_text_font_shapes[] = { "textit", 
"textsl", "textsc",
 char const * const known_coded_font_shapes[] = { "italic", "slanted",
 "smallcaps", "up", 0};
 
-/// Known special characters which need skip_spaces_braces() afterwards
-char const * const known_special_chars[] = {"ldots",
-"lyxarrow", "textcompwordmark",
-"slash", "textasciitilde", "textasciicircum", "textbackslash",
-"LyX", "TeX", "LaTeXe",
-"LaTeX", 0};
-
-/// special characters from known_special_chars which may have a \\protect 
before
-char const * const known_special_protect_chars[] = {"LyX", "TeX",
-"LaTeXe", "LaTeX", 0};
-
-/// the same as known_special_chars with .lyx names
-char const * const known_coded_special_chars[] = {"\\SpecialChar ldots\n",
-"\\SpecialChar menuseparator\n", "\\SpecialChar ligaturebreak\n",
-"\\SpecialChar breakableslash\n", "~", "^", "\n\\backslash\n",
-"\\SpecialChar LyX\n", "\\SpecialChar TeX\n", "\\SpecialChar LaTeX2e\n",
-"\\SpecialChar LaTeX\n", 0};
-
 /*!
  * Graphics file extensions known by the dvips driver of the graphics package.
  * These extensions are used to complete the filename of an included
@@ -5492,16 +5474,14 @@ void parse_text(Parser & p, ostream & os, unsigned 
flags, bool outer,
                        continue;
                }
 
-               if (is_known(t.cs(), known_special_chars) ||
-                   (t.cs() == "protect" &&
-                    p.next_token().cat() == catEscape &&
-                    is_known(p.next_token().cs(), 
known_special_protect_chars))) {
+               string lyxname;
+               if (isKnownSpecialChar(t.cs(), lyxname)
+                   || (t.cs() == "protect"
+                       && p.next_token().cat() == catEscape
+                       && isKnownSpecialChar(t.cs(), lyxname, true))) {
                        // LyX sometimes puts a \protect in front, so we have 
to ignore it
-                       where = is_known(
-                               t.cs() == "protect" ? p.get_token().cs() : 
t.cs(),
-                               known_special_chars);
                        context.check_layout(os);
-                       os << known_coded_special_chars[where - 
known_special_chars];
+                       os << "\\SpecialChar " << lyxname << '\n';
                        skip_spaces_braces(p);
                        continue;
                }
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to