From 0cd0f955fb4da8dd1210b78ce1a3877c8c7daa6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uwe=20St=C3=B6hr?= Date: Wed, 26 Oct 2011 01:18:27 +0000 Subject: [PATCH] tex2lyx: addendum to r39989; support for basic (predefined) colors; useful for things like \color{green} git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@39991 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/tex2lyx/preamble.cpp | 38 ++++++++++++++++++++++++++++++++++---- src/tex2lyx/tex2lyx.h | 2 ++ 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/tex2lyx/preamble.cpp b/src/tex2lyx/preamble.cpp index dafceb42e0..e988f1af52 100644 --- a/src/tex2lyx/preamble.cpp +++ b/src/tex2lyx/preamble.cpp @@ -169,6 +169,12 @@ const char * const known_if_commands[] = {"if", "ifarydshln", "ifbraket", "ifcancel", "ifcolortbl", "ifeurosym", "ifmarginnote", "ifmmode", "ifpdf", "ifsidecap", "ifupgreek", 0}; +const char * const known_basic_colors[] = {"blue", "black", "cyan", "green", +"magenta", "red", "white", "yellow", 0}; + +const char * const known_basic_color_codes[] = {"#0000ff", "#000000", "#00ffff", "#00ff00", +"#ff00ff", "#ff0000", "#ffffff", "#ffff00", 0}; + /// conditional commands with three arguments like \@ifundefined{}{}{} const char * const known_if_3arg_commands[] = {"@ifundefined", "IfFileExists", 0}; @@ -917,18 +923,32 @@ void parse_preamble(Parser & p, ostream & os, else if (t.cs() == "color") { string argument = p.getArg('{', '}'); - // check the case that not a color defined by LyX is used - if (argument != "document_fontcolor") { + // check the case that a standard color is used + if (is_known(argument, known_basic_colors)) + h_fontcolor = color2code(argument); + // check the case that LyX's document_fontcolor is defined + // but not used for \color + if (argument != "document_fontcolor" + && !is_known(argument, known_basic_colors)) { h_preamble << t.asInput() << '{' << argument << '}'; + // the color might already be set because \definecolor + // is parsed before this h_fontcolor = ""; } } else if (t.cs() == "pagecolor") { string argument = p.getArg('{', '}'); - // check the case that not a color defined by LyX is used - if (argument != "page_backgroundcolor") { + // check the case that a standard color is used + if (is_known(argument, known_basic_colors)) + h_backgroundcolor = color2code(argument); + // check the case that LyX's page_backgroundcolor is defined + // but not used for \pagecolor + if (argument != "page_backgroundcolor" + && !is_known(argument, known_basic_colors)) { h_preamble << t.asInput() << '{' << argument << '}'; + // the color might already be set because \definecolor + // is parsed before this h_backgroundcolor = ""; } } @@ -1300,6 +1320,16 @@ string babel2lyx(string const & language) return language; } + +/// translates a color name to a LyX color code +string color2code(string const & name) +{ + char const * const * where = is_known(name, known_basic_colors); + if (where) + return known_basic_color_codes[where - known_basic_colors]; + return name; +} + // }]) diff --git a/src/tex2lyx/tex2lyx.h b/src/tex2lyx/tex2lyx.h index 83f75df07e..7ccc303a01 100644 --- a/src/tex2lyx/tex2lyx.h +++ b/src/tex2lyx/tex2lyx.h @@ -48,6 +48,8 @@ void parse_preamble(Parser & p, std::ostream & os, std::string const & forceclass, TeX2LyXDocClass & tc); /// Translate babel language name to LyX language name extern std::string babel2lyx(std::string const & language); +/// translate color name to LyX color code +extern std::string color2code(std::string const & name); /// used packages with options extern std::map > used_packages;