backporting tex2lyx: the color support

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_2_0_X@39992 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Uwe Stöhr 2011-10-26 01:22:31 +00:00
parent 1122af1e84
commit b4e2effa3d
5 changed files with 86 additions and 58 deletions

View File

@ -52,7 +52,6 @@ Format LaTeX feature LyX feature
347 tabular valign InsetTabular
348 \phantom, \hphantom, \vphantom InsetPhantom
350 ? \default_output_format
351 ? \backgroundcolor
353 \printsubindex InsetIndex
354 \printindex*, \printsubindex* InsetIndex
355 \sout fonts
@ -76,9 +75,6 @@ Format LaTeX feature LyX feature
378 revision info InsetInfo
380 ? InsetPreview
381 \xymatrix@!{0,R,C} InsetMathXYMatrix
382 note_fontcolor InsetNote
384 document font color \fontcolor
385 shaded box background color \boxbgcolor
386 LyX version InsetInfo
390 forward/reverse search \forward_search, \forward_macro
391 decimal alignment in tables InsetTabular

View File

@ -165,6 +165,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};
@ -216,6 +222,9 @@ string h_use_bibtopic = "false";
string h_paperorientation = "portrait";
string h_suppress_date = "false";
string h_use_refstyle = "0";
string h_backgroundcolor;
string h_boxbgcolor;
string h_fontcolor;
string h_notefontcolor;
string h_secnumdepth = "3";
string h_tocdepth = "3";
@ -774,8 +783,14 @@ void end_preamble(ostream & os, TextClass const & /*textclass*/)
<< "\\paperorientation " << h_paperorientation << '\n'
<< "\\suppress_date " << h_suppress_date << '\n'
<< "\\use_refstyle " << h_use_refstyle << '\n';
if (!h_fontcolor.empty())
os << "\\fontcolor " << h_fontcolor << '\n';
if (!h_notefontcolor.empty())
os << "\\notefontcolor " << h_notefontcolor << '\n';
if (!h_backgroundcolor.empty())
os << "\\backgroundcolor " << h_backgroundcolor << '\n';
if (!h_boxbgcolor.empty())
os << "\\boxbgcolor " << h_boxbgcolor << '\n';
os << h_margins
<< "\\secnumdepth " << h_secnumdepth << "\n"
<< "\\tocdepth " << h_tocdepth << "\n"
@ -880,6 +895,38 @@ void parse_preamble(Parser & p, ostream & os,
else if (t.cs() == "pagestyle")
h_paperpagestyle = p.verbatim_item();
else if (t.cs() == "color") {
string argument = p.getArg('{', '}');
// 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 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 = "";
}
}
else if (t.cs() == "makeatletter") {
// LyX takes care of this
p.setCatCode('@', catLetter);
@ -1137,9 +1184,18 @@ void parse_preamble(Parser & p, ostream & os,
string const color = p.getArg('{', '}');
string const space = p.getArg('{', '}');
string const value = p.getArg('{', '}');
if (color == "note_fontcolor" && space == "rgb") {
if (color == "document_fontcolor" && space == "rgb") {
RGBColor c(RGBColorFromLaTeX(value));
h_fontcolor = X11hexname(c);
} else if (color == "note_fontcolor" && space == "rgb") {
RGBColor c(RGBColorFromLaTeX(value));
h_notefontcolor = X11hexname(c);
} else if (color == "page_backgroundcolor" && space == "rgb") {
RGBColor c(RGBColorFromLaTeX(value));
h_backgroundcolor = X11hexname(c);
} else if (color == "shadecolor" && space == "rgb") {
RGBColor c(RGBColorFromLaTeX(value));
h_boxbgcolor = X11hexname(c);
} else {
h_preamble << "\\definecolor{" << color
<< "}{" << space << "}{" << value
@ -1230,6 +1286,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

@ -15,7 +15,7 @@
\definecolor{document_fontcolor}{rgb}{0.66796875, 1, 0}
\color{document_fontcolor}
\definecolor{note_fontcolor}{rgb}{0, 0, 1}
\definecolor{shadecolor}{rgb}{1, 0, 0}
\definecolor{shadecolor}{rgb}{1, 1, 0}
\usepackage{framed}
\usepackage{calc}
\usepackage{fancybox}
@ -304,6 +304,7 @@ raggedleft 2 raggedleft 2 raggedleft 2 raggedleft 2 raggedleft 2
%set back to justified
\raggedright{}
\subsection{Horizontal spaces}
Lines can have an hfill \hfill in the middle.
@ -344,6 +345,21 @@ quad\quad{}a
qquad\qquad{}a
\subsubsection*{now some math examples:}
$a\hfill b$
$a\hspace*{2cm}b$
$a\hspace{1cm}b$
$a\hspace*{\fill} b$
$a\enskip b$
$a\enspace b$
\subsection{Vertical spaces}
Lines can have a vfill \vfill in the middle.

View File

@ -308,58 +308,6 @@ test
\textcolor{red}{\rule[-4ex]{5in}{1cm}}
\subsection{Spaces}
simple: a\ b
simple, protected: a~b
thin: a\,b
medium: a\negthinspace{}b
thick: a\negmedspace{}b
negative thin: a\negthinspace{}b
negative meduim: a\negmedspace{}b
negative thick: a\negthickspace{}b
half quad: a\enskip{}b
half quad, protected: a\enspace{}b
a\quad{}b
a\qquad{}b
hfill: a\hfill{}b
hfill, protected: a\hspace*{\fill}b
custom,: a\hspace{1cm}b
custom, protected: a\hspace*{1cm}b
visible: a\textvisiblespace{}b
\subsubsection*{now some math examples:}
$a\hfill b$
$a\hspace*{2cm}b$
$a\hspace{1cm}b$
$a\hspace*{\fill} b$
$a\enskip b$
$a\enspace b$
\subsection{Phantoms}
test\phantom{Wow}test

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;