string const getPolyglossiaBegin(string const & lang_begin_command,
- string const & lang, string const & opts)
+ string const & lang, string const & opts,
+ bool const localswitch = false)
{
string result;
- if (!lang.empty())
- result = subst(lang_begin_command, "$$lang", lang);
+ if (!lang.empty()) {
+ // we need to revert the upcasing done in getPolyglossiaEnvName()
+ // in case we have a local polyglossia command (\textarabic).
+ string language = localswitch ? ascii_lowercase(lang) : lang;
+ result = subst(lang_begin_command, "$$lang", language);
+ }
string options = opts.empty() ?
string() : "[" + opts + "]";
result = subst(result, "$$opts", options);
// 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()
|| (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();
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<lang> 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();
&& (par_lang != openLanguageName(state) || localswitch)
&& !par_lang.empty()) {
string bc = use_polyglossia ?
- getPolyglossiaBegin(lang_begin_command, par_lang, par_language->polyglossiaOpts())
+ getPolyglossiaBegin(lang_begin_command, par_lang,
+ par_language->polyglossiaOpts(),
+ localswitch)
: subst(lang_begin_command, "$$lang", par_lang);
os << bc;
os << lang_command_termination;
if (runparams.encoding->package() == Encoding::CJK
&& par_lang != openLanguageName(state)
&& !par_lang.empty()) {
- os << from_ascii(subst(
- lang_begin_command,
- "$$lang",
- par_lang))
- << lang_command_termination;
+ string bc = use_polyglossia ?
+ getPolyglossiaBegin(lang_begin_command, par_lang,
+ par_language->polyglossiaOpts(),
+ localswitch)
+ : subst(lang_begin_command, "$$lang", par_lang);
+ os << bc
+ << lang_command_termination;
if (using_begin_end)
pushLanguageName(par_lang, localswitch);
}
&&((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
// 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
&& current_lang != openLanguageName(state)) {
string bc = use_polyglossia ?
getPolyglossiaBegin(lang_begin_command, current_lang,
- current_language->polyglossiaOpts())
+ current_language->polyglossiaOpts(),
+ localswitch)
: subst(lang_begin_command, "$$lang", current_lang);
os << bc;
pending_newline = !localswitch;
&& 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;