I'm using make4ht
to generate HTML from a .tex file which contains tikz
images.
I use the tikzexternalize
command together with code from Htlatex and Tikz creates sometimes incorrect svgs to ensure that the images are included as .png
files in the HTML.
minimal working example
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{external}
\ifdefined\HCode
% this part is activated with make4ht
\tikzexternalize[mode=only graphics]
\tikzset{png export/.style={
/pgf/images/external info,
/pgf/images/include external/.code={%
\includegraphics{##1.png},
},
},
png export,
}
\else
% this part is activated with pdflatex
\tikzexternalize
\tikzset{pdf export/.style={
/pgf/images/external info,
/pgf/images/include external/.code={%
\includegraphics{##1.pdf},
},
},
pdf export,
}
\fi
\begin{document}
\begin{tikzpicture}
\draw (0,0) -- (0,1) -- (1,1) -- (1,0) -- (0,0);
\end{tikzpicture}
\end{document}
compilation
I use the following command to produce myfile-figure0.pdf
and then image magick to produce myfile-figure0.png
:
pdflatex --shell-escape myfile
magick.exe myfile-figure0.pdf myfile-figure0.png
I then use
make4ht -m draft myfile.tex
to produce the following HTML
<!DOCTYPE html>
<html lang='en-US' xml:lang='en-US'>
<head><title></title>
<meta charset='utf-8' />
<meta content='TeX4ht (https://tug.org/tex4ht/)' name='generator' />
<meta content='width=device-width,initial-scale=1' name='viewport' />
<link href='myfile.css' rel='stylesheet' type='text/css' />
<meta content='myfile.tex' name='src' />
</head><body>
<!-- l. 29 --><p class='noindent'><img alt=',
' src='myfile0x.svg' />
</p>
</body>
</html>
the question
How can I configure my build process so that instead of
<img alt=',
' src='myfile0x.svg' />
I receive
<img alt=',
' src='myfile-figure0.png' />
for reference
I'm on texlive 2021 and make4ht version 0.3j. In texlive 2020 and before, I did not have this issue, and the settings that I have gave my desired output.
Perhaps my issue is related to the following snippet from myfile.log
which I also did not receive in texlive 2020.
(\end occurred inside a group at level 1)
### simple group (level 1) entered at line 22 ({)
### bottom level
Best Answer
This is caused by the fact that TeX4ht now uses the
pgfsys-dvisvgm4ht.def
driver by default. It doesn't support theexternal
library. Here is the version that fixes this issue:I've also found that you have one issue in your TeX file. You have spurious comma after
\includegraphics
command. It ends in the HTML code. This is a fixed version:Btw, TeX4ht has built-in support for the externalization library, it always requires the picture mode. The current version is somehow broken, but you can try this fix,
tikz-hooks.4ht
:You can then simplify your document:
And this is the result: