+ if (runparams.for_search) {
+ // Mark end of arguments for findadv() only
+ os << "\\endarguments{}";
+ }
+}
+
+
+} // namespace
+
+
+void pushLanguageName(string const & lang_name, bool localswitch)
+{
+ OutputState * state = getOutputState();
+
+ int nest_level = localswitch ? -state->nest_level_ : state->nest_level_;
+ state->lang_switch_depth_.push(nest_level);
+ state->open_polyglossia_lang_.push(lang_name);
+}
+
+
+void popLanguageName()
+{
+ OutputState * state = getOutputState();
+
+ state->lang_switch_depth_.pop();
+ state->open_polyglossia_lang_.pop();
+}
+
+
+string const & openLanguageName()
+{
+ OutputState * state = getOutputState();
+
+ return openLanguageName(state);
+}
+
+
+namespace {
+
+void addArgInsets(Paragraph const & par, string const & prefix,
+ Layout::LaTeXArgMap const & latexargs,
+ map<int, InsetArgument const *> & ilist,
+ vector<string> & required)
+{
+ for (auto const & table : par.insetList()) {
+ InsetArgument const * arg = table.inset->asInsetArgument();
+ if (!arg)
+ continue;
+ if (arg->name().empty()) {
+ LYXERR0("Error: Unnamed argument inset!");
+ continue;
+ }
+ 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));
+ }
+ }
+}
+
+} // 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);