}
-Layout const * findLayoutWithoutModule(TextClass const & textclass,
- string const & name, bool command)
+Layout const * findLayoutWithoutModule(TextClass const & tc,
+ string const & name, bool command,
+ string const & latexparam)
{
- DocumentClass::const_iterator it = textclass.begin();
- DocumentClass::const_iterator en = textclass.end();
- for (; it != en; ++it) {
- if (it->latexname() == name &&
- ((command && it->isCommand()) || (!command && it->isEnvironment())))
- return &*it;
+ for (auto const & lay : tc) {
+ if (lay.latexname() == name &&
+ (latexparam.empty() ||
+ (!lay.latexparam().empty() && suffixIs(latexparam, lay.latexparam()))) &&
+ ((command && lay.isCommand()) || (!command && lay.isEnvironment())))
+ return &lay;
}
return 0;
}
-InsetLayout const * findInsetLayoutWithoutModule(TextClass const & textclass,
- string const & name, bool command)
+InsetLayout const * findInsetLayoutWithoutModule(TextClass const & tc,
+ string const & name, bool command,
+ string const & latexparam)
{
- DocumentClass::InsetLayouts::const_iterator it = textclass.insetLayouts().begin();
- DocumentClass::InsetLayouts::const_iterator en = textclass.insetLayouts().end();
- for (; it != en; ++it) {
- if (it->second.latexname() == name &&
- ((command && it->second.latextype() == InsetLayout::COMMAND) ||
- (!command && it->second.latextype() == InsetLayout::ENVIRONMENT)))
- return &(it->second);
+ for (auto const & ilay : tc.insetLayouts()) {
+ if (ilay.second.latexname() == name &&
+ (latexparam.empty() ||
+ (!ilay.second.latexparam().empty() && suffixIs(latexparam, ilay.second.latexparam()))) &&
+ ((command && ilay.second.latextype() == InsetLayout::COMMAND) ||
+ (!command && ilay.second.latextype() == InsetLayout::ENVIRONMENT)))
+ return &(ilay.second);
}
return 0;
}
if (layout)
output_arguments(os, p, outer, false, string(), newcontext,
layout->latexargs());
+ // If we have a latex param, we eat it here.
+ if (!context.latexparam.empty()) {
+ ostringstream oss;
+ Context dummy(true, context.textclass);
+ parse_text(p, oss, FLAG_RDELIM, outer, dummy,
+ string(1, context.latexparam.back()));
+ }
parse_text(p, os, flags, outer, newcontext, rdelim);
if (layout)
output_arguments(os, p, outer, false, "post", newcontext,
}
-Layout const * findLayout(TextClass const & textclass, string const & name, bool command)
+Layout const * findLayout(TextClass const & textclass, string const & name, bool command,
+ string const & latexparam = string())
{
- Layout const * layout = findLayoutWithoutModule(textclass, name, command);
+ Layout const * layout = findLayoutWithoutModule(textclass, name, command, latexparam);
if (layout)
return layout;
if (checkModule(name, command))
- return findLayoutWithoutModule(textclass, name, command);
+ return findLayoutWithoutModule(textclass, name, command, latexparam);
return layout;
}
-InsetLayout const * findInsetLayout(TextClass const & textclass, string const & name, bool command)
+InsetLayout const * findInsetLayout(TextClass const & textclass, string const & name, bool command,
+ string const & latexparam = string())
{
- InsetLayout const * insetlayout = findInsetLayoutWithoutModule(textclass, name, command);
+ InsetLayout const * insetlayout =
+ findInsetLayoutWithoutModule(textclass, name, command, latexparam);
if (insetlayout)
return insetlayout;
if (checkModule(name, command))
- return findInsetLayoutWithoutModule(textclass, name, command);
+ return findInsetLayoutWithoutModule(textclass, name, command, latexparam);
return insetlayout;
}
context.check_deeper(os);
output_arguments(os, p, outer, true, string(), context,
context.layout->latexargs());
+ // If we have a latex param, we eat it here.
+ if (!parent_context.latexparam.empty()) {
+ ostringstream oss;
+ Context dummy(true, parent_context.textclass);
+ parse_text(p, oss, FLAG_RDELIM, outer, dummy,
+ string(1, parent_context.latexparam.back()));
+ }
parse_text(p, os, FLAG_ITEM, outer, context);
output_arguments(os, p, outer, false, "post", context,
context.layout->postcommandargs());
continue;
}
+ // Before we look for the layout name with star and alone below, we check the layouts including
+ // the LateXParam, which might be one or several options or a star.
+ // The single '=' is meant here.
+ if (context.new_layout_allowed &&
+ (newlayout = findLayout(context.textclass, t.cs(), true, p.getCommandLatexParam()))) {
+ // store the latexparam here. This is eaten in output_command_layout
+ context.latexparam = newlayout->latexparam();
+ // write the layout
+ output_command_layout(os, p, outer, context, newlayout);
+ p.skip_spaces();
+ if (!preamble.titleLayoutFound())
+ preamble.titleLayoutFound(newlayout->intitle);
+ set<string> const & req = newlayout->requires();
+ for (set<string>::const_iterator it = req.begin(); it != req.end(); ++it)
+ preamble.registerAutomaticallyLoadedPackage(*it);
+ continue;
+ }
+
+
// Starred section headings
// Must attempt to parse "Section*" before "Section".
if ((p.next_token().asInput() == "*") &&
continue;
}
+ // Before we look for the layout name alone below, we check the layouts including the LateXParam, which
+ // might be one or several options or a star.
+ // The single '=' is meant here.
+ if ((newinsetlayout = findInsetLayout(context.textclass, starredname, true, p.getCommandLatexParam()))) {
+ if (starred)
+ p.get_token();
+ p.skip_spaces();
+ context.check_layout(os);
+ // store the latexparam here. This is eaten in parse_text_in_inset
+ context.latexparam = newinsetlayout->latexparam();
+ docstring name = newinsetlayout->name();
+ bool const caption = name.find(from_ascii("Caption:")) == 0;
+ if (caption) {
+ // Already done for floating minted listings.
+ if (minted_float.empty()) {
+ begin_inset(os, "Caption ");
+ os << to_utf8(name.substr(8)) << '\n';
+ }
+ } else {
+ // FIXME: what do we do if the prefix is not Flex: ?
+ if (prefixIs(name, from_ascii("Flex:")))
+ name.erase(0, 5);
+ begin_inset(os, "Flex ");
+ os << to_utf8(name) << '\n'
+ << "status collapsed\n";
+ }
+ if (!minted_float.empty()) {
+ parse_text_snippet(p, os, FLAG_ITEM, false, context);
+ } else if (newinsetlayout->isPassThru()) {
+ // set catcodes to verbatim early, just in case.
+ p.setCatcodes(VERBATIM_CATCODES);
+ string delim = p.get_token().asInput();
+ if (delim != "{")
+ cerr << "Warning: bad delimiter for command " << t.asInput() << endl;
+ //FIXME: handle error condition
+ string const arg = p.verbatimStuff("}").second;
+ Context newcontext(true, context.textclass);
+ if (newinsetlayout->forcePlainLayout())
+ newcontext.layout = &context.textclass.plainLayout();
+ output_ert(os, arg, newcontext);
+ } else
+ parse_text_in_inset(p, os, FLAG_ITEM, false, context, newinsetlayout);
+ if (caption)
+ p.skip_spaces();
+ // Minted caption insets are not closed here because
+ // we collect everything into the caption.
+ if (minted_float.empty())
+ end_inset(os);
+ continue;
+ }
+
// The single '=' is meant here.
if ((newinsetlayout = findInsetLayout(context.textclass, starredname, true))) {
if (starred)