mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-10 18:58:10 +00:00
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:
parent
7be5a98e1d
commit
0cd0f955fb
@ -169,6 +169,12 @@ const char * const known_if_commands[] = {"if", "ifarydshln", "ifbraket",
|
|||||||
"ifcancel", "ifcolortbl", "ifeurosym", "ifmarginnote", "ifmmode", "ifpdf",
|
"ifcancel", "ifcolortbl", "ifeurosym", "ifmarginnote", "ifmmode", "ifpdf",
|
||||||
"ifsidecap", "ifupgreek", 0};
|
"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{}{}{}
|
/// conditional commands with three arguments like \@ifundefined{}{}{}
|
||||||
const char * const known_if_3arg_commands[] = {"@ifundefined", "IfFileExists",
|
const char * const known_if_3arg_commands[] = {"@ifundefined", "IfFileExists",
|
||||||
0};
|
0};
|
||||||
@ -917,18 +923,32 @@ void parse_preamble(Parser & p, ostream & os,
|
|||||||
|
|
||||||
else if (t.cs() == "color") {
|
else if (t.cs() == "color") {
|
||||||
string argument = p.getArg('{', '}');
|
string argument = p.getArg('{', '}');
|
||||||
// check the case that not a color defined by LyX is used
|
// check the case that a standard color is used
|
||||||
if (argument != "document_fontcolor") {
|
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 << '}';
|
h_preamble << t.asInput() << '{' << argument << '}';
|
||||||
|
// the color might already be set because \definecolor
|
||||||
|
// is parsed before this
|
||||||
h_fontcolor = "";
|
h_fontcolor = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (t.cs() == "pagecolor") {
|
else if (t.cs() == "pagecolor") {
|
||||||
string argument = p.getArg('{', '}');
|
string argument = p.getArg('{', '}');
|
||||||
// check the case that not a color defined by LyX is used
|
// check the case that a standard color is used
|
||||||
if (argument != "page_backgroundcolor") {
|
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 << '}';
|
h_preamble << t.asInput() << '{' << argument << '}';
|
||||||
|
// the color might already be set because \definecolor
|
||||||
|
// is parsed before this
|
||||||
h_backgroundcolor = "";
|
h_backgroundcolor = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1300,6 +1320,16 @@ string babel2lyx(string const & language)
|
|||||||
return 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;
|
||||||
|
}
|
||||||
|
|
||||||
// }])
|
// }])
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,6 +48,8 @@ void parse_preamble(Parser & p, std::ostream & os,
|
|||||||
std::string const & forceclass, TeX2LyXDocClass & tc);
|
std::string const & forceclass, TeX2LyXDocClass & tc);
|
||||||
/// Translate babel language name to LyX language name
|
/// Translate babel language name to LyX language name
|
||||||
extern std::string babel2lyx(std::string const & language);
|
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
|
/// used packages with options
|
||||||
extern std::map<std::string, std::vector<std::string> > used_packages;
|
extern std::map<std::string, std::vector<std::string> > used_packages;
|
||||||
|
Loading…
Reference in New Issue
Block a user