Support Cancellation of Terms in MathML
Description
It would be very useful for Pandoc to be able to convert the \cancel, \bcancel, and \xcancel LaTeX commands to MathML as described below (from https://github.com/NSoiffer/MathCAT/issues/341):
The way I would suggest is to use menclose . It has the attribute notation with many options. For cancellation, one or both values updiagonalstrike downdiagonalstrike would make sense.
<math>
<menclose notation='downdiagonalstrike'> <mfrac><mn>3</mn><mn>2</mn></mfrac> </menclose>
</math>
It currently seems that, when typing math in Pandoc's Markdown, base LaTeX and amsmath commands are able to be converted to MathML. The three commands listed above are part of the cancel package.
One problem with <menclose> is that it's not part of MathML Core and so has poor support in browsers (only Firefox supports it). However, there have been discussions about adding it to MathML Core: https://github.com/w3c/mathml-core/issues/245 (and I personally would definitely be in favor of that).
Hi, I've been looking through the code for #269. It looks like the MathML reader and writer already supportmenclose for \boxed, so I think it could be added for \cancel, \bcancel, and xcancel. I'm not sure what's the best way to go about this, but I'm thinking we could add a new type ECancel, which takes the expression being cancelled and two booleans - one for \cancel and another for \bcancel. If both bools are true, then we have \xcancel.
https://github.com/jgm/texmath/blob/9d02b5a5936d91a739d95a260feac29818533127/src/Text/TeXMath/Writers/MathML.hs#L239-L240
Yes, one could add a new constructor ECancel. (Rather than booleans, it might be better to add a custom data type to customize.)
However, this is a big change: one would need to support the new constructor in every input and output format.
If someone could describe the difference between \cancel \bcancel and \xcancel, that would be helpful.
Yes, one could add a new constructor
ECancel. (Rather than booleans, it might be better to add a custom data type to customize.)
The custom data type could store the command name, so it can take values cancel, xcancel, or bcancel. Would that work?
In MathML, \cancel{251636} is equivalent to:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<menclose notation="updiagonalstrike">
<mn>251636</mn>
</menclose>
</math>
For \bcancel{251636}, notation is set to downdiagonalstrike; and for \xcancel{251636}, both updiagonalstrike and downdiagonalstrike are used. In OMML, pasting the MathML in Word gives:
<m:oMathPara>
<m:oMath>
<m:borderBox>
<m:borderBoxPr>
<m:hideTop m:val="1" />
<m:hideBot m:val="1" />
<m:hideLeft m:val="1" />
<m:hideRight m:val="1" />
<m:strikeBLTR m:val="1" />
<m:ctrlPr>
<w:rPr>
<w:rFonts w:ascii="Cambria Math" w:hAnsi="Cambria Math" />
</w:rPr>
</m:ctrlPr>
</m:borderBoxPr>
<m:e>
<m:r>
<w:rPr>
<w:rFonts w:ascii="Cambria Math" w:hAnsi="Cambria Math" />
</w:rPr>
<m:t>251636</m:t>
</m:r>
</m:e>
</m:borderBox>
</m:oMath>
</m:oMathPara>
For \bcancel{251636}, strikeTLBR is used instead of strikeBLTR; and for \xcancel{251636}, both are used. Typst also has a cancel command, but I am not sure if it has an equivalent for \bcancel and \xcancel.
The custom data type could store the command name, so it can take values cancel, xcancel, or bcancel. Would that work?
This sounds too TeX-centric. This is a neutral data structure that can be converted to/from various formats. I would suggest a data type like
data StrokeType = ForwardSlash | BackwardSlash | XSlash
I can give this a go to implement the new constructor if no work has been started.
Go ahead!