From 3934f4a36f0402612206cfc0abe0b0b62166214b Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Sun, 23 Dec 2012 17:37:50 +0100 Subject: [PATCH] In multi-par sequences, check for arguments in all pars --- src/insets/InsetText.cpp | 2 +- src/output_latex.cpp | 134 +++++++++++++++++++++++++++++---------- src/output_latex.h | 12 ++-- 3 files changed, 107 insertions(+), 41 deletions(-) diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index e2d47241f1..181a79c479 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -618,7 +618,7 @@ void InsetText::getOptArg(otexstream & os, ¶graphs()[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()); } diff --git a/src/output_latex.cpp b/src/output_latex.cpp index 9629a91ebf..3f6b44ec3d 100644 --- a/src/output_latex.cpp +++ b/src/output_latex.cpp @@ -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 ilist, vector required, bool item) { - map ilist; - vector 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(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(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 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 ilist; + vector 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(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(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 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 ilist; + vector 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(it->inset); + if (ins->name().empty()) + LYXERR0("Error: Unnamed argument inset!"); + else { + string const name = ins->name(); + unsigned int const nr = convert(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 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. diff --git a/src/output_latex.h b/src/output_latex.h index 99c2220187..c3cb2db78c 100644 --- a/src/output_latex.h +++ b/src/output_latex.h @@ -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. -- 2.39.2