- 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()))
- {
+ // localswitches need to be closed and reopened at each par
+ if ((par_lang != prev_lang || localswitch)
+ // 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())) {