5

When run through pdflatex the code snippet below produces:

enter image description here

but when I run it through make4ht the following web page, without the numbers, is generated:

enter image description here

(The difference in scale is an artifact of my skills in taking screenshots.) Here is the code:

\documentclass{article}
\usepackage{tikz}
\begin{document}

     \begin{tikzpicture}
        \foreach \x in {-3,...,3} { \draw(\x,0.25) --(\x,0)node[below]{\x}; }
        \foreach \x in {-2.5,...,2.5} { \draw(\x,0.18) --(\x,0); }
        \draw[thick,<->](-3.5,0)--(3.5,0);
        \filldraw[blue!50!white](1.5,0) circle (1mm);
        \draw[red] (-3.5,-1) rectangle (3.5,1); % make bounding box higher
     \end{tikzpicture}

\end{document}

Only the first line of the tikzpicture environment is necessary. The rest is just to show that everything else is OK.

I am using TeXLive 2018 and I have just updated all packages.

7

Try the following configuration file:

\Preamble{xhtml}
\tikzset{every node/.style={/pgf/tex4ht node/escape=true}}
\begin{document}
\EndPreamble

From the TikZ manual:

Selects the rendering method for a text node with the tex4ht driver. When this key is set to false, text is translated P R into svg text, which is somewhat limited: simple characters (letters, numerals, punctuation, , , . . . ), subscripts and superscripts (but not sub- subscripts) will display but everything else will be filtered out, ignored or will produce invalid html code (in the worst case). This means that two kind of texts render reasonably well:

  1. First, plain text without math mode, special characters or anything else special.

  2. Second, very simple mathematical text that contains subscripts or superscripts. Even then, variables are not correctly set in italics and, in general, text simple does not look very nice. If you use text that contains anything special, even something as simple as $\alpha$, this may corrupt the graphic.

    \tikz \node[draw,/pgf/tex4ht node/escape=false]

{Example :

$(a+b)^2=a^2+2ab+b^2$}; 

When you write node[/pgf/tex4ht node/escape=true] {htexti}, pgf escapes back to html to render the htexti. This method produces valid html code in most cases and the support for complicated text nodes is much better since code that renders well outside a {pgfpicture}, should also render well inside a text node. Another advantage is that inside text nodes with fixed width, html will produce line breaks for long lines. On the other hand, you need a browser with good svg support to display the picture.

Also, the text will display differently, depending on your browsers, the fonts you have on your system and your settings. Finally, pgf has to guess the size of the text rendered by the browser to scale it and prevent it from sticking from the node. When it fails, the text will be either cropped or too small.

The result on your file:

enter image description here

Another possibility is to use an alternative driver for tex4ht, which use Dvisvgm for the SVG generation. It has much better support for fonts and other advanced SVG features.

The TeX file needs to be updated to use the driver:

\documentclass{article}
\ifdefined\HCode
  \def\pgfsysdriver{pgfsys-dvisvgm4ht.def}
\fi 
\usepackage{tikz}
\begin{document}

     \begin{tikzpicture}
        \foreach \x in {-3,...,3} { \draw(\x,0.25) --(\x,0)node[below]{\x}; }
        \foreach \x in {-2.5,...,2.5} { \draw(\x,0.18) --(\x,0); }
        \draw[thick,<->](-3.5,0)--(3.5,0);
        \filldraw[blue!50!white](1.5,0) circle (1mm);
        \draw[red] (-3.5,-1) rectangle (3.5,1); % make bounding box higher
     \end{tikzpicture}

\end{document}

The result:

enter image description here

  • Thanks Michal. I had this line in before but took it out as it seemed to cause problems. My MWE now compiles properly with make4ht but it still fails with webquiz with only the top third of the numbers appearing. So evidently I am introducing a bug:( This sounds like the last sentence from your manual entry above... Thanks for telling me where to look. – Andrew Jan 23 at 11:36
  • @andrew you can also try the dvsvgm driver: github.com/michal-h21/dvisvgm4ht - but I haven't tested it with updated TikZ yet. – michal.h21 Jan 23 at 11:42
  • @Andrew it seems to work nicely, see the update – michal.h21 Jan 23 at 12:08
  • I must be doing something stupid as I am getting the error ! Undefined control sequence. l.33 \NewConfigure. As I did previously, I am including the code with the line \ifdefined\HCode \def\pgfsysdriver{pgfsys-dvisvgm4ht.def} \fi in my class file before \RequirePackage{tikz}. What am I doing wrong? – Andrew Jan 23 at 13:06
  • @Andrew do you have the same problem when you use it in the TeX file? It may be issue that you use it in class. – michal.h21 Jan 23 at 13:14

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.