+ string const name = prefix.empty() ?
+ arg->name() : split(arg->name(), ':');
+ // why converting into an integer?
+ unsigned int const nr = convert<unsigned int>(name);
+ if (ilist.find(nr) == ilist.end())
+ ilist[nr] = arg;
+ Layout::LaTeXArgMap::const_iterator const lit =
+ latexargs.find(arg->name());
+ if (lit != latexargs.end()) {
+ Layout::latexarg const & larg = lit->second;
+ vector<string> req = getVectorFromString(larg.requires);
+ move(req.begin(), req.end(), back_inserter(required));
+ }
+ }
+}
+
+} // anon namespace
+
+
+void latexArgInsets(Paragraph const & par, otexstream & os,
+ OutputParams const & runparams,
+ Layout::LaTeXArgMap const & latexargs,
+ string const & prefix)
+{
+ map<int, InsetArgument const *> ilist;
+ vector<string> required;
+ addArgInsets(par, prefix, latexargs, ilist, required);
+ 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,
+ string const & prefix)
+{
+ 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 (lyx::prev(pit, offset) == pars.begin())
+ break;
+ ParagraphList::const_iterator priorpit = lyx::prev(pit, offset + 1);
+ if (priorpit->layout() == current_layout
+ && priorpit->params().depth() == current_depth)
+ ++offset;
+ else
+ break;
+ }
+
+ ParagraphList::const_iterator spit = lyx::prev(pit, offset);
+
+ for (; spit != pars.end(); ++spit) {
+ if (spit->layout() != current_layout ||
+ spit->params().depth() < current_depth)
+ break;
+ if (spit->params().depth() > current_depth)
+ continue;
+ addArgInsets(*spit, prefix, latexargs, ilist, required);
+ }
+ getArgInsets(os, runparams, latexargs, ilist, required, prefix);
+}
+
+
+void latexArgInsetsForParent(ParagraphList const & pars, otexstream & os,
+ OutputParams const & runparams,
+ Layout::LaTeXArgMap const & latexargs,
+ string const & prefix)
+{
+ map<int, InsetArgument const *> ilist;
+ vector<string> required;
+
+ for (Paragraph const & par : pars) {
+ if (par.layout().hasArgs())
+ // The InsetArguments inside this paragraph refer to this paragraph
+ continue;
+ addArgInsets(par, prefix, latexargs, ilist, required);
+ }
+ getArgInsets(os, runparams, latexargs, ilist, required, prefix);
+}
+
+
+namespace {
+
+// output the proper paragraph start according to latextype.
+void parStartCommand(Paragraph const & par, otexstream & os,
+ OutputParams const & runparams, Layout const & style)
+{
+ switch (style.latextype) {
+ case LATEX_COMMAND:
+ os << '\\' << from_ascii(style.latexname());
+
+ // Command arguments
+ if (!style.latexargs().empty())
+ latexArgInsets(par, os, runparams, style.latexargs());
+ os << from_ascii(style.latexparam());
+ break;
+ case LATEX_ITEM_ENVIRONMENT:
+ case LATEX_LIST_ENVIRONMENT:
+ os << "\\" + style.itemcommand();
+ // Item arguments
+ if (!style.itemargs().empty())
+ latexArgInsets(par, os, runparams, style.itemargs(), "item:");
+ os << " ";
+ break;
+ case LATEX_BIB_ENVIRONMENT:
+ // ignore this, the inset will write itself
+ break;
+ default:
+ break;