+ // We need to open a new language if we couldn't close the previous
+ // one (because there's no language_command_end); and even if we closed
+ // the previous one, if the current language is different than the
+ // outer_language (which is currently in effect once the previous one
+ // is closed).
+ if ((lyxrc.language_command_end.empty() ||
+ par_language->babel() != outer_language->babel()) &&
+ !par_language->babel().empty()) {
+ // If we're inside an inset, and that inset is within an \L or \R
+ // (or equivalents), then within the inset, too, any opposite
+ // language paragraph should appear within an \L or \R (in addition
+ // to, outside of, the normal language switch commands).
+ // This behavior is not correct for ArabTeX, though.
+ if ( // not for ArabTeX
+ (par_language->lang() != "arabic_arabtex" &&
+ outer_language->lang() != "arabic_arabtex") &&
+ // are we in an inset?
+ runparams.local_font != 0 &&
+ // is the inset within an \L or \R?
+ //
+ // FIXME: currently, we don't check this; this means that
+ // we'll have unnnecessary \L and \R commands, but that
+ // doesn't seem to hurt (though latex will complain)
+ //
+ // is this paragraph in the opposite direction?
+ runparams.local_font->isRightToLeft() !=
+ par_language->rightToLeft()
+ ) {
+ // FIXME: I don't have a working copy of the Arabi package, so
+ // I'm not sure if the farsi and arabic_arabi stuff is correct
+ // or not...
+ if (par_language->lang() == "farsi")
+ os << "\\textFR{";
+ else if (outer_language->lang() == "farsi")
+ os << "\\textLR{";
+ else if (par_language->lang() == "arabic_arabi")
+ os << "\\textAR{";
+ else if (outer_language->lang() == "arabic_arabi")
+ os << "\\textLR{";
+ // remaining RTL languages currently is hebrew
+ else if (par_language->rightToLeft())
+ os << "\\R{";
+ else
+ os << "\\L{";
+ }
+ // With CJK, the CJK tag has to be closed first (see below)
+ if (runparams.encoding->package() != Encoding::CJK) {
+ os << from_ascii(subst(
+ lyxrc.language_command_begin,
+ "$$lang",
+ par_language->babel()))
+ // the '%' is necessary to prevent unwanted whitespace
+ << "%\n";
+ texrow.newline();
+ }