Am Dienstag, 16. Januar 2007 10:50 schrieb Dov Feldstern: > I just spent two hours playing around with this, and it turns out that > the problem *is* with the way LyX is writing the output. I don't exactly > understand what's going on, but I was able to fix it with a really > simple patch (attached) --- although since I don't exactly understand > the problem, I can't vouch for the patch's correctness. It does work for > me, however. > > If you want to see the example file I worked with, I can give it to you, > but I'd rather not post it publicly (it's an old version of my CV). Is > there any way for me to get it to you privately?
Dov sent me the file, and I found the problem. When I added the switchEncoding call after the paragraph I assumed that outputting additional newlines would not harm, since we are at a paragraph end anyway. This is not true in general, if we have a size change LyX will create code like this: \par\end{center}{\LARGE \par} \begin{spacing}{1.20} If the paragraph needs an encoding change at the end this will become: \par\end{center}{\LARGE \par} \inputencoding{latin9} \begin{spacing}{1.20} This results in an additional empty paragraph. Therefore this patch avoids the additional newline with the help of a new flag pending_newline, and the output will look now like this: \par\end{center}{\LARGE \par}\inputencoding{latin9} \begin{spacing}{1.20} The patch is going in now, since it fixes a regression to 1.4.x (Dov's document now has identical output with inputenc == "default" and with "auto"). The call of switchEncoding() before the paragraph start does not need to be changed, similar code is also in 1.4.x, and it does not harm. Georg
Index: src/output_latex.C =================================================================== --- src/output_latex.C (Revision 16739) +++ src/output_latex.C (Arbeitskopie) @@ -393,14 +393,13 @@ TeXOnePar(Buffer const & buf, } else if (is_command) os << '}'; + bool pending_newline = false; switch (style->latextype) { case LATEX_ITEM_ENVIRONMENT: case LATEX_LIST_ENVIRONMENT: if (boost::next(pit) != paragraphs.end() - && (pit->params().depth() < boost::next(pit)->params().depth())) { - os << '\n'; - texrow.newline(); - } + && (pit->params().depth() < boost::next(pit)->params().depth())) + pending_newline = true; break; case LATEX_ENVIRONMENT: { // if its the last paragraph of the current environment @@ -416,10 +415,8 @@ TeXOnePar(Buffer const & buf, // fall through possible default: // we don't need it for the last paragraph!!! - if (boost::next(pit) != paragraphs.end()) { - os << '\n'; - texrow.newline(); - } + if (boost::next(pit) != paragraphs.end()) + pending_newline = true; } if (!pit->forceDefaultParagraphs()) { @@ -427,9 +424,12 @@ TeXOnePar(Buffer const & buf, && (boost::next(pit) == paragraphs.end() || !boost::next(pit)->hasSameLayout(*pit))) { - os << from_ascii(pit->params().spacing().writeEnvirEnd()) - << '\n'; - texrow.newline(); + if (pending_newline) { + os << '\n'; + texrow.newline(); + } + os << from_ascii(pit->params().spacing().writeEnvirEnd()); + pending_newline = true; } } @@ -439,19 +439,21 @@ TeXOnePar(Buffer const & buf, // we need to reset the language at the end of footnote or // float. + if (pending_newline) { + os << '\n'; + texrow.newline(); + } if (lyxrc.language_command_end.empty()) os << from_ascii(subst( lyxrc.language_command_begin, "$$lang", - doc_language->babel())) - << '\n'; + doc_language->babel())); else os << from_ascii(subst( lyxrc.language_command_end, "$$lang", - language->babel())) - << '\n'; - texrow.newline(); + language->babel())); + pending_newline = true; } // FIXME we switch from the encoding of this paragraph to the @@ -459,8 +461,9 @@ TeXOnePar(Buffer const & buf, // to take the encoding of the next paragraph into account. // This may result in some unneeded encoding changes. basefont = pit->getLayoutFont(bparams, outerfont); - if (switchEncoding(os, bparams, *(basefont.language()->encoding()), - outer_encoding)) { + switchEncoding(os, bparams, *(basefont.language()->encoding()), + outer_encoding); + if (pending_newline) { os << '\n'; texrow.newline(); }