DocBook: improve equation formatting (new lines for block equations).

This commit is contained in:
Thibaut Cuvelier 2020-08-29 19:05:59 +02:00
parent 97cfabb883
commit 39ad6e84f0
5 changed files with 24 additions and 15 deletions

View File

@ -185,7 +185,7 @@ noprefix "false"
\begin_layout Standard
Also, a formula with an user-defined macro that outputs well in LaTeX but
cannot in MathML (hence replaced by picture):
cannot in MathML:
\begin_inset Formula $\testmacro$
\end_inset

View File

@ -30,7 +30,7 @@
</inlineequation>. </para>
</blockquote>
<para>Now, we're outside quotes.</para>
<para><informalequation>
<informalequation>
<alt role='tex'>Formula!</alt>
<m:math>
@ -39,7 +39,8 @@
</m:mrow>
</m:mrow>
</m:math>
</informalequation><informalequation xml:id="eq.EQ.">
</informalequation>
<informalequation xml:id="eq.EQ.">
<alt role='tex'>\text{I am a formula with a ref.}\label{eq:EQ.}</alt>
<m:math>
@ -50,9 +51,9 @@
</m:mstyle>
</m:mrow>
</m:math>
</informalequation></para>
</informalequation>
<para>See <xref linkend="sec.Sec-2kqgsdiflhqsdlifgjuzer-povtuizmvnuer-t-vmsrmfli--uh--a--rtpfuo----rtpc.m-ca-rgifzapeu-tvgz" />.</para>
<para>Also, a formula with an user-defined macro that outputs well in LaTeX but cannot in MathML (hence replaced by picture): <inlineequation>
<para>Also, a formula with an user-defined macro that outputs well in LaTeX but cannot in MathML: <inlineequation>
<alt role='tex'>\testmacro</alt>
<mathphrase>MathML export failed. Please report this as a bug.</mathphrase>
</inlineequation>. </para>

View File

@ -3349,7 +3349,8 @@ std::vector<docstring> Paragraph::simpleDocBookOnePar(Buffer const & buf,
std::vector<docstring> generatedParagraphs;
odocstringstream os;
auto * xs = new XMLStream(os);
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).
// Parsing main loop.
for (pos_type i = initial; i < size(); ++i) {
@ -3361,7 +3362,6 @@ std::vector<docstring> Paragraph::simpleDocBookOnePar(Buffer const & buf,
if (getInset(i) != nullptr && getInset(i)->lyxCode() == NEWLINE_CODE) {
generatedParagraphs.push_back(os.str());
os = odocstringstream();
// XMLStream has no copy constructor.
delete xs;
xs = new XMLStream(os);
}

View File

@ -2420,10 +2420,16 @@ void InsetMathHull::docbook(XMLStream & xs, OutputParams const & runparams) cons
docstring name;
if (getType() == hullSimple)
name = from_ascii("inlineequation");
else
else {
// This is a block equation, always have <informalequation> on its own line.
if (!xs.isLastTagCR())
xs << xml::CR();
name = from_ascii("informalequation");
}
// DocBook also has <equation>, but it comes with a title.
// TODO: recognise \tag from amsmath?
docstring attr;
for (row_type i = 0; i < nrows(); ++i) {

View File

@ -446,10 +446,16 @@ void makeParagraph(
special_case = true;
}
size_t nInsets = std::distance(par->insetList().begin(), par->insetList().end());
// Plain layouts must be ignored.
if (!special_case && buf.params().documentClass().isPlainLayout(par->layout()) && !runparams.docbook_force_pars)
special_case = true;
// TODO: Could get rid of this with a DocBook equivalent to htmlisblock?
special_case |= buf.params().documentClass().isPlainLayout(par->layout()) && !runparams.docbook_force_pars;
// Equations do not deserve their own paragraph (DocBook allows them outside paragraphs).
special_case |= nInsets == par->size() && std::all_of(par->insetList().begin(), par->insetList().end(), [](InsetList::Element inset) {
return inset.inset && inset.inset->asInsetMath();
});
// TODO: Could get rid of this with a DocBook equivalent to htmlisblock? Not for all cases, unfortunately... See above for those that have been determined not to be allowable for this potential refactoring.
if (!special_case && par->size() == 1 && par->getInset(0)) {
Inset const * firstInset = par->getInset(0);
@ -460,10 +466,6 @@ void makeParagraph(
if (!special_case && firstInset->asInsetCommand())
special_case = firstInset->asInsetCommand()->params().getCmdName() == "bibtex";
// Equations do not deserve their own paragraph (DocBook allows them outside paragraphs).
if (!special_case && firstInset->asInsetMath())
special_case = true;
// ERTs are in comments, not paragraphs.
if (!special_case && firstInset->lyxCode() == lyx::ERT_CODE)
special_case = true;