Jürgen Spitzmüller wrote: > > * In a new document write: a word > > Then change the size of the two words to small; then change the color > > of "a" (to red for example). > > Then lyx traduce it as : \textcolor{red}{\small a}{\small word} and > > the space between "a" and > > "word" disappear. > > this is > http://bugzilla.lyx.org/show_bug.cgi?id=3382
Here's an alternative patch for this issue. The problem is that blanks are swallowed if they follow another blank that is ending a command, such as in \small word We need to care about that, notwithstanding whether we manage to improve the LaTeX output (as Uwe suggests rightly in the bug report), because this case can nevertheless occur, so the two attempts are orthogonal. The attached patch is a bit more complicated than my first attempt on bugzilla that just ends every font size command by '{}' instead of a blank, but it results in better LaTeX output. It checks whether a font switch command with a trailing blank has occured, and if so, it outputs a normal space ("\ ") instead of a blank, i.e. in the case above: \textcolor{red}{\small a}{\small \ word} Even better would be "\small\ word", but I don't see how I could get that. So I think this is the best we can do for now, however I'm not entirely sure about the implementation details. So please have a look if it strikes you correct. Jürgen
Index: src/Paragraph.cpp =================================================================== --- src/Paragraph.cpp (Revision 19033) +++ src/Paragraph.cpp (Arbeitskopie) @@ -66,6 +66,7 @@ namespace lyx { using support::contains; +using support::suffixIs; using support::rsplit; @@ -2065,24 +2066,38 @@ } } + bool trailing_blank = false; // Do we need to change font? if ((font != running_font || font.language() != running_font.language()) && i != body_pos - 1) { - column += font.latexWriteStartChanges(os, bparams, + odocstringstream ods; + column += font.latexWriteStartChanges(ods, bparams, runparams, basefont, last_font); running_font = font; open_font = true; + docstring fontchange = ods.str(); + // check if the fontchange ends with a trailing blank + if (suffixIs(fontchange, 0x0020)) + trailing_blank = true; + os << fontchange; } if (c == ' ') { + // If a blank follows a font change that is itself finished + // by a blank (e.g. "{\Huge "), we need a normal space + // in order to prevent the blank from being swallowed. + if (trailing_blank) { + os << "\\ "; + column += 2; + } // Do not print the separation of the optional argument // if style->pass_thru is false. This works because // simpleTeXSpecialChars ignores spaces if // style->pass_thru is false. - if (i != body_pos - 1) { + else if (i != body_pos - 1) { if (pimpl_->simpleTeXBlanks( *(runparams.encoding), os, texrow, i, column, font, *style))