+ // If there is an argument that must be output before the main tag, do it before handling the rest of the paragraph.
+ // Also tag all arguments that shouldn't go in the main content right now, so that they are never generated at the
+ // wrong place.
+ OutputParams rp = runparams;
+ for (pos_type i = initial; i < size(); ++i) {
+ if (getInset(i) && getInset(i)->lyxCode() == ARG_CODE) {
+ const InsetArgument * arg = getInset(i)->asInsetArgument();
+ if (arg->docbookargumentbeforemaintag()) {
+ auto xs_local = XMLStream(os);
+ arg->docbook(xs_local, rp);
+
+ prependedParagraphs.push_back(os.str());
+ os.str(from_ascii(""));
+
+ rp.docbook_prepended_arguments.insert(arg);
+ } else if (arg->docbookargumentaftermaintag()) {
+ rp.docbook_appended_arguments.insert(arg);
+ }
+ }
+ }
+
+ // State variables for the main loop.
+ auto xs = new XMLStream(os); // XMLStream has no copy constructor: to create a new object, the only solution
+ // is to hold a pointer to the XMLStream (xs = XMLStream(os) is not allowed once the first object is built).
+ std::vector<char_type> delayedChars; // When a font tag ends with a space, output it after the closing font tag.
+ // This requires to store delayed characters at some point.
+
+ DocBookFontState fs; // Track whether we have opened font tags
+ DocBookFontState old_fs = fs;
+
+ Layout const & style = *d->layout_;
+ FontInfo font_old = style.labeltype == LABEL_MANUAL ? style.labelfont : style.font;
+ string const default_family = buf.masterBuffer()->params().fonts_default_family;
+
+ vector<xml::FontTag> tagsToOpen;
+ vector<xml::EndFontTag> tagsToClose;