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
This commit is contained in:
Uwe Stöhr 2011-10-26 01:18:27 +00:00
parent 7be5a98e1d
commit 0cd0f955fb
2 changed files with 36 additions and 4 deletions

View File

@ -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;
}
// }])

View File

@ -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<std::string, std::vector<std::string> > used_packages;