]> git.lyx.org Git - lyx.git/blobdiff - src/output_latex.cpp
ctests: fix/update CJK tests.
[lyx.git] / src / output_latex.cpp
index 67c667caa330cdde96ca9131dc0c3b9f898c3c21..370b1c308971ecef1955197576f613d806ca14ae 100644 (file)
@@ -877,7 +877,7 @@ void TeXOnePar(Buffer const & buf,
                lang_end_command = "}";
                lang_command_termination.clear();
        }
-       
+
        bool const localswitch_needed = localswitch && par_lang != outer_lang;
 
        // localswitches need to be closed and reopened at each par
@@ -890,7 +890,7 @@ void TeXOnePar(Buffer const & buf,
                if (!localswitch
                    && (!using_begin_end || langOpenedAtThisLevel(state))
                    && !lang_end_command.empty()
-                   && prev_lang != outer_lang 
+                   && prev_lang != outer_lang
                    && !prev_lang.empty()
                    && (!using_begin_end || !style.isEnvironment())) {
                        os << from_ascii(subst(lang_end_command,
@@ -1272,8 +1272,10 @@ void TeXOnePar(Buffer const & buf,
        }
 
        // 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 (runparams.isLastPar && !style.isEnvironment()) {
+       // if necessary. If it's an environment or nested in an environment,
+       // we'll have to \end that first.
+       if (runparams.isLastPar && !style.isEnvironment()
+               && par.params().depth() < 1) {
                switch (state->open_encoding_) {
                        case CJK: {
                                // do nothing at the end of child documents
@@ -1563,7 +1565,7 @@ void latexParagraphs(Buffer const & buf,
        // If the last paragraph is an environment, we'll have to close
        // CJK at the very end to do proper nesting.
        if (maintext && !is_child && state->open_encoding_ == CJK) {
-               os << "\\end{CJK}\n";
+               os << "\\clearpage\n\\end{CJK}\n";
                state->open_encoding_ = none;
        }
        // Likewise for polyglossia or when using begin/end commands
@@ -1608,8 +1610,9 @@ pair<bool, int> switchEncoding(odocstream & os, BufferParams const & bparams,
        // except if we use CJKutf8
        bool const from_to_cjk =
                ((oldEnc.package() == Encoding::CJK && newEnc.package() != Encoding::CJK)
-               || (oldEnc.package() != Encoding::CJK && newEnc.package() == Encoding::CJK))
-               && (bparams.encoding().name() != "utf8-cjk" || !LaTeXFeatures::isAvailable("CJKutf8"));
+                || (oldEnc.package() != Encoding::CJK && newEnc.package() == Encoding::CJK))
+               && ((bparams.encoding().name() != "utf8-cjk" && bparams.encoding().name() != "utf8")
+                       || !LaTeXFeatures::isAvailable("CJKutf8"));
        if (!force && !from_to_cjk
            && ((bparams.inputenc != "auto" && bparams.inputenc != "default") || moving_arg))
                return make_pair(false, 0);
@@ -1623,17 +1626,20 @@ pair<bool, int> switchEncoding(odocstream & os, BufferParams const & bparams,
        // This does of course only work in special cases (e.g. switch from
        // tis620-0 to latin1, but the text in latin1 contains ASCII only),
        // but it is the best we can do
-       // 
+       //
        // 2019-01-08 Possibly no longer required since tis620-0 is supported
        // by inputenc (but check special encodings "utf8-plain" and "default").
        if (oldEnc.package() == Encoding::none || newEnc.package() == Encoding::none)
                return make_pair(false, 0);
 
-       LYXERR(Debug::LATEX, "Changing LaTeX encoding from "
-               << oldEnc.name() << " to " << newEnc.name());
-       os << setEncoding(newEnc.iconvName());
-       if (bparams.inputenc == "default")
-               return make_pair(true, 0);
+       // change encoding (not required with UTF8)
+       if (bparams.encoding().iconvName() != "UTF-8") {
+               LYXERR(Debug::LATEX, "Changing LaTeX encoding from "
+                          << oldEnc.name() << " to " << newEnc.name());
+               os << setEncoding(newEnc.iconvName());
+               if (bparams.inputenc == "default")
+                 return make_pair(true, 0);
+       }
 
        docstring const inputenc_arg(from_ascii(newEnc.latexName()));
        OutputState * state = getOutputState();
@@ -1694,7 +1700,6 @@ pair<bool, int> switchEncoding(odocstream & os, BufferParams const & bparams,
        }
        // Dead code to avoid a warning:
        return make_pair(true, 0);
-
 }
 
 } // namespace lyx