]> git.lyx.org Git - lyx.git/blobdiff - src/output_latex.cpp
Remove special code for CJK that is no longer required (amends e665715fc4).
[lyx.git] / src / output_latex.cpp
index af7d5c971c762262b938edf477aab15831e58e02..7cc5b73e225a472af7d2ee53f6d6b56c20b23b99 100644 (file)
@@ -307,11 +307,8 @@ static TeXEnvironmentData prepareEnvironment(Buffer const & buf,
        if (data.par_language->encoding()->package() == Encoding::CJK &&
            state->open_encoding_ != CJK && pit->isMultiLingual(bparams)) {
                if (prev_par_language->encoding()->package() == Encoding::CJK) {
-                       docstring const cjkenc = (bparams.encoding().name() == "utf8-cjk"
-                                                 && LaTeXFeatures::isAvailable("CJKutf8")) ?
-                                                       from_ascii("UTF8")
-                                                     : from_ascii(data.par_language->encoding()->latexName());
-                       os << "\\begin{CJK}{" << cjkenc
+                       os << "\\begin{CJK}{"
+                          << from_ascii(data.par_language->encoding()->latexName())
                           << "}{" << from_ascii(bparams.fonts_cjk) << "}%\n";
                }
                state->open_encoding_ = CJK;
@@ -530,6 +527,10 @@ void getArgInsets(otexstream & os, OutputParams const & runparams, Layout::LaTeX
                        }
                }
        }
+       if (runparams.for_search) {
+               // Mark end of arguments for findadv() only
+               os << "\\endarguments{}";
+       }
 }
 
 
@@ -696,6 +697,11 @@ void parStartCommand(Paragraph const & par, otexstream & os,
                        os << " ";
                }
                break;
+       case LATEX_ENVIRONMENT:
+               if (runparams.for_search) {
+                       os << "\\latexenvironment{" << style.latexname() << "}{";
+               }
+               break;
        case LATEX_BIB_ENVIRONMENT:
                // ignore this, the inset will write itself
                break;
@@ -877,7 +883,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 +896,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,
@@ -999,11 +1005,8 @@ void TeXOnePar(Buffer const & buf,
                        // context (nesting issue).
                        if (par_language->encoding()->package() == Encoding::CJK
                                && state->open_encoding_ != CJK && state->cjk_inherited_ == 0) {
-                               docstring const cjkenc = (bparams.encoding().name() == "utf8-cjk"
-                                                         && LaTeXFeatures::isAvailable("CJKutf8")) ?
-                                                               from_ascii("UTF8")
-                                                             : from_ascii(par_language->encoding()->latexName());
-                               os << "\\begin{CJK}{" << cjkenc
+                               os << "\\begin{CJK}{"
+                                  << from_ascii(par_language->encoding()->latexName())
                                   << "}{" << from_ascii(bparams.fonts_cjk) << "}%\n";
                                state->open_encoding_ = CJK;
                        }
@@ -1033,6 +1036,8 @@ void TeXOnePar(Buffer const & buf,
        }
 
        runparams.moving_arg |= style.needprotect;
+       if (style.needmboxprotect)
+               ++runparams.inulemcmd;
        Encoding const * const prev_encoding = runparams.encoding;
 
        bool const useSetSpace = bparams.documentClass().provides("SetSpace");
@@ -1262,7 +1267,8 @@ void TeXOnePar(Buffer const & buf,
        // 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 (nextpar
-               && state->open_encoding_ == CJK
+               && (state->open_encoding_ == CJK && bparams.encoding().iconvName() != "UTF-8"
+                       && bparams.encoding().package() != Encoding::CJK )
                && (nextpar_language->encoding()->package() != Encoding::CJK
                   || (nextpar->layout().isEnvironment() && nextpar->isMultiLingual(bparams)))
                // inbetween environments, CJK has to be closed later (nesting!)
@@ -1272,16 +1278,18 @@ 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
                                if (maintext && buf.masterBuffer() != &buf)
                                        break;
-                               // end of main text
+                               // end of main text: also insert a \clearpage (see #5386)
                                if (maintext) {
-                                       os << "\n\\end{CJK}\n";
+                                       os << "\n\\clearpage\n\\end{CJK}\n";
                                // end of an inset
                                } else
                                        os << "\\end{CJK}";
@@ -1402,17 +1410,20 @@ void latexParagraphs(Buffer const & buf,
        }
 
        // Open a CJK environment at the beginning of the main buffer
-       // if the document's language is a CJK language
-       // (but not in child documents)
+       // if the document's main encoding requires the CJK package
+       // or the document encoding is utf8 and the CJK package is required
+       // (but not in child documents or documents using system fonts):
        OutputState * state = getOutputState();
        if (maintext && !is_child && !bparams.useNonTeXFonts
-           && bparams.language->encoding()->package() == Encoding::CJK
-           && (bparams.encoding().name() == "utf8-cjk"
-               || bparams.encoding().iconvName() != "UTF-8")) {
-               docstring const cjkenc = (bparams.encoding().name() == "utf8-cjk"
-                                         && LaTeXFeatures::isAvailable("CJKutf8")) ?
-                                               from_ascii("UTF8")
-                                             : from_ascii(bparams.encoding().latexName());
+           && (bparams.encoding().package() == Encoding::CJK
+                       || (bparams.encoding().name() == "utf8"
+                               && bparams.language->encoding()->package() == Encoding::CJK)
+                               //  FIXME: should test if any language requires CJK
+                               //  && LaTeXFeatures::mustProvide("CJK"))
+                               // error: cannot call member function ‘bool lyx::LaTeXFeatures::mustProvide(const string&) const’ without object
+                  )) {
+               docstring const cjkenc = bparams.encoding().iconvName() == "UTF-8"
+                                                                ? from_ascii("UTF8") : from_ascii(bparams.encoding().latexName());
                os << "\\begin{CJK}{" << cjkenc
                   << "}{" << from_ascii(bparams.fonts_cjk) << "}%\n";
                state->open_encoding_ = CJK;
@@ -1561,7 +1572,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
@@ -1602,13 +1613,7 @@ pair<bool, int> switchEncoding(odocstream & os, BufferParams const & bparams,
 
        Encoding const & oldEnc = *runparams.encoding;
        bool moving_arg = runparams.moving_arg;
-       // If we switch from/to CJK, we need to switch anyway, despite custom inputenc,
-       // 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"));
-       if (!force && !from_to_cjk
+       if (!force
            && ((bparams.inputenc != "auto" && bparams.inputenc != "default") || moving_arg))
                return make_pair(false, 0);
 
@@ -1621,15 +1626,18 @@ 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
-       if (oldEnc.package() == Encoding::none
-               || newEnc.package() == Encoding::none)
+       //
+       // 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);
 
+       // change encoding
        LYXERR(Debug::LATEX, "Changing LaTeX encoding from "
-               << oldEnc.name() << " to " << newEnc.name());
+                  << oldEnc.name() << " to " << newEnc.name());
        os << setEncoding(newEnc.iconvName());
        if (bparams.inputenc == "default")
-               return make_pair(true, 0);
+         return make_pair(true, 0);
 
        docstring const inputenc_arg(from_ascii(newEnc.latexName()));
        OutputState * state = getOutputState();
@@ -1679,11 +1687,8 @@ pair<bool, int> switchEncoding(odocstream & os, BufferParams const & bparams,
                                os << "\\egroup";
                                count += 7;
                        }
-                       docstring const cjkenc = (bparams.encoding().name() == "utf8-cjk"
-                                                 && LaTeXFeatures::isAvailable("CJKutf8")) ?
-                                                       from_ascii("UTF8")
-                                                     : from_ascii(bparams.encoding().latexName());
-                       os << "\\begin{CJK}{" << cjkenc << "}{"
+                       os << "\\begin{CJK}{"
+                          << from_ascii(newEnc.latexName()) << "}{"
                           << from_ascii(bparams.fonts_cjk) << "}";
                        state->open_encoding_ = CJK;
                        return make_pair(true, count + 15);
@@ -1691,7 +1696,6 @@ pair<bool, int> switchEncoding(odocstream & os, BufferParams const & bparams,
        }
        // Dead code to avoid a warning:
        return make_pair(true, 0);
-
 }
 
 } // namespace lyx