On Fri, Oct 16, 2009 at 11:45:53AM -0400, rgheck wrote: > On 10/16/2009 10:43 AM, J�rgen Spitzm�ller wrote: > > rgheck wrote: > > > >> The attached files illustrate the bug. We have an English document that > >> includes a file marked for Spanish and one marked for English. The > >> English document ends up also being in Spanish, as the appearance of the > >> word "Figura" shows. There's some bug here then about language changes. > >> I think the problem is that, at the end of the LaTeX exported for the > >> Spanish document, we have "\selectlanguage{spanish}", where I think we > >> were supposed to be going back to English. > >> > > Actually, the behaviour is to be expected (although it's a bug, of course). > > At > > the beginning of the child, LyX switches the language with > > \selectlanguage{spanish}. Since we never switch back, Spanish remains the > > document language until the end. > > > See below. > > >> Strangely, if the included file contains no newlines (i.e., contains a > >> single paragraph), then the problem vanishes. > >> > > This is not strange: within in a single paragraph, we use > > \foreignlanguage{spanish}{<content>} > > so the language is closed in this case. > > > > I guess we need to treat child documents like environments, language-wise. > > A new task for Enrico. > > > > > That's not what I see. If there's only one paragraph, then we get > \selectlanguage{spanish} at the beginning of the child, and then > \selectlangauge{english} at the end. (Note that this is with \input, if > that matters.) If there is more than one paragraph, then we get > \selectlanguage{spanish} at the end. So I think there's some confusion > between outer_language and prev_language, or something like that, in the > code somewhere. But I can't disentangle those routines. > > Here's a little info. This code: > > // when the paragraph uses CJK, the language has to be closed > earlier > if (font.language()->encoding()->package() != Encoding::CJK) { > if (lyxrc.language_command_end.empty()) { > if (!prev_language->babel().empty()) { > os << from_ascii(subst( > lyxrc.language_command_begin, > "$$lang", > prev_language->babel())) << "% (6000)\n";; > pending_newline = true; > } > } else if (!par_language->babel().empty()) { > os << from_ascii(subst( > lyxrc.language_command_end, > "$$lang", > par_language->babel())) << "% (6)\n"; > pending_newline = true; > } > } > } > > is outputting the \selectlanguage{} command at the end of the included > file. (I added some debugging markers.) The language it wants to select > is prev_language. That gets set here: > > Language const * const prev_language = > (pit != paragraphs.begin()) > ? (use_prev_env_language ? prev_env_language_ > : priorpit->getParLanguage(bparams)) > : outer_language; > > The first test here explains why things work are different depending > upon how many paragraphs there are. But I don't understand what's > happening well enough to know what all these variables are doing.
The bug is due to the fact that LyX doesn't account for the fact that the language may be switched in an included child document. The first child is correctly translated to latex only because the include inset and the included child document have different languages, and thus the appropriate language switching commands are issued. However, the second include inset and included child document have the same language, and thus LyX deems unnecessary a language switch. Everything works when the first child has only one paragraph, only because at the end of the paragraph the outer language is still set to the inset master language, and it is this language that gets restored. The attached patch fixes the bug for me, but I have no idea if it is correct in a CJK environment. -- Enrico
Index: src/insets/InsetInclude.cpp =================================================================== --- src/insets/InsetInclude.cpp (revisione 31651) +++ src/insets/InsetInclude.cpp (copia locale) @@ -25,6 +25,7 @@ #include "Format.h" #include "FuncRequest.h" #include "FuncStatus.h" +#include "Language.h" #include "LaTeXFeatures.h" #include "LayoutFile.h" #include "LayoutModuleList.h" @@ -453,6 +454,7 @@ int InsetInclude::latex(odocstream & os, } Buffer const * const masterBuffer = buffer().masterBuffer(); + Language const * const masterLanguage = masterBuffer->params().language; // if incfile is relative, make it relative to the master // buffer directory. @@ -489,6 +491,8 @@ int InsetInclude::latex(odocstream & os, LYXERR(Debug::LATEX, "exportfile:" << exportfile); LYXERR(Debug::LATEX, "writefile:" << writefile); + bool reset_language = false; + if (runparams.inComment || runparams.dryrun) { //Don't try to load or copy the file if we're //in a comment or doing a dryrun @@ -500,6 +504,8 @@ int InsetInclude::latex(odocstream & os, return false; Buffer * tmp = theBufferList().getBuffer(included_file); + Language const * const childLanguage = tmp->params().language; + reset_language = masterLanguage->babel() != childLanguage->babel(); if (tmp->params().baseClass() != masterBuffer->params().baseClass()) { // FIXME UNICODE @@ -623,6 +629,13 @@ int InsetInclude::latex(odocstream & os, break; } + if (reset_language) { + os << from_ascii(subst( + lyxrc.language_command_begin, + "$$lang", + masterLanguage->babel())); + } + return 0; }