lyx_mirror/src/mathed/InsetMathClass.cpp
Thibaut Cuvelier 98d1b04160 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>
 ```
2023-07-27 01:22:30 -04:00

83 lines
1.4 KiB
C++

/**
* \file InsetMathClass.cpp
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author André Pönitz
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "InsetMathClass.h"
#include "MathStream.h"
#include "support/docstream.h"
namespace lyx {
InsetMathClass::InsetMathClass(Buffer * buf, MathClass mc)
: InsetMathNest(buf, 1), math_class_(mc)
{}
Inset * InsetMathClass::clone() const
{
return new InsetMathClass(*this);
}
Limits InsetMathClass::defaultLimits(bool display) const
{
if (allowsLimitsChange() && display)
return LIMITS;
else
return NO_LIMITS;
}
void InsetMathClass::metrics(MetricsInfo & mi, Dimension & dim) const
{
cell(0).metrics(mi, dim);
}
void InsetMathClass::draw(PainterInfo & pi, int x, int y) const
{
cell(0).draw(pi, x, y);
}
void InsetMathClass::write(TeXMathStream & os) const
{
InsetMathNest::write(os);
writeLimits(os);
}
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_);
}
void InsetMathClass::infoize(odocstream & os) const
{
os << name() << " ";
}
} // namespace lyx