From: Uwe Stöhr Date: Tue, 19 May 2015 00:19:24 +0000 (+0200) Subject: tex2lyx/text.cpp: add support for box alignment X-Git-Tag: 2.2.0alpha1~758 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=1ace9f5ac267e77c7c7fe4bf9b659b6fe7e297fb;p=features.git tex2lyx/text.cpp: add support for box alignment the nasty hack with the FIXME is due to bug #9552 --- diff --git a/src/tex2lyx/TODO.txt b/src/tex2lyx/TODO.txt index 61f4e25474..5305fea871 100644 --- a/src/tex2lyx/TODO.txt +++ b/src/tex2lyx/TODO.txt @@ -83,9 +83,6 @@ Format LaTeX feature LyX feature \twocolumn[]{}{} Layout Twocolumn, InsetArgument \item[]<> InsetArgument \begin{enumerate|itemize|...}[] InsetArgument -489 horizontal alignment in boxes InsetBox - \centering - \reggedleft General diff --git a/src/tex2lyx/test/box-color-size-space-align.tex b/src/tex2lyx/test/box-color-size-space-align.tex index cc982ba58e..3ced26fec0 100644 --- a/src/tex2lyx/test/box-color-size-space-align.tex +++ b/src/tex2lyx/test/box-color-size-space-align.tex @@ -179,6 +179,16 @@ $\boxed{\int A=B}$ {\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} \colorbox{blue}{www} diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index 60fa6257d9..b3ad38c182 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -127,6 +127,7 @@ string parse_text_snippet(Parser & p, unsigned flags, const bool outer, string fboxrule = ""; string fboxsep = ""; string shadow_size = ""; +bool wasBoxAlign = false; char const * const known_ref_commands[] = { "ref", "pageref", "vref", "vpageref", "prettyref", "nameref", "eqref", 0 }; @@ -1030,6 +1031,39 @@ void parse_box(Parser & p, ostream & os, unsigned outer_flags, width_unit.clear(); 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) { ostringstream ss; 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" - || t.cs() == "shadowsize") { + || t.cs() == "shadowsize" + || t.cs() == "raggedleft" || t.cs() == "centering" + || t.cs() == "raggedright") { p.skip_spaces(true); if (t.cs() == "fboxrule") fboxrule = ""; @@ -4266,16 +4305,24 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, fboxsep = ""; if (t.cs() == "shadowsize") shadow_size = ""; - while (p.good() && p.next_token().cat() != catSpace - && p.next_token().cat() != catNewline - && p.next_token().cat() != catEscape) { - if (t.cs() == "fboxrule") - fboxrule = fboxrule + p.get_token().asInput(); - if (t.cs() == "fboxsep") - fboxsep = fboxsep + p.get_token().asInput(); - if (t.cs() == "shadowsize") - shadow_size = shadow_size + p.get_token().asInput(); + if (t.cs() != "raggedleft" && t.cs() != "centering" + && t.cs() != "raggedright") { + while (p.good() && p.next_token().cat() != catSpace + && p.next_token().cat() != catNewline + && p.next_token().cat() != catEscape) { + if (t.cs() == "fboxrule") + fboxrule = fboxrule + p.get_token().asInput(); + if (t.cs() == "fboxsep") + fboxsep = fboxsep + p.get_token().asInput(); + if (t.cs() == "shadowsize") + 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{}