X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Foutput_latex.cpp;h=bdc7cb28efd40c513460f75581b327debaab38e2;hb=4480b72a9dc8a5453a17edf55d4d4a60847a68ae;hp=fa890f5b3c250be9b4f4c916fdfd058bfa010bb5;hpb=bcb002039b1a0e4893f18a032e02b6f6368924f9;p=lyx.git diff --git a/src/output_latex.cpp b/src/output_latex.cpp index fa890f5b3c..bdc7cb28ef 100644 --- a/src/output_latex.cpp +++ b/src/output_latex.cpp @@ -790,6 +790,9 @@ void TeXOnePar(Buffer const & buf, // environment with nesting depth greater than (or equal to, but with // a different layout) the current one. If there is no previous // paragraph, the previous language is the outer language. + // Note further that we take the outer language also if the prior par + // is PassThru, since in that case it has latex_language, and all secondary + // languages have been closed (#10793). bool const use_prev_env_language = state->prev_env_language_ != 0 && priorpar && priorpar->layout().isEnvironment() @@ -797,12 +800,11 @@ void TeXOnePar(Buffer const & buf, || (priorpar->getDepth() == par.getDepth() && priorpar->layout() != par.layout())); Language const * const prev_language = - (pit != 0) + (priorpar && !priorpar->isPassThru()) ? (use_prev_env_language ? state->prev_env_language_ : priorpar->getParLanguage(bparams)) : outer_language; - bool const use_polyglossia = runparams.use_polyglossia; string const par_lang = use_polyglossia ? getPolyglossiaEnvName(par_language): par_language->babel(); @@ -829,32 +831,43 @@ void TeXOnePar(Buffer const & buf, os << '{'; } - // In some insets (such as Arguments), we cannot use \selectlanguage + // In some insets (such as Arguments), we cannot use \selectlanguage. + // Also, if an RTL language is set via environment in polyglossia, + // only a nested \\text command will reset the direction for LTR + // languages (see # 10111). + bool const in_polyglossia_rtl_env = + use_polyglossia + && runparams.local_font != 0 + && outer_language->rightToLeft() + && !par_language->rightToLeft(); bool const localswitch = text.inset().forceLocalFontSwitch() - || (using_begin_end && text.inset().forcePlainLayout()); + || (using_begin_end && text.inset().forcePlainLayout()) + || in_polyglossia_rtl_env; if (localswitch) { lang_begin_command = use_polyglossia ? "\\text$$lang$$opts{" : lyxrc.language_command_local; lang_end_command = "}"; lang_command_termination.clear(); } - - if (par_lang != prev_lang - // check if we already put language command in TeXEnvironment() - && !(style.isEnvironment() - && (pit == 0 || (priorpar->layout() != par.layout() - && priorpar->getDepth() <= par.getDepth()) - || priorpar->getDepth() < par.getDepth()))) - { - if ((!using_begin_end || langOpenedAtThisLevel(state)) && - !lang_end_command.empty() && - prev_lang != outer_lang && - !prev_lang.empty() && - (!using_begin_end || !style.isEnvironment())) - { + + bool const localswitch_needed = localswitch && par_lang != outer_lang; + + // localswitches need to be closed and reopened at each par + if ((par_lang != prev_lang || localswitch_needed) + // check if we already put language command in TeXEnvironment() + && !(style.isEnvironment() + && (pit == 0 || (priorpar->layout() != par.layout() + && priorpar->getDepth() <= par.getDepth()) + || priorpar->getDepth() < par.getDepth()))) { + if (!localswitch + && (!using_begin_end || langOpenedAtThisLevel(state)) + && !lang_end_command.empty() + && prev_lang != outer_lang + && !prev_lang.empty() + && (!using_begin_end || !style.isEnvironment())) { os << from_ascii(subst(lang_end_command, - "$$lang", - prev_lang)) + "$$lang", + prev_lang)) << lang_command_termination; if (using_begin_end) popLanguageName(); @@ -1115,7 +1128,8 @@ void TeXOnePar(Buffer const & buf, &&((nextpar && par_lang != nextpar_lang) || (runparams.isLastPar && par_lang != outer_lang)); - if ((intitle_command && using_begin_end) + if (localswitch_needed + || (intitle_command && using_begin_end) || closing_rtl_ltr_environment || ((runparams.isLastPar || close_lang_switch) && (par_lang != outer_lang || (using_begin_end @@ -1125,7 +1139,7 @@ void TeXOnePar(Buffer const & buf, // we need to reset the language at the end of footnote or // float. - if (pending_newline || close_lang_switch) + if (!localswitch && (pending_newline || close_lang_switch)) os << '\n'; // when the paragraph uses CJK, the language has to be closed earlier @@ -1169,7 +1183,8 @@ void TeXOnePar(Buffer const & buf, && style != nextpar->layout()))) || (atSameLastLangSwitchDepth(state) && state->lang_switch_depth_.size() - && cur_lang != par_lang)) + && cur_lang != par_lang) + || in_polyglossia_rtl_env) { if (using_begin_end && !localswitch) os << breakln;