+ // if this is a CJK-paragraph and the next isn't, close CJK
+ // also if the next paragraph is a multilingual environment (because of nesting)
+ if (boost::next(pit) != paragraphs.end() && open_encoding_ == CJK &&
+ (boost::next(pit)->getParLanguage(bparams)->encoding()->package() != Encoding::CJK ||
+ boost::next(pit)->layout()->isEnvironment() && boost::next(pit)->isMultiLingual(bparams))
+ // in environments, CJK has to be closed later (nesting!)
+ && !style->isEnvironment()) {
+ os << "\\end{CJK}\n";
+ open_encoding_ = none;
+ }
+
+ // If this is the last paragraph, close the CJK environment
+ // if necessary. If it's an environment, we'll have to \end that first.
+ if (boost::next(pit) == paragraphs.end() && !style->isEnvironment()) {
+ switch (open_encoding_) {
+ case CJK: {
+ // end of main text
+ if (runparams.local_font == 0) {
+ os << '\n';
+ texrow.newline();
+ os << "\\end{CJK}\n";
+ texrow.newline();
+ // end of an inset
+ } else
+ os << "\\end{CJK}";
+ open_encoding_ = none;
+ break;
+ }
+ case inputenc: {
+ os << "\\egroup";
+ open_encoding_ = none;
+ break;
+ }
+ case none:
+ default:
+ // do nothing
+ break;
+ }
+ // auto_end tag only if the last par is in a babel language
+ if (runparams.local_font == 0 && !lyxrc.language_auto_end &&
+ !bparams.language->babel().empty() &&
+ font.language()->encoding()->package() != Encoding::CJK) {
+ os << from_utf8(subst(lyxrc.language_command_end,
+ "$$lang",
+ bparams.language->babel()))
+ << '\n';
+ texrow.newline();
+ }
+ }
+