I found that make4ht/tex4ht uses a combination of unicode + dvi/svg images to represent my document in HTML.

I think it would be much more useful to me if I could choose to have all my mathematics (i.e. anything inside $, $$, or an amsmath environment) be represented by DVI/SVG.

But it is not clear to me if this is something I can make make4ht do?

Closely related: Converting LaTeX to HTML but keeping equations as LaTeX

  • I must be missing something, but if you just use mathjax mode in make4ht, then all the math will be rendered as svg automatically by mathjax in HTML? For images, I have my makefiles convert all pdf images to svg automatically before calling make4ht, and so all my non-math images (i.e. graphics) are in svg as well.
    – Nasser
    Commented Oct 20, 2022 at 23:00
  • @Nasser I use a lot of macros in my math, which mathjax fails to handle. Both mathjax and katex are next to useless for me.
    – bzm3r
    Commented Oct 20, 2022 at 23:09

1 Answer 1


Curiously, I wrote a section on picture math for TeX4ht documentation just yesterday.

You can use various TeX4ht options to request the conversion of additional math environments to pictures. See the various pic-... options.

One issue with picture math is the vertical alignment of inline elements. If you use something like $ a = \sqrt{b^2}$, the a character will be placed higher than the surrounding text. This is a well known issue, but I just found a solution, thanks to this configuration file:


{\Css{img[src="\PictureFile"]{vertical-align:-\fp_eval:n{ \dim_to_fp:n{\dp0}/(\dim_to_fp:n{\ht0}+\dim_to_fp:n{\dp0}) * 100}\%;}}
{ class="math" }

The \Preamble{xhtml,pic-m,pic-equation,svg} requires creation of pictures for inline math and equations, also it requires the svg format. Then we use the PicMath configuration, which is called for all inline math, to typeset math inside a box first. We can then use this box to measure the correct vertical alignment. The formula I use is this: box depth / total box height * 100. The resulting value can be used in CSS. You will get something like this in the CSS file:


Here is a sample file:


Hello $a=\sqrt{b}$, and other text xyz \(a=\sqrt{b}\)

  a = \frac{a}{b}

  a = \frac{a}{b}


Compile using:

$ make4ht -c config.cfg sample.tex

And this is the rendered page:

enter image description here

  • Whoa! This is precisely what I wanted. Thank you!
    – bzm3r
    Commented Oct 20, 2022 at 18:43

You must log in to answer this question.

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