Scaling delimiters in MathJax

mathjaxmathmltex4ht

I use TeX4ht with MathJax to convert tex to HTML/MathML. One issue I have is that delimiters scale depending on the height of the line, even if the tall content is not between the delimiters. For instance, compiling the document

\documentclass{article}
\begin{document}
\[
    f(x) = \frac{\frac{x}{1}}{\frac{2}{3}} 
\]
\end{document}

with

htlatex test "cf,mathjax"

yields

enter image description here

Here cf.cfg just contains

\Preamble{html,mathml}
\begin{document}
\EndPreamble

I think the parentheses are too large. Is there a way to control the scaling?

Best Answer

As David Carlisle said, this is a bug in TeX4ht. <mo> elements around parentheses should have set the stretchy="false" attribute. I will fix that in TeX4ht sources. Until this fix is added to TeX Live, you can use the following .cfg file:

\Preamble{xhtml,mathml,mathjax}
\catcode`\:=11
\Configure{MathClass}{4}{*}{<\a:mathml mo\Hnewline
          \mml:class="MathClass-open" stretchy="false">}
                        {</\a:mathml mo>}{}
\Configure{MathClass}{5}{*}{<\a:mathml mo\Hnewline
          \mml:class="MathClass-close" stretchy="false">}
                        {</\a:mathml mo>}{}
\catcode`\:=12
\begin{document}
\EndPreamble

BTW, I would recommend to use make4ht instead of htlatex, because it fixes some issues with MathML that are impossible to fix on the TeX side. So you can compile your file using:

make4ht -c cf.cfg test "mathml,mathjax"

This is the result:

enter image description here

Related Question