]> git.lyx.org Git - lyx.git/blobdiff - src/output_latex.C
Fix bug 2474; partial fix for 1777. Added last_reference_ member to QRef class and...
[lyx.git] / src / output_latex.C
index a109c934b455da8c44deee79104097463dcc7bc6..f1f43f48a596a728cfc0804f38f22686c0f924f1 100644 (file)
@@ -64,7 +64,7 @@ TeXDeeper(Buffer const & buf,
          odocstream & os, TexRow & texrow,
          OutputParams const & runparams)
 {
-       lyxerr[Debug::LATEX] << "TeXDeeper...     " << &*pit << endl;
+       LYXERR(Debug::LATEX) << "TeXDeeper...     " << &*pit << endl;
        ParagraphList::const_iterator par = pit;
 
        while (par != paragraphs.end() &&
@@ -77,7 +77,7 @@ TeXDeeper(Buffer const & buf,
                                             os, texrow, runparams);
                }
        }
-       lyxerr[Debug::LATEX] << "TeXDeeper...done " << endl;
+       LYXERR(Debug::LATEX) << "TeXDeeper...done " << endl;
 
        return par;
 }
@@ -90,7 +90,7 @@ TeXEnvironment(Buffer const & buf,
               odocstream & os, TexRow & texrow,
               OutputParams const & runparams)
 {
-       lyxerr[Debug::LATEX] << "TeXEnvironment...     " << &*pit << endl;
+       LYXERR(Debug::LATEX) << "TeXEnvironment...     " << &*pit << endl;
 
        BufferParams const & bparams = buf.params();
 
@@ -203,8 +203,8 @@ TeXEnvironment(Buffer const & buf,
                texrow.newline();
        }
 
-       if (par != paragraphs.end() && lyxerr.debugging(Debug::LATEX))
-               lyxerr << "TeXEnvironment...done " << &*par << endl;
+       if (par != paragraphs.end())
+               LYXERR(Debug::LATEX) << "TeXEnvironment...done " << &*par << endl;
        return par;
 }
 
@@ -240,7 +240,7 @@ TeXOnePar(Buffer const & buf,
          OutputParams const & runparams_in,
          string const & everypar)
 {
-       lyxerr[Debug::LATEX] << "TeXOnePar...     " << &*pit << " '"
+       LYXERR(Debug::LATEX) << "TeXOnePar...     " << &*pit << " '"
                << everypar << "'" << endl;
        BufferParams const & bparams = buf.params();
        LyXLayout_ptr style;
@@ -292,6 +292,33 @@ TeXOnePar(Buffer const & buf,
                }
        }
 
+       // Switch file encoding if necessary
+       if (bparams.inputenc == "auto") {
+               // 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
+               // sections.
+               for (pos_type i = 0; i < pit->size(); ++i) {
+                       char_type const c = pit->getChar(i);
+                       if (c < 0x80)
+                               continue;
+                       if (pit->isInset(i))
+                               break;
+                       // All characters before c are in the ASCII range, and
+                       // c is non-ASCII (but no inset), so change the
+                       // 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) {
+                               runparams.encoding = encoding;
+                               os << '\n';
+                               texrow.newline();
+                       }
+                       break;
+               }
+       }
+
        // In an inset with unlimited length (all in one row),
        // don't allow any special options in the paragraph
        if (!pit->forceDefaultParagraphs()) {
@@ -349,7 +376,6 @@ TeXOnePar(Buffer const & buf,
        // FIXME UNICODE
        os << from_utf8(everypar);
        bool need_par = pit->simpleTeXOnePar(buf, bparams, outerfont,
-       //                                     *encoding,
                                             os, texrow, runparams);
 
        // Make sure that \\par is done with the font of the last
@@ -457,9 +483,8 @@ TeXOnePar(Buffer const & buf,
                texrow.newline();
        }
 
-       if (boost::next(pit) != paragraphs.end() &&
-           lyxerr.debugging(Debug::LATEX))
-               lyxerr << "TeXOnePar...done " << &*boost::next(pit) << endl;
+       if (boost::next(pit) != paragraphs.end())
+               LYXERR(Debug::LATEX) << "TeXOnePar...done " << &*boost::next(pit) << endl;
 
        return ++pit;
 }
@@ -565,17 +590,21 @@ void latexParagraphs(Buffer const & buf,
 
 
 int switchEncoding(odocstream & os, BufferParams const & bparams,
-                   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.
-       if ((bparams.inputenc == "auto" || bparams.inputenc == "default") &&
+       // 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 "
+               LYXERR(Debug::LATEX) << "Changing LaTeX encoding from "
                                     << oldEnc.name() << " to "
                                     << newEnc.name() << endl;
                os << setEncoding(newEnc.iconvName());