I am really loving make4ht and tex4ht, as they finally allow me to keep all of my tooling while generating web pages. One minor issue I am running into has to do with the kerning of some characters while in math mode. So if I have a tikz image, I am getting things that look like this.

In the image below, you can see that the sigma character is too close to the frame of the vector, and that the underbrace is a little off from the array as well.

enter image description here

In the corresponding pdf output, these issues don't exist. Now I could just add some spaces or something as a workaround, but wanted to check and see if there is anything that I might be doing wrong or any simple fixes. Could this be some sort of CSS issue?

Note, I can supply additional examples of this if it would be helpful.


I am including a full example. This was the code that regenerates the issue.

First, here isthe command string that I used:

make4ht -d html -f html5+latexmk_build -s mydevfile.tex 

Here is the myconfig.cfg


The mymacros.tex file:

\def\RRRR{{\bf R}}
\newcommand\bface[1]{{\mathbf #1}}
  \begin{tikzpicture}[baseline=(current bounding box)]
    \foreach \x in {1,...,#2} {
      \foreach \y in {1,...,#1} {
        \draw[fill=#3, color=#3] ($(0.4*\x, 0.4*\y)$) circle[radius=0.15cm];
    \draw (0.2, 0.2) rectangle ($(0.4*#2, 0.4*#1) + (0.2, 0.2)$);

The mymacros.sty file:


Finally, here is a minimal latex document, mydevfile.tex:

\documentclass[12pt, a4paper, oneside, headinclude, footinclude]{article}


\usetikzlibrary{shapes.multipart, positioning, decorations.markings,
  arrows.meta, calc, fit}

\title{\normalfont\spacedallcaps{My doc}}
\date{\today\\version 0.1}


\section*{First Section}

  \RRRR = \bface{x}
Some simple text.

  \underbrace{\grid{10}{1}{red}}_{\mathbf{\hat{x}}} =
  \sigma \left( \underbrace{\grid{10}{5}{blue}}_{\mathbf{u}^\top}
    \sigma \left( \underbrace{\grid{5}{2}{blue}}_{\mathbf{w}^\top} 
      \sigma \left(\underbrace{\grid{2}{5}{blue}}_{\mathbf{U}}
        \sigma\left( \underbrace{\grid{5}{10}{blue}}_{\mathbf{V}}
          \underbrace{\grid{10}{1}{red}}_{x}\right)\right) \right) \right)

Now the picture looks like: enter image description here

  • can you please post a full MWE, so we can test it?
    – michal.h21
    Mar 27 at 22:36
  • @michal.h21 yep, I was able to regenerate the exact issue. I am still getting these weird kerning errors. Hopefully you can reproduce them. Let me know if anything is ambiguous about the code.
    – krishnab
    Mar 28 at 5:23

It seems that you want to combine two methods for displaying math: I suppose that you want to use MathJax for inline math, and SVG pictures for display math. The problem is that most math environments and commands are redefined to output the literal LaTeX code that is passed to them in the MathJax mode. This means that your \grid command which uses TikZ cannot work, as MathJax doesn't support TikZ.

To configure \[ ... \] to produce pictures, you can try the following configuration file:

% don't redefine \left and \right
       \protect\csname nested:math\endcsname%
   {$$\EndPicDisplay \egroup \ShowPar \par{\HCondtrue\noindent}%


I've used the \Configure{[]} command from the default HTML configuration. The important commands are \PicDisplay and \EndPicDisplay, which convert the contained content to images. Rest of the commands handle paragraphs and math nesting. One important thing is \def\fixmathjaxsec#1{}. The original version of this command redefines command that is passed to it to produce literal output. It is used for \left and \right commands, because they caused some issues when used in sections. We need to prevent that. Just remember that you shouldn't use \left and \right in sections, because you will get an error otherwise.

This is the result:

enter image description here

  • Thanks so much @Michal.h21. This code works. I still get some overlap between the sigma and the brackets, but I can perhaps just add some spaces. In terms of your comment about SVG for display math and Mathjax for inline math, I was just wondering if I am doing it wrong, or if I not following what most other folks do? I was literally just hoping to include the Tikz and Pgf diagrams in the latex export to html. So whatever way works best for this, I am happy to follow. I was not tryign to do anything non-standard.
    – krishnab
    Mar 28 at 15:09
  • 1
    @krishnab no you are not doing anything wrong, there is just the issue that mathjax doesn't support TikZ, so you have to use some workarounds, and it is possible that you will experience some strange bugs.
    – michal.h21
    Mar 28 at 15:27
  • Okay that is reassuring :). Yes, I get what you mean now. I mean, I am impressed at how well make4ht, tex4ht, and pandoc all work, given the different processing engines, etc. So I really appreciate all of the efforts that you and everyone invests in making this ecosystem run. I guess once I get more of a feel for the html stuff, I will figure out the workarounds. Thanks again for all of your help.
    – krishnab
    Mar 28 at 15:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.