X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Foutput_latex.cpp;h=cdd42aaf4325222dffc0f18efff4d343bca6e20c;hb=e45427de389bc188f02ebe0de2c052740dcde09c;hp=2f4e765ebacdba2f7f1f0fcbe34b5c9bf53574a6;hpb=8c053ea10ce1187499bc112ae88d04d956ae48f9;p=lyx.git diff --git a/src/output_latex.cpp b/src/output_latex.cpp index 2f4e765eba..cdd42aaf43 100644 --- a/src/output_latex.cpp +++ b/src/output_latex.cpp @@ -181,7 +181,7 @@ TeXEnvironment(Buffer const & buf, << "}\n"; } else if (style.labeltype == LABEL_BIBLIO) { if (pit->params().labelWidthString().empty()) - os << '{' << bibitemWidest(buf) << "}\n"; + os << '{' << bibitemWidest(buf, runparams) << "}\n"; else os << '{' << pit->params().labelWidthString() @@ -252,14 +252,22 @@ TeXEnvironment(Buffer const & buf, os << "\\end{" << from_ascii(style.latexname()) << "}\n"; texrow.newline(); prev_env_language_ = par_language; - runparams.encoding = prev_encoding; + if (runparams.encoding != prev_encoding) { + runparams.encoding = prev_encoding; + if (!bparams.useXetex) + os << setEncoding(prev_encoding->iconvName()); + } } if (leftindent_open) { os << "\\end{LyXParagraphLeftIndent}\n"; texrow.newline(); prev_env_language_ = par_language; - runparams.encoding = prev_encoding; + if (runparams.encoding != prev_encoding) { + runparams.encoding = prev_encoding; + if (!bparams.useXetex) + os << setEncoding(prev_encoding->iconvName()); + } } if (par != paragraphs.end()) @@ -311,6 +319,15 @@ ParagraphList::const_iterator TeXOnePar(Buffer const & buf, OutputParams runparams = runparams_in; runparams.isLastPar = nextpit == paragraphs.end(); + bool const maintext = text.isMainText(); + // we are at the beginning of an inset and CJK is already open; + // we count inheritation levels to get the inset nesting right. + if (pit == paragraphs.begin() && !maintext + && (cjk_inherited_ > 0 || open_encoding_ == CJK)) { + cjk_inherited_ += 1; + open_encoding_ = none; + } + if (runparams.verbatim) { int const dist = distance(paragraphs.begin(), pit); Font const outerfont = text.outerFont(dist); @@ -331,17 +348,6 @@ ParagraphList::const_iterator TeXOnePar(Buffer const & buf, Layout const style = text.inset().forcePlainLayout() ? bparams.documentClass().plainLayout() : pit->layout(); - runparams.moving_arg |= style.needprotect; - - bool const maintext = text.isMainText(); - // we are at the beginning of an inset and CJK is already open; - // we count inheritation levels to get the inset nesting right. - if (pit == paragraphs.begin() && !maintext - && (cjk_inherited_ > 0 || open_encoding_ == CJK)) { - cjk_inherited_ += 1; - open_encoding_ = none; - } - // This paragraph's language Language const * const par_language = pit->getParLanguage(bparams); // The document's language @@ -454,7 +460,9 @@ ParagraphList::const_iterator TeXOnePar(Buffer const & buf, // Look ahead for future encoding changes. // We try to output them at the beginning of the paragraph, // since the \inputencoding command is not allowed e.g. in - // sections. + // sections. For this reason we only set runparams.moving_arg + // after checking for the encoding change, otherwise the + // change would be always avoided by switchEncoding(). for (pos_type i = 0; i < pit->size(); ++i) { char_type const c = pit->getChar(i); Encoding const * const encoding = @@ -505,6 +513,7 @@ ParagraphList::const_iterator TeXOnePar(Buffer const & buf, } } + runparams.moving_arg |= style.needprotect; Encoding const * const prev_encoding = runparams.encoding; bool const useSetSpace = bparams.documentClass().provides("SetSpace"); @@ -589,7 +598,11 @@ ParagraphList::const_iterator TeXOnePar(Buffer const & buf, os << "\\par}"; } else if (is_command) { os << '}'; - runparams.encoding = prev_encoding; + if (runparams.encoding != prev_encoding) { + runparams.encoding = prev_encoding; + if (!bparams.useXetex) + os << setEncoding(prev_encoding->iconvName()); + } } bool pending_newline = false; @@ -659,11 +672,18 @@ ParagraphList::const_iterator TeXOnePar(Buffer const & buf, // 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 + : outer_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()) { @@ -810,7 +830,7 @@ void latexParagraphs(Buffer const & buf, texrow.newline(); open_encoding_ = CJK; } - // if "auto begin" is switched off, explicitely switch the + // if "auto begin" is switched off, explicitly switch the // language on at start if (maintext && !lyxrc.language_auto_begin && !bparams.language->babel().empty()) { @@ -884,7 +904,7 @@ void latexParagraphs(Buffer const & buf, texrow.newline(); } - // if "auto end" is switched off, explicitely close the language at the end + // if "auto end" is switched off, explicitly close the language at the end // but only if the last par is in a babel language if (maintext && !lyxrc.language_auto_end && !bparams.language->babel().empty() && lastpar->getParLanguage(bparams)->encoding()->package() != Encoding::CJK) {