+} // 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:
+ if (par.needsCProtection(runparams.moving_arg)) {
+ if (contains(runparams.active_chars, '^'))
+ // cprotect relies on ^ being on catcode 7
+ os << "\\begingroup\\catcode`\\^=7";
+ os << "\\cprotect";
+ }
+ os << '\\' << from_ascii(style.latexname());