On Sat, 22 Jul 2023 at 00:00, Jean-Marc Lasgouttes <lasgout...@lyx.org>
wrote:

> Le 18/07/2023 à 15:11, Jean-Marc Lasgouttes a écrit :
> > Hello,
> >
> > In the attached patch, I am able to support the mod/bmod/pmod/pod macros
> > by just defining them in lib/symbols with an argument.
> >
> > The result is a more pleasing editing process (IMO) and a simplification
> > of the documentation.
>
> It is in now.
>

Your change with arguments doesn't cause any real trouble for MathML
output, it works as expected. However, it highlighted a problem with
InsetMathClass:
it would output something like [mathbin [char + mathalpha]] instead of +,
due to the use of \mathbin when you define \bmod. I'm fixing that with the
attached patch.

Could you (or anyone else) please commit the attached patch? I currently
don't have access to the Git repo via SSH :/. Thanks!
From 4c868a476eca6cad8b7a9db29e560e27f4ceb579 Mon Sep 17 00:00:00 2001
From: Thibaut Cuvelier <tcuvelier@lyx.org>
Date: Thu, 27 Jul 2023 02:43:56 +0200
Subject: [PATCH] MathML: implement InsetMathClass.

Before this patch, each character within InsetMathClass was output separately, without understanding their meaning, using the default text output (with [] around each character). This commit changes the behaviour to skip the InsetMathClass during the MathML output. This effectively renders the inset useless for MathML (instead of controlling spacing), as expected, because the MathML processor is supposed to handle the spacing itself.

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 | 11 +++++++++++
 src/mathed/InsetMathClass.h   |  2 ++
 src/mathed/MathClass.h        |  2 +-
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/mathed/InsetMathClass.cpp b/src/mathed/InsetMathClass.cpp
index 0c22d478c7..2bfea82ce0 100644
--- a/src/mathed/InsetMathClass.cpp
+++ b/src/mathed/InsetMathClass.cpp
@@ -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_);
diff --git a/src/mathed/InsetMathClass.h b/src/mathed/InsetMathClass.h
index 89189f2b0d..f4308beb9b 100644
--- a/src/mathed/InsetMathClass.h
+++ b/src/mathed/InsetMathClass.h
@@ -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; }
diff --git a/src/mathed/MathClass.h b/src/mathed/MathClass.h
index 169bfdb51a..af4f884cca 100644
--- a/src/mathed/MathClass.h
+++ b/src/mathed/MathClass.h
@@ -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,
-- 
2.41.0.windows.1

-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to