]> git.lyx.org Git - features.git/commitdiff
In multi-par sequences, check for arguments in all pars
authorJuergen Spitzmueller <spitz@lyx.org>
Sun, 23 Dec 2012 16:37:50 +0000 (17:37 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Sun, 23 Dec 2012 16:37:50 +0000 (17:37 +0100)
src/insets/InsetText.cpp
src/output_latex.cpp
src/output_latex.h

index e2d47241f1f6c1adb3748af3d0ff23ed7127a62a..181a79c4799db99739d222575d224dadf762a67d 100644 (file)
@@ -618,7 +618,7 @@ void InsetText::getOptArg(otexstream & os,
                &paragraphs()[0].getFirstFontSettings(buffer().masterBuffer()->params());
        if (isPassThru())
                runparams.pass_thru = true;
-       latexArgInsets(paragraphs()[0], os, runparams, getLayout().latexargs());
+       latexArgInsets(paragraphs(), paragraphs().begin(), os, runparams, getLayout().latexargs());
 }
 
 
index 9629a91ebffc9cb9affa3bf630c6705918d04c70..3f6b44ec3daa3e01f48cf8e933ad50b222e89f40 100644 (file)
@@ -163,9 +163,9 @@ static TeXEnvironmentData prepareEnvironment(Buffer const & buf,
        if (style.isEnvironment()) {
                os << "\\begin{" << from_ascii(style.latexname()) << '}';
                if (!style.latexargs().empty()) {
-                   OutputParams rp = runparams;
-                   rp.local_font = &pit->getFirstFontSettings(bparams);
-                   latexArgInsets(*pit, os, rp, style.latexargs());
+                       OutputParams rp = runparams;
+                       rp.local_font = &pit->getFirstFontSettings(bparams);
+                       latexArgInsets(paragraphs, pit, os, rp, style.latexargs());
                }
                if (style.latextype == LATEX_LIST_ENVIRONMENT) {
                        os << '{'
@@ -312,40 +312,10 @@ void TeXEnvironment(Buffer const & buf, Text const & text,
                LYXERR(Debug::LATEX, "TeXEnvironment for paragraph " << par_begin << " done.");
 }
 
-} // namespace anon
-
 
-void latexArgInsets(Paragraph const & par, otexstream & os,
-       OutputParams const & runparams, Layout::LaTeXArgMap const & latexargs, bool item)
+void getArgInsets(otexstream & os, OutputParams const & runparams, Layout::LaTeXArgMap const & latexargs,
+                 map<int, lyx::InsetArgument const *> ilist, vector<string> required, bool item)
 {
-       map<int, InsetArgument const *> ilist;
-       vector<string> required;
-
-       InsetList::const_iterator it = par.insetList().begin();
-       InsetList::const_iterator end = par.insetList().end();
-       for (; it != end; ++it) {
-               if (it->inset->lyxCode() == ARG_CODE) {
-                       InsetArgument const * ins =
-                               static_cast<InsetArgument const *>(it->inset);
-                       if (ins->name().empty())
-                               LYXERR0("Error: Unnamed argument inset!");
-                       else {
-                               string const name = item ? split(ins->name(), ':') : ins->name();
-                               unsigned int const nr = convert<unsigned int>(name);
-                               ilist[nr] = ins;
-                               Layout::LaTeXArgMap::const_iterator const lit =
-                                               latexargs.find(ins->name());
-                               if (lit != latexargs.end()) {
-                                       Layout::latexarg const & arg = (*lit).second;
-                                       if (!arg.requires.empty()) {
-                                               vector<string> req = getVectorFromString(arg.requires);
-                                               required.insert(required.end(), req.begin(), req.end());
-                                       }
-                               }
-                       }
-               }
-       }
-
        unsigned int const argnr = latexargs.size();
        if (argnr == 0)
                return;
@@ -411,6 +381,100 @@ void latexArgInsets(Paragraph const & par, otexstream & os,
        }
 }
 
+
+} // namespace anon
+
+
+void latexArgInsets(Paragraph const & par, otexstream & os,
+       OutputParams const & runparams, Layout::LaTeXArgMap const & latexargs, bool item)
+{
+       map<int, InsetArgument const *> ilist;
+       vector<string> required;
+
+       InsetList::const_iterator it = par.insetList().begin();
+       InsetList::const_iterator end = par.insetList().end();
+       for (; it != end; ++it) {
+               if (it->inset->lyxCode() == ARG_CODE) {
+                       InsetArgument const * ins =
+                               static_cast<InsetArgument const *>(it->inset);
+                       if (ins->name().empty())
+                               LYXERR0("Error: Unnamed argument inset!");
+                       else {
+                               string const name = item ? split(ins->name(), ':') : ins->name();
+                               unsigned int const nr = convert<unsigned int>(name);
+                               ilist[nr] = ins;
+                               Layout::LaTeXArgMap::const_iterator const lit =
+                                               latexargs.find(ins->name());
+                               if (lit != latexargs.end()) {
+                                       Layout::latexarg const & arg = (*lit).second;
+                                       if (!arg.requires.empty()) {
+                                               vector<string> req = getVectorFromString(arg.requires);
+                                               required.insert(required.end(), req.begin(), req.end());
+                                       }
+                               }
+                       }
+               }
+       }
+       getArgInsets(os, runparams, latexargs, ilist, required, item);
+}
+
+
+void latexArgInsets(ParagraphList const & pars, ParagraphList::const_iterator pit,
+       otexstream & os, OutputParams const & runparams, Layout::LaTeXArgMap const & latexargs)
+{
+       map<int, InsetArgument const *> ilist;
+       vector<string> required;
+
+       depth_type const current_depth = pit->params().depth();
+       Layout const current_layout = pit->layout();
+
+       // get the first paragraph in sequence with this layout and depth
+       pit_type offset = 0;
+       while (true) {
+               if (boost::prior(pit, offset) == pars.begin())
+                       break;
+               ParagraphList::const_iterator priorpit = boost::prior(pit, offset + 1);
+               if (priorpit->layout() == current_layout
+                   && priorpit->params().depth() == current_depth)
+                       ++offset;
+               else
+                       break;
+       }
+
+       ParagraphList::const_iterator spit = boost::prior(pit, offset);
+
+       for (; spit != pars.end(); ++spit) {
+               if (spit->layout() != current_layout)
+                       break;
+               InsetList::const_iterator it = spit->insetList().begin();
+               InsetList::const_iterator end = spit->insetList().end();
+               for (; it != end; ++it) {
+                       if (it->inset->lyxCode() == ARG_CODE) {
+                               InsetArgument const * ins =
+                                       static_cast<InsetArgument const *>(it->inset);
+                               if (ins->name().empty())
+                                       LYXERR0("Error: Unnamed argument inset!");
+                               else {
+                                       string const name = ins->name();
+                                       unsigned int const nr = convert<unsigned int>(name);
+                                       if (ilist.find(nr) == ilist.end())
+                                               ilist[nr] = ins;
+                                       Layout::LaTeXArgMap::const_iterator const lit =
+                                                       latexargs.find(ins->name());
+                                       if (lit != latexargs.end()) {
+                                               Layout::latexarg const & arg = (*lit).second;
+                                               if (!arg.requires.empty()) {
+                                                       vector<string> req = getVectorFromString(arg.requires);
+                                                       required.insert(required.end(), req.begin(), req.end());
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+       getArgInsets(os, runparams, latexargs, ilist, required, false);
+}
+
 namespace {
 
 // output the proper paragraph start according to latextype.
index 99c222018749054f124321b0893668a6c1057a12..c3cb2db78c97933f6cc930d878a5d6153e6b6d55 100644 (file)
@@ -32,14 +32,16 @@ class OutputParams;
 class TexRow;
 class Text;
 
-/// Export up to \p reqargs required arguments and
-/// \p optargs optional ones. If not enough required
-/// ones are given, we'll output: {}. The optional ones
-/// must all come first.
+/** Export optional and required arguments of the paragraph \p par.
+    Non-existing required arguments are output empty: {}.
+ */
 void latexArgInsets(Paragraph const & par,
                otexstream & os, OutputParams const & runparams,
                Layout::LaTeXArgMap const & latexargs, bool item = false);
-
+/// Same for multi-par sequences (e.g. merged environments or InsetLayouts)
+void latexArgInsets(ParagraphList const & pars, ParagraphList::const_iterator pit,
+               otexstream & os, OutputParams const & runparams,
+               Layout::LaTeXArgMap const & latexargs);
 /** Export \p paragraphs of buffer \p buf to LaTeX.
     Don't use a temporary stringstream for \p os if the final output is
     supposed to go to a file.