[LyX/master] DocBook: improve equation formatting (new lines for block equations).
Thibaut Cuvelier
tcuvelier at lyx.org
Sat Sep 19 18:18:55 UTC 2020
commit 39ad6e84f076cea65f140593e5b6647905219af3
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date: Sat Aug 29 19:05:59 2020 +0200
DocBook: improve equation formatting (new lines for block equations).
---
autotests/export/docbook/basic.lyx | 2 +-
autotests/export/docbook/basic.xml | 9 +++++----
src/Paragraph.cpp | 4 ++--
src/mathed/InsetMathHull.cpp | 8 +++++++-
src/output_docbook.cpp | 16 +++++++++-------
5 files changed, 24 insertions(+), 15 deletions(-)
diff --git a/autotests/export/docbook/basic.lyx b/autotests/export/docbook/basic.lyx
index 1735dc4..fa98d65 100644
--- a/autotests/export/docbook/basic.lyx
+++ b/autotests/export/docbook/basic.lyx
@@ -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
diff --git a/autotests/export/docbook/basic.xml b/autotests/export/docbook/basic.xml
index 7980289..430611e 100644
--- a/autotests/export/docbook/basic.xml
+++ b/autotests/export/docbook/basic.xml
@@ -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>
diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index e87ef88..aad1ccf 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -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);
}
diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp
index 800cbeb..5847121 100644
--- a/src/mathed/InsetMathHull.cpp
+++ b/src/mathed/InsetMathHull.cpp
@@ -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) {
diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index 9d51853..e609f39 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -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;
More information about the lyx-cvs
mailing list