make4ht icon indicating copy to clipboard operation
make4ht copied to clipboard

'mathml'-option produces long vertical line

Open iabarus opened this issue 3 years ago • 4 comments

LaTeX: $$\left({\bf E}|X|^p\right)^{\frac{q}{p}} \leq {\bf E} |X|^q$$

Compilation command: make4ht markup.tex 'mathml,mathjax'

Erroneous output: image image

Correct output: image

The problem summary: The absolute value line on the left is too long

iabarus avatar Nov 06 '22 17:11 iabarus

In this case, just the right | character is used as the superscript base. You need to use {|X|} instead of just |X|.

michal-h21 avatar Nov 07 '22 11:11 michal-h21

But this is not a standard LaTeX behaviour, no one uses | for superscripts. Furthermore, the problem only appears within the mathml context.

Considering how widespread the usage of | is for absolute value brackets, would it be possible to fix this in a new version of make4ht? Is there a temporary cfg fix?

iabarus avatar Nov 10 '22 08:11 iabarus

The problem is that it is impossible at the TeX level to detect superscript base without proper grouping. You either use group, or only the last token is used. In the PDF output this error doesn't cause problems, because it is visually correct. In MathML, you need to correctly mark the base, and it is impossible without proper user input.

michal-h21 avatar Nov 10 '22 08:11 michal-h21

Unfortunately, I do not understand this at all. In LaTeX, one uses ^{...} for superscripts. What does | have anything to do with superscript behaviour? Furthermore, MathJaX's TeX converter always parses this correctly, so why exactly is it not possible with MathML? I googled latex superscript base and found nothing about it. Is it really that important? Wouldn't it be possible to turn it off and instead use | for symbol only?

I would usually accept that this behaviour is unfixable but in this case it is quite important (statistically). 80% of entries on my website use | for absolute values and therefore produce wrong output. To fix this, I would need to switch to 'mathjax' from 'mathml,mathjax' which would be very painful for me since my users use a lot of custom \def and \newcommands which are then not parsed in math mode.

Thanks a lot for taking your time to answer these questions.

iabarus avatar Nov 10 '22 11:11 iabarus

I've just realized that you can use an MathML attribute stretchy to disable stretching of the bar. It seems that MathJax uses it as well. I still think it is better to correctly mark the superscript base, but with this change, the visual output will be the same.

Try this config file:

\Preamble{xhtml}
\Configure{MathClass}{3}{*}{<mo class="MathClass-rel" stretchy="false">}{</mo>}{}
\begin{document}
\EndPreamble

michal-h21 avatar Dec 14 '22 09:12 michal-h21

Yes, this works perfectly! I hope this will become the default behaviour.

iabarus avatar Jul 11 '23 17:07 iabarus