commit 32d653432ceb2d68c080838b9157d28e9dfffab9 Author: Juergen Spitzmueller <sp...@lyx.org> Date: Sun Feb 23 09:39:53 2025 +0100
Fix tex2lyx glitch (and test document that revealed it) --- src/tex2lyx/Preamble.cpp | 16 ++++++++--- src/tex2lyx/Preamble.h | 2 +- .../test/box-color-size-space-align.lyx.lyx | 32 ++++++++++++++++++++-- src/tex2lyx/text.cpp | 2 +- 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp index fd90f50644..3267a96a89 100644 --- a/src/tex2lyx/Preamble.cpp +++ b/src/tex2lyx/Preamble.cpp @@ -624,6 +624,14 @@ void Preamble::setTextClass(string const & tclass, TeX2LyXDocClass & tc) } +bool Preamble::isCustomColor(string const & col) const +{ + if (h_custom_colors.find(col) != h_custom_colors.end()) + return true; + return false; +} + + namespace { // Given is a string like "scaled=0.9" or "scale=0.9", return 0.9 * 100 @@ -3232,7 +3240,7 @@ void Preamble::parse(Parser & p, string const & forceclass, } else if ((where = is_known(color2, known_textcolors))) { h_fontcolor = known_coded_textcolors[where - known_textcolors]; registerAutomaticallyLoadedPackage("xcolor"); - } else if (h_custom_colors.find(color2) != h_custom_colors.end()) + } else if (isCustomColor(color2)) h_fontcolor = color2; } else if (color1 == "note_fontcolor") { // check the case that a standard color is used @@ -3245,7 +3253,7 @@ void Preamble::parse(Parser & p, string const & forceclass, } else if ((where = is_known(color2, known_textcolors))) { h_notefontcolor = known_coded_textcolors[where - known_textcolors]; registerAutomaticallyLoadedPackage("xcolor"); - } else if (h_custom_colors.find(color2) != h_custom_colors.end()) + } else if (isCustomColor(color2)) h_notefontcolor = color2; } else if (color1 == "page_backgroundcolor") { // check the case that a standard color is used @@ -3258,7 +3266,7 @@ void Preamble::parse(Parser & p, string const & forceclass, } else if ((where = is_known(color2, known_textcolors))) { h_backgroundcolor = known_coded_textcolors[where - known_textcolors]; registerAutomaticallyLoadedPackage("xcolor"); - } else if (h_custom_colors.find(color2) != h_custom_colors.end()) + } else if (isCustomColor(color2)) h_backgroundcolor = color2; } else if (color1 == "shadecolor") { // check the case that a standard color is used @@ -3271,7 +3279,7 @@ void Preamble::parse(Parser & p, string const & forceclass, } else if ((where = is_known(color2, known_textcolors))) { h_boxbgcolor = known_coded_textcolors[where - known_textcolors]; registerAutomaticallyLoadedPackage("xcolor"); - } else if (h_custom_colors.find(color2) != h_custom_colors.end()) + } else if (isCustomColor(color2)) h_boxbgcolor = color2; } else { h_preamble << "\\colorlet{" << color1 diff --git a/src/tex2lyx/Preamble.h b/src/tex2lyx/Preamble.h index d230e0e5c5..e31111b030 100644 --- a/src/tex2lyx/Preamble.h +++ b/src/tex2lyx/Preamble.h @@ -53,7 +53,7 @@ public: /// bool svgnames() const { return h_use_xcolor_svgnames; } /// - std::map<std::string, std::string> customColors() { return h_custom_colors; } + bool isCustomColor(std::string const & col) const; /// std::string nomenclOpts() const { return h_nomencl_options; } /// The document language diff --git a/src/tex2lyx/test/box-color-size-space-align.lyx.lyx b/src/tex2lyx/test/box-color-size-space-align.lyx.lyx index 23abd51e82..748d1ae0c1 100644 --- a/src/tex2lyx/test/box-color-size-space-align.lyx.lyx +++ b/src/tex2lyx/test/box-color-size-space-align.lyx.lyx @@ -1872,9 +1872,37 @@ Custom Colors \begin_layout Standard test -\color darkgreen +\begin_inset ERT +status collapsed + +\begin_layout Plain Layout + +\backslash +textcolor{darkgreen} +\end_layout + +\end_inset + + +\begin_inset ERT +status collapsed + +\begin_layout Plain Layout +{ +\end_layout + +\end_inset + dark green -\color inherit +\begin_inset ERT +status collapsed + +\begin_layout Plain Layout +} +\end_layout + +\end_inset + test \end_layout diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index 1526b32aa3..fd7aa4e1e4 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -4473,7 +4473,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, os << "\n\\color inherit\n"; preamble.registerAutomaticallyLoadedPackage("xcolor"); // custom colors - } else if (preamble.customColors().find(color) != preamble.customColors().end()) { + } else if (preamble.isCustomColor(color)) { context.check_layout(os); os << "\n\\color " << color << "\n"; parse_text_snippet(p, os, FLAG_ITEM, outer, context); -- lyx-cvs mailing list lyx-cvs@lists.lyx.org https://lists.lyx.org/mailman/listinfo/lyx-cvs