]> git.lyx.org Git - features.git/commitdiff
Before this patch, each character within InsetMathClass was output separately, withou...
authorThibaut Cuvelier <dourouc05@gmail.com>
Thu, 27 Jul 2023 05:21:46 +0000 (01:21 -0400)
committerRichard Kimberly Heck <rikiheck@lyx.org>
Thu, 27 Jul 2023 05:22:30 +0000 (01:22 -0400)
Another implementation would have been to use the lspace and rspace attributes in MathML, but they require to give the exact spacing before and after the operator instead of relying on rules like TeX.

For instance, `$a\mathbin{+}b$` resulted in this MathML output before the patch:

```
<math xmlns='http://www.w3.org/1998/Math/MathML'>
<mrow>
 <mi>a</mi><!--  -->
 <mi>[mathbin [char + mathalpha]]</mi>
 <mi>b</mi>
</mrow>
</math>
```

For comparison, this was the output with LyX 2.3.7

```
<math xmlns="http://www.w3.org/1998/Math/MathML">
 <mrow>
  <mrow><mi>a</mi><!--  -->
   <mi>[mathbin [char + mathalpha]]
   </mi><mi>b</mi>
  </mrow>
 </mrow></math>
 ```

 After this patch, it looks like:

 ```
 <math xmlns='http://www.w3.org/1998/Math/MathML'>
 <mstyle class='math'>
  <mrow>
   <mi>a</mi>
   <mo>+</mo>
   <mi>b</mi>
  </mrow>
 </mstyle>
 </math>
 ```

src/mathed/InsetMathClass.cpp
src/mathed/InsetMathClass.h
src/mathed/MathClass.h

index 0c22d478c7acb8d413eb5aa131afb2a544c2c0a8..2bfea82ce0e79fb3c8fa26291be2d00e3930bf1d 100644 (file)
@@ -11,6 +11,7 @@
 #include <config.h>
 
 #include "InsetMathClass.h"
+#include "MathStream.h"
 
 #include "support/docstream.h"
 
@@ -56,6 +57,16 @@ void InsetMathClass::write(TeXMathStream & os) const
 }
 
 
+void InsetMathClass::mathmlize(MathMLStream & ms) const
+{
+       // Skip the \mathXXX macro, the MathML processor is supposed to handle
+       // spacing down the line.
+       for (size_t i = 0; i < nargs(); ++i) {
+               ms << cell(i);
+       }
+}
+
+
 docstring InsetMathClass::name() const
 {
        return class_to_string(math_class_);
index 89189f2b0ddf88814a070be94e9abd1712241ed5..f4308beb9b1406bd0874aad2d2a10a71aadebf55 100644 (file)
@@ -43,6 +43,8 @@ public:
        ///
        void write(TeXMathStream & os) const override;
        ///
+       void mathmlize(MathMLStream & ms) const override;
+       ///
        void infoize(odocstream & os) const override;
        ///
        InsetCode lyxCode() const override { return MATH_CLASS_CODE; }
index 169bfdb51aec456e5bc1a0961f4e5aa678281e30..af4f884cca5df2824700a7cac78313bf2aff9a9b 100644 (file)
@@ -40,7 +40,7 @@ class MetricsBase;
  * + Vcent: a vbox to be centered, produced by \vcenter.
  *
  * Over, Under, Acc, Rad and Vcent are not considered in the enum
- * below. The relvant elements will be considered as Ord.
+ * below. The relevant elements will be considered as Ord.
  */
 enum MathClass {
        MC_ORD,