On Sun, Oct 18, 2009 at 11:37:42AM +0200, Jürgen Spitzmüller wrote: > Enrico Forestieri wrote: > > The attached patch fixes the bug for me, but I have no idea if it is > > correct in a CJK environment. > > It looks correct, but of course some testing will not harm. We know how > sensitive this area is.
The attached patch uses a different approach. The correct language is restored directly in the child. I think that this is cleaner and also correct CJK-wise. -- Enrico
Index: src/insets/InsetInclude.cpp =================================================================== --- src/insets/InsetInclude.cpp (revisione 31652) +++ src/insets/InsetInclude.cpp (copia locale) @@ -542,10 +542,12 @@ int InsetInclude::latex(odocstream & os, // The included file might be written in a different encoding Encoding const * const oldEnc = runparams.encoding; runparams.encoding = &tmp->params().encoding(); + runparams.master_language = masterBuffer->params().language; tmp->makeLaTeXFile(writefile, masterFileName(buffer()).onlyPath().absFilename(), runparams, false); runparams.encoding = oldEnc; + runparams.master_language = 0; } else { // In this case, it's not a LyX file, so we copy the file // to the temp dir, so that .aux files etc. are not created Index: src/OutputParams.h =================================================================== --- src/OutputParams.h (revisione 31652) +++ src/OutputParams.h (copia locale) @@ -25,6 +25,7 @@ namespace lyx { class Encoding; class ExportData; class Font; +class Language; class OutputParams { @@ -91,6 +92,10 @@ public: */ mutable std::string document_language; + /** The master language. Non-null only for child documents. + */ + mutable Language const * master_language; + /** Current stream encoding. Only used for LaTeX. This must be set to the document encoding (via the constructor) before output starts. Afterwards it must be kept up to date for Index: src/output_latex.cpp =================================================================== --- src/output_latex.cpp (revisione 31652) +++ src/output_latex.cpp (copia locale) @@ -671,11 +671,18 @@ ParagraphList::const_iterator TeXOnePar( // 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()) { + // If this is a child, we should restore the + // master language after the last paragraph. + Language const * const current_language = + (nextpit == paragraphs.end() + && runparams.master_language) + ? runparams.master_language + : prev_language; + if (!current_language->babel().empty()) { os << from_ascii(subst( lyxrc.language_command_begin, "$$lang", - prev_language->babel())); + current_language->babel())); pending_newline = true; } } else if (!par_language->babel().empty()) { Index: src/OutputParams.cpp =================================================================== --- src/OutputParams.cpp (revisione 31652) +++ src/OutputParams.cpp (copia locale) @@ -20,7 +20,8 @@ namespace lyx { OutputParams::OutputParams(Encoding const * enc) : flavor(LATEX), nice(false), moving_arg(false), inulemcmd(false), - local_font(0), encoding(enc), free_spacing(false), use_babel(false), + local_font(0), master_language(0), encoding(enc), + free_spacing(false), use_babel(false), use_indices(false), use_japanese(false), linelen(0), depth(0), exportdata(new ExportData), inComment(false), inTableCell(NO), inFloat(NONFLOAT),