tex2lyx/text.cpp: add support for box alignment

the nasty hack with the FIXME is due to bug #9552
This commit is contained in:
Uwe Stöhr 2015-05-19 02:19:24 +02:00
parent 78aeccc19a
commit 1ace9f5ac2
3 changed files with 67 additions and 13 deletions

View File

@ -83,9 +83,6 @@ Format LaTeX feature LyX feature
\twocolumn[]{}{} Layout Twocolumn, InsetArgument \twocolumn[]{}{} Layout Twocolumn, InsetArgument
\item[]<> InsetArgument \item[]<> InsetArgument
\begin{enumerate|itemize|...}[] InsetArgument \begin{enumerate|itemize|...}[] InsetArgument
489 horizontal alignment in boxes InsetBox
\centering
\reggedleft
General General

View File

@ -179,6 +179,16 @@ $\boxed{\int A=B}$
{\fboxsep 35pt\shadowsize 15pt\shadowbox{\centering www}} {\fboxsep 35pt\shadowsize 15pt\shadowbox{\centering www}}
\parbox[t]{0.9\columnwidth}{%
\centering www%
}
{\raggedleft
\parbox[t]{0.9\columnwidth}{
\centering www%
}
}
\subsection{Color Boxes} \subsection{Color Boxes}
\colorbox{blue}{www} \colorbox{blue}{www}

View File

@ -127,6 +127,7 @@ string parse_text_snippet(Parser & p, unsigned flags, const bool outer,
string fboxrule = ""; string fboxrule = "";
string fboxsep = ""; string fboxsep = "";
string shadow_size = ""; string shadow_size = "";
bool wasBoxAlign = false;
char const * const known_ref_commands[] = { "ref", "pageref", "vref", char const * const known_ref_commands[] = { "ref", "pageref", "vref",
"vpageref", "prettyref", "nameref", "eqref", 0 }; "vpageref", "prettyref", "nameref", "eqref", 0 };
@ -1030,6 +1031,39 @@ void parse_box(Parser & p, ostream & os, unsigned outer_flags,
width_unit.clear(); width_unit.clear();
width_special = "none"; width_special = "none";
} }
// try to determine the box content alignment
// first handle the simple case of "{\centering..."
if (p.next_token().asInput() == "\\raggedright") {
wasBoxAlign = true;
hor_pos = "l";
} else if (p.next_token().asInput() == "\\centering") {
wasBoxAlign = true;
hor_pos = "c";
} else if (p.next_token().asInput() == "\\raggedleft") {
wasBoxAlign = true;
hor_pos = "r";
} else {
// now handle the cases "{%catNewline\centering..."
// and "{catNewline\centering..."
p.pushPosition();
p.get_token().asInput();
if (p.next_token().cat() == catComment || p.next_token().cat() == catNewline)
p.get_token().asInput();
if (p.next_token().asInput() == "\\raggedright") {
wasBoxAlign = true;
hor_pos = "l";
} else if (p.next_token().asInput() == "\\centering") {
wasBoxAlign = true;
os << "\n sada";
hor_pos = "c";
} else if (p.next_token().asInput() == "\\raggedleft") {
wasBoxAlign = true;
hor_pos = "r";
}
p.popPosition();
}
if (use_ert) { if (use_ert) {
ostringstream ss; ostringstream ss;
if (!outer_type.empty()) { if (!outer_type.empty()) {
@ -4257,8 +4291,13 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
} }
} }
// FIXME: due to the compiler limit of "if" nestings
// the code for the alignment was put here
// put them in their own if if this is fixed
else if (t.cs() == "fboxrule" || t.cs() == "fboxsep" else if (t.cs() == "fboxrule" || t.cs() == "fboxsep"
|| t.cs() == "shadowsize") { || t.cs() == "shadowsize"
|| t.cs() == "raggedleft" || t.cs() == "centering"
|| t.cs() == "raggedright") {
p.skip_spaces(true); p.skip_spaces(true);
if (t.cs() == "fboxrule") if (t.cs() == "fboxrule")
fboxrule = ""; fboxrule = "";
@ -4266,6 +4305,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
fboxsep = ""; fboxsep = "";
if (t.cs() == "shadowsize") if (t.cs() == "shadowsize")
shadow_size = ""; shadow_size = "";
if (t.cs() != "raggedleft" && t.cs() != "centering"
&& t.cs() != "raggedright") {
while (p.good() && p.next_token().cat() != catSpace while (p.good() && p.next_token().cat() != catSpace
&& p.next_token().cat() != catNewline && p.next_token().cat() != catNewline
&& p.next_token().cat() != catEscape) { && p.next_token().cat() != catEscape) {
@ -4276,6 +4317,12 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
if (t.cs() == "shadowsize") if (t.cs() == "shadowsize")
shadow_size = shadow_size + p.get_token().asInput(); shadow_size = shadow_size + p.get_token().asInput();
} }
} else {
// we only handle them if they are in a box
if (!wasBoxAlign)
output_ert_inset(os, '\\' + t.cs() + ' ', context);
}
wasBoxAlign = false;
} }
//\framebox() is part of the picture environment and different from \framebox{} //\framebox() is part of the picture environment and different from \framebox{}