- // In some insets (such as Arguments), we cannot use \selectlanguage
- bool const localswitch = text.inset().forceLocalFontSwitch()
- || (use_polyglossia && text.inset().forcePlainLayout());
+ // For InTitle commands, we need to switch the language inside the command
+ // (see #10849); thus open the command here.
+ if (intitle_command) {
+ parStartCommand(par, os, runparams, style);
+ if (style.isCommand() && style.needprotect)
+ // Due to the moving argument, some fragile
+ // commands (labels, index entries)
+ // are output after this command (#2154)
+ runparams.postpone_fragile_stuff = true;
+ os << '{';
+ }
+
+ // 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 = runparams_in.for_search
+ || text.inset().forceLocalFontSwitch()
+ || (using_begin_end && text.inset().forcePlainLayout())
+ || in_polyglossia_rtl_env;