TransWikia.com

Typesetting issues with make4ht and tex4ht--kerning of math characters seems too close

TeX - LaTeX Asked on May 18, 2021

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.

UPDATED

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

Preamble{xhtml,mathjax}
Configure{@BODY}{IgnorePar
HCode{detokenize{(}}
special{t4ht*<mymacros.tex}
HCode{detokenize{)}}
par
}
begin{document}
EndPreamble

The mymacros.tex file:

defRRRR{{bf R}}
newcommandbface[1]{{mathbf #1}}
newcommandgrid[3]{
  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)$);
  end{tikzpicture}
}
renewcommand{vec}[1]{mathbf{#1}}

The mymacros.sty file:

ProvidesPackage{mymacros}
input{mymacros.tex}
endinput

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

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

ifdefinedHCode
  defpgfsysdriver{pgfsys-dvisvgm4ht.def}
fi 

usepackage{tikz}
usetikzlibrary{shapes.multipart, positioning, decorations.markings,
  arrows.meta, calc, fit}
usepackage{pgfplots}
usepackage{pgfplotstable}
usepackage{mymacros}

title{normalfontspacedallcaps{My doc}}
author{spacedlowsmallcaps{kb}} 
date{todayversion 0.1}
begin{document} 

pagestyle{scrheadings} 
maketitle 
setcounter{tocdepth}{2}
tableofcontents 

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}}
        sigmaleft( underbrace{grid{5}{10}{blue}}_{mathbf{V}}
          underbrace{grid{10}{1}{red}}_{x}right)right) right) right)
]
end{document}

Now the picture looks like:
enter image description here

One Answer

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:

Preamble{xhtml,mathjax}
% don't redefine left and right
deffixmathjaxsec#1{}
Configure{[]}
   {bgroup%
       protectcsname nested:mathendcsname%
       PicDisplay%
       $$everymath{}everydisplay{}}
   {$$EndPicDisplay egroup ShowPar par{HCondtruenoindent}%
}

begin{document}
EndPreamble

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 deffixmathjaxsec#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

Correct answer by michal.h21 on May 18, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP