Is it possible to make the \dfrac command work in inline mode? Or is it possible to force all the math in diplaystyle mode ? I use make4ht with mathml.

$\frac12$ $\dfrac22$  $\displaystyle \frac32$
\[  \frac{4}{2} \]

I use the command line make4ht file.tex "mathml"

1 Answer 1


Fortunately, information about math style is available in the underlying genfrac configuration, which can be used to enclose the dfrac contents in an element with displaystyle="true" attribute:

\pend:def\dfrac{\Configure{genfrac}{\HCode{<mstyle \mathchoice{displaystyle="true"}{}{}{}>}}{}{}{}{}{\HCode{</mstyle>}}}
\pend:def\tfrac{\Configure{genfrac}{\HCode{<mstyle \mathchoice{displaystyle="false"}{}{}{}>}}{}{}{}{}{\HCode{</mstyle>}}}
\pend:def\dbinom{\Configure{genfrac}{\HCode{<mstyle \mathchoice{displaystyle="true"}{}{}{}>}}{}{}{}{}{\HCode{</mstyle>}}}
\pend:def\tbinom{\Configure{genfrac}{\HCode{<mstyle \mathchoice{displaystyle="false"}{}{}{}>}}{}{}{}{}{\HCode{</mstyle>}}}

In this configuration, we add the <mrow> element, and using the \mathchoice command, we can add the displaystyle attribute. This is the result:

enter image description here

If you want to use displaystyle for all inline math delimited by $ $, use this configuration:

\Configure{$}{\Configure{@math}{display="inline" displaystyle="true"}\DviMath}{\EndDviMath}{}

enter image description here

The downside is that it can be too large when used in text.

  • Thanks for your reactivity, but the first code don't work for me with Mathml+mathjax Dec 21, 2022 at 16:38
  • I try to use Mathml+mathjax for more compatibility Dec 21, 2022 at 16:44
  • @ManuelCart it seems that MathJax needs <mstyle> instead of <mrow>. I've updated my answer with the solution that I used in the end in TeX4ht sources.
    – michal.h21
    Dec 21, 2022 at 16:57
  • I have a new problem with the new code, maybe it is related,. i post it here : tex.stackexchange.com/questions/669428/… Dec 23, 2022 at 12:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .