]> git.lyx.org Git - features.git/commitdiff
Make tex2lyx tests green again
authorGeorg Baum <baum@lyx.org>
Thu, 11 Jun 2015 20:25:00 +0000 (22:25 +0200)
committerGeorg Baum <baum@lyx.org>
Thu, 11 Jun 2015 20:25:00 +0000 (22:25 +0200)
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.

src/tex2lyx/test/box-color-size-space-align.lyx.lyx
src/tex2lyx/text.cpp

index 897859e4212c4559e4cc59322d34da8d279f9c29..70a523cffbd459d74220a5c8e329959826093e02 100644 (file)
@@ -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
index d510c0010ec45b0e24c40026c9933c686b7fdc9c..ffeac41df38aa090b987458f3036a3d1285f5fc7 100644 (file)
@@ -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;
                }