]> git.lyx.org Git - features.git/commitdiff
DocBook: improve equation formatting (new lines for block equations).
authorThibaut Cuvelier <tcuvelier@lyx.org>
Sat, 29 Aug 2020 17:05:59 +0000 (19:05 +0200)
committerThibaut Cuvelier <tcuvelier@lyx.org>
Sat, 19 Sep 2020 18:43:38 +0000 (20:43 +0200)
autotests/export/docbook/basic.lyx
autotests/export/docbook/basic.xml
src/Paragraph.cpp
src/mathed/InsetMathHull.cpp
src/output_docbook.cpp

index 1735dc426690522f395371de7ea97c0180f22e67..fa98d65fdda9428ec4adc7586d29b8111856d8ed 100644 (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
 
index 79802893f6a255bb8ff65c57b5215eca3d4a9dd9..430611e490e729b941245cdd4e8aa23240ad7198 100644 (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>
index e87ef8817628918e226e4bea2a9b35932e4782a2..aad1ccf1424c10b20670abf5317348f8ed707220 100644 (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);
                }
index 800cbeb50f0592df4bd5f97db9fe4128ac783074..58471210698aa5da58d029ffcedab1046f47f06d 100644 (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) {
index 9d518539e7864da93741b290952dde8363753173..e609f3928270c8c1b4f26ecb37c4006100f7fd05 100644 (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;