- // we have to provide all the optional arguments here, even though
- // the last one is the only one we care about.
- owner_->latex(bp, f, ods, tr, features.runparams(), 0, -1, true);
- docstring const d = ods.str();
- if (!d.empty()) {
- // this will have "{" at the beginning, but not at the end
- string const content = to_utf8(d);
- string const cmd = layout_->latexname();
- features.addPreambleSnippet("\\" + cmd + content + "}");
+ otexstream os(ods, texrow);
+ if (is_command) {
+ os << '\\' << from_ascii(layout_->latexname());
+ // we have to provide all the optional arguments here, even though
+ // the last one is the only one we care about.
+ // Separate handling of optional argument inset.
+ if (layout_->optargs != 0 || layout_->reqargs != 0)
+ latexArgInsets(*owner_, os, features.runparams(),
+ layout_->reqargs, layout_->optargs);
+ else
+ os << from_ascii(layout_->latexparam());
+ }
+ docstring::size_type const length = ods.str().length();
+ // this will output "{" at the beginning, but not at the end
+ owner_->latex(bp, f, os, features.runparams(), 0, -1, true);
+ if (ods.str().length() > length) {
+ if (is_command)
+ ods << '}';
+ string const snippet = to_utf8(ods.str());
+ features.addPreambleSnippet(snippet);