]> git.lyx.org Git - lyx.git/blobdiff - src/output_latex.C
minimal effort implementation of:
[lyx.git] / src / output_latex.C
index 31a8416d46052a533e5a0fa5678bf13f3da346e5..c945e19c2d08ff95c3e435f681aadef394a93366 100644 (file)
 #include "encoding.h"
 #include "language.h"
 #include "lyxrc.h"
+#include "outputparams.h"
 #include "paragraph.h"
 #include "paragraph_funcs.h"
 #include "ParagraphParameters.h"
 #include "texrow.h"
 #include "vspace.h"
 
+#include "insets/insetbibitem.h"
 #include "insets/insetoptarg.h"
 
 #include "support/lstrings.h"
 
-#ifdef HAVE_LOCALE
-#endif
-
 using lyx::support::subst;
 
 using std::endl;
 using std::ostream;
 using std::string;
 
-extern string bibitemWidest(Buffer const &);
-
 
 namespace {
 
@@ -78,7 +75,7 @@ TeXDeeper(Buffer const & buf,
                                             os, texrow, runparams);
                }
        }
-       lyxerr[Debug::LATEX] << "TeXDeeper...done " << &*par << endl;
+       lyxerr[Debug::LATEX] << "TeXDeeper...done " << endl;
 
        return par;
 }
@@ -189,23 +186,28 @@ TeXEnvironment(Buffer const & buf,
                texrow.newline();
        }
 
-       lyxerr[Debug::LATEX] << "TeXEnvironment...done " << &*par << endl;
-       return par;  // ale970302
+       if (par != paragraphs.end() && lyxerr.debugging(Debug::LATEX))
+               lyxerr << "TeXEnvironment...done " << &*par << endl;
+       return par;
 }
 
 
-InsetOptArg * optArgInset(Paragraph const & par)
+int latexOptArgInsets(Buffer const & buf, Paragraph const & par,
+                     ostream & os, OutputParams const & runparams, int number)
 {
-       // Find the entry.
+       int lines = 0;
+
        InsetList::const_iterator it = par.insetlist.begin();
        InsetList::const_iterator end = par.insetlist.end();
-       for (; it != end; ++it) {
-               InsetBase * ins = it->inset;
-               if (ins->lyxCode() == InsetBase::OPTARG_CODE) {
-                       return static_cast<InsetOptArg *>(ins);
+       for (; it != end && number > 0 ; ++it) {
+               if (it->inset->lyxCode() == InsetBase::OPTARG_CODE) {
+                       InsetOptArg * ins =
+                               static_cast<InsetOptArg *>(it->inset);
+                       lines += ins->latexOptional(buf, os, runparams);
+                       --number;
                }
        }
-       return 0;
+       return lines;
 }
 
 
@@ -214,7 +216,7 @@ TeXOnePar(Buffer const & buf,
          ParagraphList const & paragraphs,
          ParagraphList::const_iterator pit,
          ostream & os, TexRow & texrow,
-         OutputParams const & runparams,
+         OutputParams const & runparams_in,
          string const & everypar)
 {
        lyxerr[Debug::LATEX] << "TeXOnePar...     " << &*pit << " '"
@@ -230,6 +232,9 @@ TeXOnePar(Buffer const & buf,
        else
                style = bparams.getLyXTextClass().defaultLayout();
 
+       OutputParams runparams = runparams_in;
+       runparams.moving_arg |= style->needprotect;
+
        Language const * language = pit->getParLanguage(bparams);
        Language const * doc_language = bparams.language;
        Language const * previous_language =
@@ -267,7 +272,7 @@ TeXOnePar(Buffer const & buf,
        if (bparams.inputenc == "auto" &&
            language->encoding() != previous_language->encoding()) {
                os << "\\inputencoding{"
-                  << language->encoding()->LatexName()
+                  << language->encoding()->latexName()
                   << "}\n";
                texrow.newline();
        }
@@ -304,10 +309,13 @@ TeXOnePar(Buffer const & buf,
                os << '\\' << style->latexname();
 
                // Separate handling of optional argument inset.
-               if (style->optionalargs == 1) {
-                       InsetOptArg * it = optArgInset(*pit);
-                       if (it)
-                               it->latexOptional(buf, os, runparams);
+               if (style->optionalargs > 0) {
+                       int ret = latexOptArgInsets(buf, *pit, os, runparams,
+                                                   style->optionalargs);
+                       while (ret > 0) {
+                               texrow.newline();
+                               --ret;
+                       }
                }
                else
                        os << style->latexparam();
@@ -325,7 +333,7 @@ TeXOnePar(Buffer const & buf,
 
        os << everypar;
        bool need_par = pit->simpleTeXOnePar(buf, bparams,
-                       outerFont(pit - paragraphs.begin(), paragraphs),
+                                            outerFont(std::distance(paragraphs.begin(), pit), paragraphs),
                                             os, texrow, runparams);
 
        // Make sure that \\par is done with the font of the last
@@ -338,8 +346,8 @@ TeXOnePar(Buffer const & buf,
        // We do not need to use to change the font for the last paragraph
        // or for a command.
        LyXFont const outerfont =
-                       outerFont(pit - paragraphs.begin(),
-paragraphs);
+               outerFont(std::distance(paragraphs.begin(), pit),
+                         paragraphs);
 
        LyXFont const font =
                (pit->empty()
@@ -405,7 +413,7 @@ paragraphs);
                }
        }
 
-       if (boost::next(pit) == const_cast<ParagraphList&>(paragraphs).end()
+       if (boost::next(pit) == paragraphs.end()
            && language->babel() != doc_language->babel()) {
                // Since \selectlanguage write the language to the aux file,
                // we need to reset the language at the end of footnote or
@@ -432,7 +440,9 @@ paragraphs);
                texrow.newline();
        }
 
-       lyxerr[Debug::LATEX] << "TeXOnePar...done " << &*boost::next(pit) << endl;
+       if (boost::next(pit) != paragraphs.end() &&
+           lyxerr.debugging(Debug::LATEX))
+               lyxerr << "TeXOnePar...done " << &*boost::next(pit) << endl;
        return ++pit;
 }
 
@@ -453,8 +463,20 @@ void latexParagraphs(Buffer const & buf,
        ParagraphList::const_iterator par = paragraphs.begin();
        ParagraphList::const_iterator endpar = paragraphs.end();
 
+       BOOST_ASSERT(runparams.par_begin <= runparams.par_end);
+       // if only part of the paragraphs will be outputed
+       if (runparams.par_begin !=  runparams.par_end) {
+               par = boost::next(paragraphs.begin(), runparams.par_begin);
+               endpar = boost::next(paragraphs.begin(), runparams.par_end);
+               // runparams will be passed to nested paragraphs, so
+               // we have to reset the range parameters.
+               const_cast<OutputParams&>(runparams).par_begin = 0;
+               const_cast<OutputParams&>(runparams).par_end = 0;
+       }
+
        // if only_body
        while (par != endpar) {
+               ParagraphList::const_iterator lastpar = par;
                // well we have to check if we are in an inset with unlimited
                // length (all in one row) if that is true then we don't allow
                // any special options in the paragraph and also we don't allow
@@ -492,7 +514,7 @@ void latexParagraphs(Buffer const & buf,
 
                        if (layout->is_environment) {
                                par = TeXOnePar(buf, paragraphs, par, os, texrow,
-                                               runparams, everypar);
+                                               runparams, everypar);
                        } else if (layout->isEnvironment() ||
                                !par->params().leftIndent().zero())
                        {
@@ -500,12 +522,14 @@ void latexParagraphs(Buffer const & buf,
                                                     texrow, runparams);
                        } else {
                                par = TeXOnePar(buf, paragraphs, par, os, texrow,
-                                               runparams, everypar);
+                                               runparams, everypar);
                        }
                } else {
                        par = TeXOnePar(buf, paragraphs, par, os, texrow,
-                                       runparams, everypar);
+                                       runparams, everypar);
                }
+               if (std::distance(lastpar, par) >= std::distance(lastpar, endpar))
+                       break;
        }
        // It might be that we only have a title in this document
        if (was_title && !already_title) {