]> git.lyx.org Git - lyx.git/blobdiff - src/output_latex.cpp
BufferParams.h: add comment
[lyx.git] / src / output_latex.cpp
index 55cec5bbb761c8dc15699c4151d010c7885df145..152fd89e09b242b471d9210f5448572e39926a61 100644 (file)
@@ -94,7 +94,7 @@ TeXEnvironment(Buffer const & buf,
 
        BufferParams const & bparams = buf.params();
 
-       LyXLayout_ptr const & style = pit->layout();
+       Layout_ptr const & style = pit->layout();
 
        Language const * const par_language = pit->getParLanguage(bparams);
        Language const * const doc_language = bparams.language;
@@ -105,7 +105,8 @@ TeXEnvironment(Buffer const & buf,
        if (par_language->babel() != prev_par_language->babel()) {
 
                if (!lyxrc.language_command_end.empty() &&
-                   prev_par_language->babel() != doc_language->babel()) {
+                   prev_par_language->babel() != doc_language->babel() &&
+                   !prev_par_language->babel().empty()) {
                        os << from_ascii(subst(
                                lyxrc.language_command_end,
                                "$$lang",
@@ -115,7 +116,8 @@ TeXEnvironment(Buffer const & buf,
                }
 
                if (lyxrc.language_command_end.empty() ||
-                   par_language->babel() != doc_language->babel()) {
+                   par_language->babel() != doc_language->babel() &&
+                   !par_language->babel().empty()) {
                        os << from_ascii(subst(
                                lyxrc.language_command_begin,
                                "$$lang",
@@ -243,14 +245,14 @@ TeXOnePar(Buffer const & buf,
        LYXERR(Debug::LATEX) << "TeXOnePar...     " << &*pit << " '"
                << everypar << "'" << endl;
        BufferParams const & bparams = buf.params();
-       LyXLayout_ptr style;
+       Layout_ptr style;
 
        // In an inset with unlimited length (all in one row),
        // force layout to default
        if (!pit->forceDefaultParagraphs())
                style = pit->layout();
        else
-               style = bparams.getLyXTextClass().defaultLayout();
+               style = bparams.getTextClass().defaultLayout();
 
        OutputParams runparams = runparams_in;
        runparams.moving_arg |= style->needprotect;
@@ -271,7 +273,8 @@ TeXOnePar(Buffer const & buf,
                     || boost::prior(pit)->getDepth() < pit->getDepth())))
        {
                if (!lyxrc.language_command_end.empty() &&
-                   prev_par_language->babel() != doc_language->babel())
+                   prev_par_language->babel() != doc_language->babel() &&
+                   !prev_par_language->babel().empty())
                {
                        os << from_ascii(subst(lyxrc.language_command_end,
                                "$$lang",
@@ -281,7 +284,8 @@ TeXOnePar(Buffer const & buf,
                }
 
                if (lyxrc.language_command_end.empty() ||
-                   par_language->babel() != doc_language->babel())
+                   par_language->babel() != doc_language->babel() &&
+                   !par_language->babel().empty())
                {
                        os << from_ascii(subst(
                                lyxrc.language_command_begin,
@@ -293,7 +297,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
@@ -309,7 +314,8 @@ 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,
+                       if (encoding->package() == Encoding::inputenc &&
+                           switchEncoding(os, bparams, false,
                                           *(runparams.encoding), *encoding) > 0) {
                                runparams.encoding = encoding;
                                os << '\n';
@@ -456,17 +462,21 @@ TeXOnePar(Buffer const & buf,
                        os << '\n';
                        texrow.newline();
                }
-               if (lyxrc.language_command_end.empty())
-                       os << from_ascii(subst(
-                               lyxrc.language_command_begin,
-                               "$$lang",
-                               doc_language->babel()));
-               else
+               if (lyxrc.language_command_end.empty()) {
+                       if (!doc_language->babel().empty()) {
+                               os << from_ascii(subst(
+                                       lyxrc.language_command_begin,
+                                       "$$lang",
+                                       doc_language->babel()));
+                               pending_newline = true;
+                       }
+               } 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) {
@@ -502,7 +512,7 @@ void latexParagraphs(Buffer const & buf,
 {
        bool was_title = false;
        bool already_title = false;
-       LyXTextClass const & tclass = buf.params().getLyXTextClass();
+       TextClass const & tclass = buf.params().getTextClass();
        ParagraphList::const_iterator par = paragraphs.begin();
        ParagraphList::const_iterator endpar = paragraphs.end();
 
@@ -526,7 +536,7 @@ void latexParagraphs(Buffer const & buf,
                // any environment other than the default layout of the
                // text class to be valid!
                if (!par->forceDefaultParagraphs()) {
-                       LyXLayout_ptr const & layout = par->layout();
+                       Layout_ptr const & layout = par->layout();
 
                        if (layout->intitle) {
                                if (already_title) {
@@ -593,27 +603,54 @@ int switchEncoding(odocstream & os, BufferParams const & bparams,
                    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;
 }