Jean-Marc Lasgouttes wrote:

>>>>>> "Georg" == Georg Baum
>>>>>> <[EMAIL PROTECTED]>
>>>>>> writes:
> 
> Georg> This patch fixes bug 2786: tex2lyx does not know any of the
> Georg> spaces supported by InsetSpace except ~. The attached LyX file
> Georg> shows that the roundtrip LyX-> LaTeX->LyX->LaTeX is perfect.
> 
> I do not think we should skip braces and spaces depending on what LyX
> outputs.

Why not? My goal was to translate all spaces in such a way that the
resulting DVI of the original .tex file and that of the generated .lyx file
look identical. If we want that then we have to take into account whether
LyX outputs {} or not. The second goal is to remove {} if it is not needed.

> +                     // LyX adds {} after the space, so we have to eat
> +                     // spaces here if there are any before a possible
> +                     // {} pair, but not after \\, (whitespace after \\,
> +                     // is not swallowed by LaTeX).
> +                     if (t.cs() !=  ",")
> +                             eat_whitespace(p, os, context, false);
> 
> This should be generic and depend only on the name of the macro, right?

I do not understand. LaTeX eats whitespace after all these spaces macros
except after "\,", so we have to do the same.

> +                     // LyX does not add {} after "\\ " and "\\,"
> +                     if (t.cs() != " " && t.cs() != ",")
> +                             skip_braces(p);
> +             }
> 
> Would it hurt to skip braces after \, and "\ "?

Not if they directly follow, like this: \,{}
Yes if there is some whitespace before: \, {}

> In general, should we use what we know about macros (in
> syntax.defaults) to eat all the {} that are after \foo macros? Shall
> this code be for space insets only, or more general?

syntax.default does not give this information, and it is only used for
macros that have no LyX inset. I don't think that we should mix that.

> Georg> This goes in tonight unless somebody objects. Jean-Marc, also
> Georg> for 1.4.3?
> 
> This would be OK in 1.4.3 in any case (my objections above are for
> code cleanup, so presumably 1.5).

I do not want two different solutions, so I propose this patch instead. It
does swallow one more {}, and I changed the comments to be less confusing.
Is that now OK with you?


Georg
Index: src/tex2lyx/text.C
===================================================================
--- src/tex2lyx/text.C	(Revision 14830)
+++ src/tex2lyx/text.C	(Arbeitskopie)
@@ -198,6 +198,15 @@ char const * const known_pdftex_graphics
  */
 char const * const known_tex_extensions[] = {"tex", 0};
 
+/// spaces known by InsetSpace
+char const * const known_spaces[] = { " ", "space", ",", "thinspace", "quad",
+"qquad", "enspace", "enskip", "negthinspace", 0};
+
+/// the same as known_spaces with .lyx names
+char const * const known_coded_spaces[] = { "space{}", "space{}",
+"thinspace{}", "thinspace{}", "quad{}", "qquad{}", "enspace{}", "enskip{}",
+"negthinspace{}", 0};
+
 
 /// splits "x=z, y=b" into a map
 map<string, string> split_map(string const & s)
@@ -2184,6 +2193,25 @@ void parse_text(Parser & p, ostream & os
 			skip_braces(p);
 		}
 
+		else if (is_known(t.cs(), known_spaces)) {
+			char const * const * where = is_known(t.cs(), known_spaces);
+			context.check_layout(os);
+			begin_inset(os, "InsetSpace ");
+			os << '\\' << known_coded_spaces[where - known_spaces]
+			   << '\n';
+			// LaTeX swallows whitespace after all spaces except
+			// "\\,". We have to do that here, too, because LyX
+			// adds "{}" which would make the spaces significant.
+			if (t.cs() !=  ",")
+				eat_whitespace(p, os, context, false);
+			// LyX adds "{}" after all spaces except "\\ " and
+			// "\\,", so we have to remove "{}".
+			// "\\,{}" is equivalent to "\\," in LaTeX, so we
+			// remove the braces after "\\,", too.
+			if (t.cs() != " ")
+				skip_braces(p);
+		}
+
 		else if (t.cs() == "newpage") {
 			context.check_layout(os);
 			// FIXME: what about \\clearpage and \\pagebreak?

Reply via email to