]> git.lyx.org Git - features.git/commitdiff
Fix for CJK-documents with input-encoding "utf8".
authorGünter Milde <milde@lyx.org>
Mon, 28 Jan 2019 16:49:58 +0000 (17:49 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Jun 2020 12:39:57 +0000 (14:39 +0200)
autotests/export/latex/CJK/ja-en-de-el-ru_utf8-cjk.lyx
development/autotests/invertedTests
src/output_latex.cpp

index b22bc5a75fbcb3767bc3038d42089289b6509f15..54d10b9c11c793efdfc056a4d40ce33f959a2803 100644 (file)
@@ -105,7 +105,7 @@ For multi-lingual documents with parts in European languages, you can use
 
 \begin_layout Enumerate
 Short texts may be written without setting the language (hyphenation will
- be missing and spell-checking complain): Greetings; Grüße; Приветы; χαιρετισμός
+ be missing and spell-checking complain): Greetings; Grüße; Приветы; χαιρετισμός.
 \end_layout
 
 \begin_layout Enumerate
index 1b49a0a4dd6003bba37488c18e9756d180c6574b..e9ade78ac8fa88dea30d48f6fcef7c9fcd9b45fd 100644 (file)
@@ -86,7 +86,7 @@ export/examples/ja/multilingual_.*_systemF
 # CJK for multilingual documents:
 #
 # input-encoding "utf8" should work for documents using a CJK language:
-export/export/latex/CJK/.*-en-de-el-ru_utf8_pdf2
+#export/export/latex/CJK/.*-en-de-el-ru_utf8_pdf2
 #
 # but that is not so easy if the main language does not require CJK:
 export/export/latex/CJK/en-de-el-ru-.*_utf8_pdf2
index 67c667caa330cdde96ca9131dc0c3b9f898c3c21..f360c15e21df2f454c70051ce800d2cdf6ea00e3 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,
@@ -1273,6 +1273,7 @@ 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.
+       // FIXME: don't close if the paragraph is nested in an environment
        if (runparams.isLastPar && !style.isEnvironment()) {
                switch (state->open_encoding_) {
                        case CJK: {
@@ -1563,7 +1564,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 +1609,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 +1625,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 for CJK 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 +1699,6 @@ pair<bool, int> switchEncoding(odocstream & os, BufferParams const & bparams,
        }
        // Dead code to avoid a warning:
        return make_pair(true, 0);
-
 }
 
 } // namespace lyx