]> git.lyx.org Git - lyx.git/blobdiff - src/output_latex.cpp
Fix bug 4441. GuiRef: Ok button must be default.
[lyx.git] / src / output_latex.cpp
index 164d8886acc37e77efade9ce08fa24ec7d4f4616..c9538ca9a66d723a8b9dc32fd5f238a233e0f156 100644 (file)
@@ -3,7 +3,7 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
- * \author Lars Gullik Bjønnes
+ * \author Lars Gullik Bjønnes
  *
  * Full author contact details are available in file CREDITS.
  */
@@ -61,14 +61,6 @@ TeXEnvironment(Buffer const & buf,
               odocstream & os, TexRow & texrow,
               OutputParams const & runparams);
 
-ParagraphList::const_iterator
-TeXOnePar(Buffer const & buf,
-         Text const & text,
-         ParagraphList::const_iterator pit,
-         odocstream & os, TexRow & texrow,
-         OutputParams const & runparams,
-         string const & everypar = string());
-
 
 ParagraphList::const_iterator
 TeXDeeper(Buffer const & buf,
@@ -82,13 +74,12 @@ TeXDeeper(Buffer const & buf,
 
        ParagraphList const & paragraphs = text.paragraphs();
 
-       // FIXME This test should not be necessary.
-       // We should perhaps issue an error if it is.
-       Layout const & style = par->forcePlainLayout() ?
-               buf.params().documentClass().plainLayout() : par->layout();
-
        while (par != paragraphs.end() &&
-                    par->params().depth() == pit->params().depth()) {
+                                       par->params().depth() == pit->params().depth()) {
+               // FIXME This test should not be necessary.
+               // We should perhaps issue an error if it is.
+               Layout const & style = par->forcePlainLayout() ?
+                       buf.params().documentClass().plainLayout() : par->layout();
                if (style.isEnvironment()) {
                        par = TeXEnvironment(buf, text, par,
                                             os, texrow, runparams);
@@ -189,8 +180,9 @@ TeXEnvironment(Buffer const & buf,
        bool cjk_nested = false;
        if (par_language->encoding()->package() == Encoding::CJK &&
            open_encoding_ != CJK && pit->isMultiLingual(bparams)) {
-               os << "\\begin{CJK}{" << from_ascii(par_language->encoding()->latexName())
-                  << "}{" << from_ascii(bparams.fontsCJK) << "}%\n";
+               if (prev_par_language->encoding()->package() == Encoding::CJK)
+                       os << "\\begin{CJK}{" << from_ascii(par_language->encoding()->latexName())
+                          << "}{" << from_ascii(bparams.fontsCJK) << "}%\n";
                open_encoding_ = CJK;
                cjk_nested = true;
                texrow.newline();
@@ -278,28 +270,24 @@ int latexOptArgInsets(Paragraph const & par, odocstream & os,
        return lines;
 }
 
-
-namespace {
-
-ParagraphList::const_iterator
-TeXOnePar(Buffer const & buf,
+// FIXME: this should be anonymous
+ParagraphList::const_iterator TeXOnePar(Buffer const & buf,
          Text const & text,
          ParagraphList::const_iterator const pit,
          odocstream & os, TexRow & texrow,
          OutputParams const & runparams_in,
-         string const & everypar)
+         string const & everypar,
+         int start_pos, int end_pos)
 {
        LYXERR(Debug::LATEX, "TeXOnePar...     " << &*pit << " '"
                << everypar << "'");
        BufferParams const & bparams = buf.params();
        ParagraphList const & paragraphs = text.paragraphs();
 
-       ParagraphList::const_iterator priorpit = pit;
-       if (priorpit != paragraphs.begin())
-               --priorpit;
-       ParagraphList::const_iterator nextpit = pit;
-       if (nextpit != paragraphs.end())
-               ++nextpit;
+       ParagraphList::const_iterator const priorpit = 
+               pit == paragraphs.begin() ? pit : boost::prior(pit);
+       ParagraphList::const_iterator const nextpit = 
+               pit == paragraphs.end() ? pit : boost::next(pit);
 
        OutputParams runparams = runparams_in;
        runparams.isLastPar = nextpit == paragraphs.end();
@@ -315,7 +303,7 @@ TeXOnePar(Buffer const & buf,
                }
 
                /*bool need_par = */ pit->latex(bparams, outerfont,
-                       os, texrow, runparams);
+                       os, texrow, runparams, start_pos, end_pos);
                return nextpit;
        }
 
@@ -454,11 +442,8 @@ TeXOnePar(Buffer const & buf,
                        // With CJK, only add switch if we have CJK content at the beginning
                        // of the paragraph
                        if (encoding->package() != Encoding::CJK || i == 0) {
-                               OutputParams tmp_rp = runparams;
-                               runparams.moving_arg = false;
                                pair<bool, int> enc_switch = switchEncoding(os, bparams, runparams,
                                        *encoding);
-                               runparams = tmp_rp;
                                // the following is necessary after a CJK environment in a multilingual
                                // context (nesting issue).
                                if (par_language->encoding()->package() == Encoding::CJK &&
@@ -546,7 +531,7 @@ TeXOnePar(Buffer const & buf,
        // FIXME UNICODE
        os << from_utf8(everypar);
        bool need_par = pit->latex(bparams, outerfont,
-                                            os, texrow, runparams);
+                                            os, texrow, runparams, start_pos, end_pos);
 
        // Make sure that \\par is done with the font of the last
        // character if this has another size as the default.
@@ -586,14 +571,13 @@ TeXOnePar(Buffer const & buf,
        case LATEX_ENVIRONMENT: {
                // if its the last paragraph of the current environment
                // skip it otherwise fall through
-               ParagraphList::const_iterator next = nextpit;
-
-               if (next != paragraphs.end() && (next->layout() != pit->layout()
-                       || next->params().depth() != pit->params().depth()))
+               if (nextpit != paragraphs.end() && 
+                   (nextpit->layout() != pit->layout()
+                    || nextpit->params().depth() != pit->params().depth()))
                        break;
        }
 
-               // fall through possible
+       // fall through possible
        default:
                // we don't need it for the last paragraph!!!
                if (nextpit != paragraphs.end())
@@ -626,9 +610,9 @@ TeXOnePar(Buffer const & buf,
                // are we about to close the language?
                ((nextpit != paragraphs.end() &&
                  par_language->babel() !=
-                       (nextpit->getParLanguage(bparams))->babel()) ||
-                (nextpit == paragraphs.end() &&
-                 par_language->babel() != outer_language->babel()));
+                   (nextpit->getParLanguage(bparams))->babel()) ||
+                 (nextpit == paragraphs.end() &&
+                   par_language->babel() != outer_language->babel()));
 
        if (closing_rtl_ltr_environment || (nextpit == paragraphs.end()
            && par_language->babel() != outer_language->babel())) {
@@ -671,9 +655,9 @@ TeXOnePar(Buffer const & buf,
        // also if the next paragraph is a multilingual environment (because of nesting)
        if (nextpit != paragraphs.end() && open_encoding_ == CJK &&
            (nextpit->getParLanguage(bparams)->encoding()->package() != Encoding::CJK ||
-            nextpit->layout().isEnvironment() && nextpit->isMultiLingual(bparams))
-            // in environments, CJK has to be closed later (nesting!)
-            && !style.isEnvironment()) {
+            (nextpit->layout().isEnvironment() && nextpit->isMultiLingual(bparams)))
+            // inbetween environments, CJK has to be closed later (nesting!)
+            && (!style.isEnvironment() || !nextpit->layout().isEnvironment())) {
                os << "\\end{CJK}\n";
                open_encoding_ = none;
        }
@@ -724,13 +708,22 @@ TeXOnePar(Buffer const & buf,
                runparams_in.encoding = runparams.encoding;
 
 
-       // we don't need it for the last paragraph!!!
-       // Note from JMarc: we will re-add a \n explicitely in
+       // we don't need a newline for the last paragraph!!!
+       // Note from JMarc: we will re-add a \n explicitly in
        // TeXEnvironment, because it is needed in this case
        if (nextpit != paragraphs.end()) {
                Layout const & next_layout = nextpit->layout();
-               // no blank lines before environments!
-               if (!next_layout.isEnvironment() || style == next_layout) {
+               if (style == next_layout
+                   // no blank lines before environments!
+                   || !next_layout.isEnvironment()
+                   // unless there's a depth change
+                   // FIXME What we really want to do here is put every \begin and \end
+                   // tag on a new line (which was not the case with nested environments).
+                   // But in the present state of play, we don't have access to the
+                   // information whether the current TeX row is empty or not.
+                   // For some ideas about how to fix this, see this thread:
+                   // http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg145787.html
+                   || nextpit->params().depth() != pit->params().depth()) {
                        os << '\n';
                        texrow.newline();
                }
@@ -742,8 +735,6 @@ TeXOnePar(Buffer const & buf,
        return nextpit;
 }
 
-} // anon namespace
-
 
 // LaTeX all paragraphs
 void latexParagraphs(Buffer const & buf,
@@ -804,8 +795,7 @@ void latexParagraphs(Buffer const & buf,
                // FIXME This check should not be needed. We should
                // perhaps issue an error if it is.
                Layout const & layout = par->forcePlainLayout() ?
-                               tclass.plainLayout() :
-                               par->layout();
+                               tclass.plainLayout() : par->layout();
 
                if (layout.intitle) {
                        if (already_title) {
@@ -938,7 +928,7 @@ pair<bool, int> switchEncoding(odocstream & os, BufferParams const & bparams,
                                count += 7;
                        }
                        if (runparams.local_font != 0
-                           && oldEnc.package() == Encoding::CJK) {
+                           &&  oldEnc.package() == Encoding::CJK) {
                                // within insets, \inputenc switches need
                                // to be embraced within \bgroup...\egroup;
                                // else CJK fails.