]> git.lyx.org Git - lyx.git/blobdiff - src/output_latex.cpp
* Only enter inset which return true on isActive(). This is the behavior in the curso...
[lyx.git] / src / output_latex.cpp
index d281feac0a9e190b50e375aa0123f47d60fcd626..10a4191c0330e23b8bcb254202a988ad754d924e 100644 (file)
@@ -115,8 +115,8 @@ TeXEnvironment(Buffer const & buf,
                        texrow.newline();
                }
 
-               if (lyxrc.language_command_end.empty() ||
-                   par_language->babel() != doc_language->babel() &&
+               if ((lyxrc.language_command_end.empty() ||
+                    par_language->babel() != doc_language->babel()) &&
                    !par_language->babel().empty()) {
                        os << from_ascii(subst(
                                lyxrc.language_command_begin,
@@ -283,10 +283,9 @@ TeXOnePar(Buffer const & buf,
                        texrow.newline();
                }
 
-               if (lyxrc.language_command_end.empty() ||
-                   par_language->babel() != doc_language->babel() &&
-                   !par_language->babel().empty())
-               {
+               if ((lyxrc.language_command_end.empty() ||
+                    par_language->babel() != doc_language->babel()) &&
+                   !par_language->babel().empty()) {
                        os << from_ascii(subst(
                                lyxrc.language_command_begin,
                                "$$lang",
@@ -297,7 +296,8 @@ TeXOnePar(Buffer const & buf,
        }
 
        // Switch file encoding if necessary
-       if (bparams.inputenc == "auto") {
+       if (bparams.inputenc == "auto" &&
+           runparams.encoding->package() == Encoding::inputenc) {
                // Look ahead for future encoding changes.
                // We try to output them at the beginning of the paragraph,
                // since the \inputencoding command is not allowed e.g. in
@@ -313,8 +313,9 @@ TeXOnePar(Buffer const & buf,
                        // encoding to that required by the language of c.
                        Encoding const * const encoding =
                                pit->getFontSettings(bparams, i).language()->encoding();
-                       if (switchEncoding(os, bparams, false,
-                                          *(runparams.encoding), *encoding) > 0) {
+                       if (encoding->package() == Encoding::inputenc &&
+                           switchEncoding(os, bparams, false,
+                                          *(runparams.encoding), *encoding) > 0) {
                                runparams.encoding = encoding;
                                os << '\n';
                                texrow.newline();
@@ -468,12 +469,13 @@ TeXOnePar(Buffer const & buf,
                                        doc_language->babel()));
                                pending_newline = true;
                        }
-               } else if (!par_language->babel().empty())
+               } else if (!par_language->babel().empty()) {
                        os << from_ascii(subst(
                                lyxrc.language_command_end,
                                "$$lang",
                                par_language->babel()));
-               pending_newline = true;
+                       pending_newline = true;
+               }
        }
 
        if (pending_newline) {
@@ -567,7 +569,7 @@ void latexParagraphs(Buffer const & buf,
                                par = TeXOnePar(buf, paragraphs, par, os, texrow,
                                                runparams, everypar);
                        } else if (layout->isEnvironment() ||
-                                  !par->params().leftIndent().zero()) {
+                                  !par->params().leftIndent().zero()) {
                                par = TeXEnvironment(buf, paragraphs, par, os,
                                                     texrow, runparams);
                        } else {
@@ -597,30 +599,57 @@ void latexParagraphs(Buffer const & buf,
 
 
 int switchEncoding(odocstream & os, BufferParams const & bparams,
-                   bool moving_arg, Encoding const & oldEnc,
-                   Encoding const & newEnc)
+                  bool moving_arg, Encoding const & oldEnc,
+                  Encoding const & newEnc)
 {
-       // FIXME thailatex does not support the inputenc package, so we
-       // ignore switches from/to tis620-0 encoding here. This does of
-       // course only work as long as the non-thai text contains ASCII
-       // only, but it is the best we can do.
-       // Since the \inputencoding command does not work inside sections
-       // we ignore the encoding switch also in moving arguments.
-       if (((bparams.inputenc == "auto" && !moving_arg) ||
-            bparams.inputenc == "default") &&
-           oldEnc.name() != newEnc.name() &&
-           oldEnc.name() != "ascii" && newEnc.name() != "ascii" &&
-           oldEnc.name() != "tis620-0" && newEnc.name() != "tis620-0") {
-               LYXERR(Debug::LATEX) << "Changing LaTeX encoding from "
-                                    << oldEnc.name() << " to "
-                                    << newEnc.name() << endl;
-               os << setEncoding(newEnc.iconvName());
-               if (bparams.inputenc != "default") {
-                       docstring const inputenc(from_ascii(newEnc.latexName()));
+       if ((bparams.inputenc != "auto" || moving_arg)
+               && bparams.inputenc != "default")
+               return 0;
+
+       // Do nothing if the encoding is unchanged.
+       if (oldEnc.name() == newEnc.name())
+               return 0;
+
+       // FIXME We ignore encoding switches from/to encodings that do
+       // neither support the inputenc package nor the CJK package here.
+       // 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)
+               return 0;
+
+       LYXERR(Debug::LATEX) << "Changing LaTeX encoding from "
+               << oldEnc.name() << " to "
+               << newEnc.name() << endl;
+       os << setEncoding(newEnc.iconvName());
+       if (bparams.inputenc == "default")
+               return 0;
+
+       docstring const inputenc(from_ascii(newEnc.latexName()));
+       switch (newEnc.package()) {
+               case Encoding::none:
+                       return 0;
+               case Encoding::inputenc: {
+                       int count = inputenc.length();
+                       if (oldEnc.package() == Encoding::CJK) {
+                               os << "\\end{CJK}";
+                               count += 9;
+                       }
                        os << "\\inputencoding{" << inputenc << '}';
-                       return 16 + inputenc.length();
+                       return count + 16;
+                }
+               case Encoding::CJK: {
+                       int count = inputenc.length();
+                       if (oldEnc.package() == Encoding::CJK) {
+                               os << "\\end{CJK}";
+                               count += 9;
+                       }
+                       os << "\\begin{CJK}{" << inputenc << "}{}";
+                       return count + 15;
                }
        }
+       // Dead code to avoid a warning:
        return 0;
 }