From: Georg Baum Date: Thu, 11 Jun 2015 20:25:00 +0000 (+0200) Subject: Make tex2lyx tests green again X-Git-Tag: 2.2.0alpha1~534 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=6f84ceb821782c74281a8822f10d6e82cec07bac;p=features.git Make tex2lyx tests green again Unfortunately I overlooked in 44f73b065004 that the first three whitespace changes in box-color-size-space-align.lyx.lyx were actually correct, so they should not have been reverted. In detail: 1), 2): The space after \raggedleft must not be part of the ERT inset, but it is ouput by check_space() as part of the standard text which follows. 3): The space in front of www is caused by the fact that there is a newline between the opening brace of the parbox and the \centering command, so this space is not the one after \centering (which is correctly swallowed). This additional space is in fact not needed, and the contents would look better in LyX without it, but since it is not caused by special code I'll put it back in the refernce for now. We can still improve this in the future if anybody has a good idea. The remaining whitespace issues are all fixed by a simple change in parse_text(): Instead of always eating whitespace after detecting \centering et al, and always output a space as part of the ERT if these commands need an ERT, let the standard space handling mechanism kick in: skip whitespace if no ERT is used (in this case LyX will always output the needed space), and do not touch whitespace if an ERT is used. --- diff --git a/src/tex2lyx/test/box-color-size-space-align.lyx.lyx b/src/tex2lyx/test/box-color-size-space-align.lyx.lyx index 897859e421..70a523cffb 100644 --- a/src/tex2lyx/test/box-color-size-space-align.lyx.lyx +++ b/src/tex2lyx/test/box-color-size-space-align.lyx.lyx @@ -1350,12 +1350,12 @@ status collapsed \begin_layout Plain Layout \backslash -raggedleft +raggedleft \end_layout \end_inset - + \begin_inset Box Frameless position "t" hor_pos "c" @@ -1376,7 +1376,7 @@ status open \begin_layout Plain Layout -www + www \end_layout \end_inset diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index d510c0010e..ffeac41df3 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -4289,7 +4289,6 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, || t.cs() == "shadowsize" || t.cs() == "raggedleft" || t.cs() == "centering" || t.cs() == "raggedright") { - p.skip_spaces(true); if (t.cs() == "fboxrule") fboxrule = ""; if (t.cs() == "fboxsep") @@ -4298,6 +4297,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, shadow_size = ""; if (t.cs() != "raggedleft" && t.cs() != "centering" && t.cs() != "raggedright") { + p.skip_spaces(true); while (p.good() && p.next_token().cat() != catSpace && p.next_token().cat() != catNewline && p.next_token().cat() != catEscape) { @@ -4310,8 +4310,14 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, } } else { // we only handle them if they are in a box - if (!wasBoxAlign) - output_ert_inset(os, '\\' + t.cs() + ' ', context); + if (wasBoxAlign) { + // LyX will add a space after outputting the + // alignment command, so eat any space which + // might follow. Otherwise the paragraph + // might start with an unneeded space. + p.skip_spaces(true); + } else + output_ert_inset(os, t.asInput(), context); } wasBoxAlign = false; }