michal-h21 / make4ht

Build system for tex4ht
132 stars 15 forks source link

'mathml'-option produces long vertical line #97

Closed yalguzaq closed 1 year ago

yalguzaq commented 1 year ago

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

michal-h21 commented 1 year ago

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

yalguzaq commented 1 year ago

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?

michal-h21 commented 1 year ago

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.

yalguzaq commented 1 year ago

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.

michal-h21 commented 1 year ago

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
yalguzaq commented 1 year ago

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