diff --git a/src/output_latex.cpp b/src/output_latex.cpp index 81e8581371..c3bb39bb85 100644 --- a/src/output_latex.cpp +++ b/src/output_latex.cpp @@ -51,7 +51,7 @@ enum OpenEncoding { }; static int open_encoding_ = none; -static bool cjk_inherited_ = false; +static int cjk_inherited_ = 0; ParagraphList::const_iterator @@ -299,9 +299,11 @@ TeXOnePar(Buffer const & buf, OutputParams runparams = runparams_in; runparams.moving_arg |= style->needprotect; - // we are at the beginning of an inset and CJK is already open. - if (pit == paragraphs.begin() && !maintext && open_encoding_ == CJK) { - cjk_inherited_ = true; + // we are at the beginning of an inset and CJK is already open; + // we count inheritation levels to get the inset nesting right. + if (pit == paragraphs.begin() && !maintext + && (cjk_inherited_ > 0 || open_encoding_ == CJK)) { + cjk_inherited_ += 1; open_encoding_ = none; } @@ -432,7 +434,7 @@ TeXOnePar(Buffer const & buf, // the following is necessary after a CJK environment in a multilingual // context (nesting issue). if (par_language->encoding()->package() == Encoding::CJK && - open_encoding_ != CJK && !cjk_inherited_) { + open_encoding_ != CJK && cjk_inherited_ == 0) { os << "\\begin{CJK}{" << from_ascii(par_language->encoding()->latexName()) << "}{}%\n"; open_encoding_ = CJK; @@ -851,9 +853,10 @@ void latexParagraphs(Buffer const & buf, open_encoding_ = none; } // reset inherited encoding - if (cjk_inherited_) { - open_encoding_ = CJK; - cjk_inherited_ = false; + if (cjk_inherited_ > 0) { + cjk_inherited_ -= 1; + if (cjk_inherited_ == 0) + open_encoding_ = CJK; } } diff --git a/status.15x b/status.15x index f58328495c..e9ff00c417 100644 --- a/status.15x +++ b/status.15x @@ -35,6 +35,8 @@ What's new * DOCUMENT INPUT/OUTPUT +- Fix a LaTeX error with nested insets in CJK documents (bug 4913). + - New layout and template files for the Journal of Statistical Software (JSS). - The importer for comma separated value (*.csv) files has been rewritten.