+ // Output the MathML subtree.
+ // TeX transcription. Avoid MTag/ETag so that there are no extraneous spaces.
+ ms << "<" << from_ascii("alt") << " role='tex'" << ">";
+ // Workaround for db2latex: db2latex always includes equations with
+ // \ensuremath{} or \begin{display}\end{display}
+ // so we strip LyX' math environment
+ odocstringstream ls;
+ otexstream ols(ls);
+ TeXMathStream wi(ols, false, false, TeXMathStream::wsDefault, runparams.encoding);
+ InsetMathGrid::write(wi);
+ ms << from_utf8(subst(subst(to_utf8(ls.str()), "&", "&"), "<", "<"));
+ ms << "</" << from_ascii("alt") << ">";
+
+ // Actual transformation of the formula into MathML. This translation may fail (for example, due to custom macros).
+ // The new output stream is required to deal with the errors: first write completely the formula into this
+ // temporary stream; then, if it is possible without error, then copy it back to the "real" stream. Otherwise,
+ // some incomplete tags might be put into the real stream.
+ try {
+ // First, generate the MathML expression. If there is an error in the generation, this block is not fully
+ // executed, and the formula is not output to the DocBook stream.
+ odocstringstream ostmp;
+ MathMLStream mstmp(ostmp, ms.xmlns());
+ mathmlize(mstmp);
+
+ // Choose the display style for the formula, to be output as an attribute near the formula root.
+ std::string mathmlAttr;
+ if (getType() == hullSimple)
+ mathmlAttr = "display=\"inline\"";
+ else
+ mathmlAttr = "display=\"block\"";