]> git.lyx.org Git - lyx.git/blobdiff - src/output_latex.cpp
Natbib authoryear uses (Ref1; Ref2) by default.
[lyx.git] / src / output_latex.cpp
index 3f6b44ec3daa3e01f48cf8e933ad50b222e89f40..697a3b5028d3cb97a2263cb0e04f588c4ce6d033 100644 (file)
@@ -33,6 +33,7 @@
 #include "support/convert.h"
 #include "support/debug.h"
 #include "support/lstrings.h"
+#include "support/textutils.h"
 
 #include <algorithm>
 #include <boost/next_prior.hpp>
@@ -314,7 +315,7 @@ void TeXEnvironment(Buffer const & buf, Text const & text,
 
 
 void getArgInsets(otexstream & os, OutputParams const & runparams, Layout::LaTeXArgMap const & latexargs,
-                 map<int, lyx::InsetArgument const *> ilist, vector<string> required, bool item)
+                 map<int, lyx::InsetArgument const *> ilist, vector<string> required, string const & prefix)
 {
        unsigned int const argnr = latexargs.size();
        if (argnr == 0)
@@ -347,25 +348,27 @@ void getArgInsets(otexstream & os, OutputParams const & runparams, Layout::LaTeX
                        Layout::LaTeXArgMap::const_iterator lait = latexargs.begin();
                        Layout::LaTeXArgMap::const_iterator const laend = latexargs.end();
                        for (; lait != laend; ++lait) {
-                               string const name = item ? "item:" + convert<string>(i) : convert<string>(i);
+                               string const name = prefix + convert<string>(i);
                                if ((*lait).first == name) {
                                        Layout::latexarg arg = (*lait).second;
+                                       docstring preset = arg.presetarg;
+                                       if (!arg.defaultarg.empty()) {
+                                               if (!preset.empty())
+                                                       preset += ",";
+                                               preset += arg.defaultarg;
+                                       }
                                        if (arg.mandatory) {
                                                docstring ldelim = arg.ldelim.empty() ?
                                                                from_ascii("{") : arg.ldelim;
                                                docstring rdelim = arg.rdelim.empty() ?
                                                                from_ascii("}") : arg.rdelim;
-                                               os << ldelim << arg.presetarg << rdelim;
-                                       } else if (!arg.presetarg.empty()) {
-                                               docstring ldelim = arg.mandatory ?
-                                                               from_ascii("{") : from_ascii("[");
-                                               docstring rdelim = arg.mandatory ?
-                                                               from_ascii("}") : from_ascii("]");
-                                               if (!arg.ldelim.empty())
-                                                       ldelim = arg.ldelim;
-                                               if (!arg.rdelim.empty())
-                                                       rdelim = arg.rdelim;
-                                               os << ldelim << arg.presetarg << rdelim;
+                                               os << ldelim << preset << rdelim;
+                                       } else if (!preset.empty()) {
+                                               docstring ldelim = arg.ldelim.empty() ?
+                                                               from_ascii("[") : arg.ldelim;
+                                               docstring rdelim = arg.rdelim.empty() ?
+                                                               from_ascii("]") : arg.rdelim;
+                                               os << ldelim << preset << rdelim;
                                        } else if (find(required.begin(), required.end(),
                                                   (*lait).first) != required.end()) {
                                                docstring ldelim = arg.ldelim.empty() ?
@@ -386,7 +389,7 @@ void getArgInsets(otexstream & os, OutputParams const & runparams, Layout::LaTeX
 
 
 void latexArgInsets(Paragraph const & par, otexstream & os,
-       OutputParams const & runparams, Layout::LaTeXArgMap const & latexargs, bool item)
+       OutputParams const & runparams, Layout::LaTeXArgMap const & latexargs, string const & prefix)
 {
        map<int, InsetArgument const *> ilist;
        vector<string> required;
@@ -400,7 +403,7 @@ void latexArgInsets(Paragraph const & par, otexstream & os,
                        if (ins->name().empty())
                                LYXERR0("Error: Unnamed argument inset!");
                        else {
-                               string const name = item ? split(ins->name(), ':') : ins->name();
+                               string const name = prefix.empty() ? ins->name() : split(ins->name(), ':');
                                unsigned int const nr = convert<unsigned int>(name);
                                ilist[nr] = ins;
                                Layout::LaTeXArgMap::const_iterator const lit =
@@ -415,12 +418,13 @@ void latexArgInsets(Paragraph const & par, otexstream & os,
                        }
                }
        }
-       getArgInsets(os, runparams, latexargs, ilist, required, item);
+       getArgInsets(os, runparams, latexargs, ilist, required, prefix);
 }
 
 
 void latexArgInsets(ParagraphList const & pars, ParagraphList::const_iterator pit,
-       otexstream & os, OutputParams const & runparams, Layout::LaTeXArgMap const & latexargs)
+       otexstream & os, OutputParams const & runparams, Layout::LaTeXArgMap const & latexargs,
+       string const & prefix)
 {
        map<int, InsetArgument const *> ilist;
        vector<string> required;
@@ -444,8 +448,10 @@ void latexArgInsets(ParagraphList const & pars, ParagraphList::const_iterator pi
        ParagraphList::const_iterator spit = boost::prior(pit, offset);
 
        for (; spit != pars.end(); ++spit) {
-               if (spit->layout() != current_layout)
+               if (spit->layout() != current_layout || spit->params().depth() < current_depth)
                        break;
+               if (spit->params().depth() > current_depth)
+                       continue;
                InsetList::const_iterator it = spit->insetList().begin();
                InsetList::const_iterator end = spit->insetList().end();
                for (; it != end; ++it) {
@@ -455,7 +461,7 @@ void latexArgInsets(ParagraphList const & pars, ParagraphList::const_iterator pi
                                if (ins->name().empty())
                                        LYXERR0("Error: Unnamed argument inset!");
                                else {
-                                       string const name = ins->name();
+                                       string const name = prefix.empty() ? ins->name() : split(ins->name(), ':');
                                        unsigned int const nr = convert<unsigned int>(name);
                                        if (ilist.find(nr) == ilist.end())
                                                ilist[nr] = ins;
@@ -472,7 +478,7 @@ void latexArgInsets(ParagraphList const & pars, ParagraphList::const_iterator pi
                        }
                }
        }
-       getArgInsets(os, runparams, latexargs, ilist, required, false);
+       getArgInsets(os, runparams, latexargs, ilist, required, prefix);
 }
 
 namespace {
@@ -495,7 +501,7 @@ void parStartCommand(Paragraph const & par, otexstream & os,
                os << "\\" + style.itemcommand();
                // Item arguments
                if (!style.itemargs().empty())
-                       latexArgInsets(par, os, runparams, style.itemargs(), true);
+                       latexArgInsets(par, os, runparams, style.itemargs(), "item:");
                os << " ";
                break;
        case LATEX_BIB_ENVIRONMENT:
@@ -581,7 +587,7 @@ void TeXOnePar(Buffer const & buf,
                        os << '\n';
                if (!style.parbreak_is_newline) {
                        os << '\n';
-               } else if (nextpar) {
+               } else if (nextpar && !style.isEnvironment()) {
                        Layout const nextstyle = text.inset().forcePlainLayout()
                                ? bparams.documentClass().plainLayout()
                                : nextpar->layout();
@@ -741,7 +747,7 @@ void TeXOnePar(Buffer const & buf,
                                par.getFontSettings(bparams, i).language()->encoding();
                        if (encoding->package() != Encoding::CJK
                                && runparams.encoding->package() == Encoding::inputenc
-                               && c < 0x80)
+                               && isASCII(c))
                                continue;
                        if (par.isInset(i))
                                break;
@@ -835,6 +841,8 @@ void TeXOnePar(Buffer const & buf,
                os << "\\" << from_ascii(font.latexSize()) << " \\par}";
        } else if (is_command) {
                os << '}';
+               if (!style.postcommandargs().empty())
+                       latexArgInsets(par, os, runparams, style.postcommandargs(), "post:");
                if (runparams.encoding != prev_encoding) {
                        runparams.encoding = prev_encoding;
                        if (!runparams.isFullUnicode())
@@ -1033,6 +1041,9 @@ void latexParagraphs(Buffer const & buf,
                     OutputParams const & runparams,
                     string const & everypar)
 {
+       LASSERT(runparams.par_begin <= runparams.par_end,
+               { os << "% LaTeX Output Error\n"; return; } );
+
        BufferParams const & bparams = buf.params();
 
        bool const maintext = text.isMainText();
@@ -1070,7 +1081,6 @@ void latexParagraphs(Buffer const & buf,
        }
 
        ParagraphList const & paragraphs = text.paragraphs();
-       LASSERT(runparams.par_begin <= runparams.par_end, /**/);
 
        if (runparams.par_begin == runparams.par_end) {
                // The full doc will be exported but it is easier to just rely on