# Tikz patterns library and dvisvgm4ht

Does the dvisvgm4ht driver with make4ht support the TikZ Patterns library? The following MWE:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{patterns}
\def\pgfsysdriver{pgfsys-dvisvgm4ht.def}
\begin{document}
Testing patterns:

\begin{tikzpicture}
\fill[pattern = north east lines] (-1,2) rectangle (-2,-2);
\end{tikzpicture}
\end{document}


generates the HTML:

<!DOCTYPE html>
<html xml:lang='en-US' lang='en-US'>
<meta charset='utf-8' />
<meta content='TeX4ht (https://tug.org/tex4ht/)' name='generator' />
<meta content='width=device-width,initial-scale=1' name='viewport' />
<meta content='Test2.tex' name='src' />
<script>window.MathJax = { tex: { tags: "ams", }, }; </script>
<script async='async' type='text/javascript' src='https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml-full.js' id='MathJax-script'></script>
<!-- l. 6 --><p class='noindent'>Testing patterns:
</p><!-- l. 8 --><p class='indent'>   <img src='Test20x.svg' alt='  ' />
</p>
</body>
</html>


and an empty SVG file.

Edit:

I've updated the dvisvgm4ht driver. It is possible to choose between dvips (default) and dvisvgm backend. The dvisvgm backend supports TikZ patterns, but it fails with some complex pictures, so it isn't used by default. To select it, use the tikz+ option:

make4ht -m draft filename.tex "tikz+"


The dvisvgm4ht driver uses another driver, pgfsys-dvips.def, internally. It seems that it doesn't support patterns. It doesn't use pgfsys-dvisvgm4ht.def, because it didn't record the image dimensions correctly, they were set to zero. So even if the SVG file contained the graphics, it couldn't be displayed.

I finally found the way how to correctly use the dvisvgm driver and keep the image dimensions. Here is a new version of pgfsys-dvisvgm4ht.def:

% Copyright 2020 by Michal Hoftich
% Copyright 2006 by Till Tantau
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
%

\ProvidesFileRCS{pgfsys-dvisvgm4ht.def}

% Driver commands for tex4ht

%
%
\input pgfsys-dvisvgm.def
%\input pgfsys-dvips.def

\def\texfourht@tikz@begin{%
\bgroup%
\ifdefined\inside@pict@cmd% handle nested uses
\def\run@pict@cmd{}% insert the \Picture hooks only in the top nesting level
\def\end@pict@cmd{}%
\else
% use different version of \Picture depending on the vertical mode
\ifvmode\def\run@pict@cmd{\Picture*}\else\def\run@pict@cmd{\Picture+}\fi%
\def\end@pict@cmd{\EndPicture}%
\fi%
% command used to detect nesting
\def\inside@pict@cmd{}%
\csname a:tikzpicture\endcsname%
}

\def\texfourht@tikz@end{%
\csname b:tikzpicture\endcsname%
\egroup%
\par%
}

\AtBeginDocument{
% configure the output picture format to svg
\Configure{Picture}{.svg}
% insert tex4ht hook to the code used at the start and end of each TikZ picture
\def\pgfsys@beginpicture{%
\texfourht@tikz@begin%
\orig@pgfsys@begin%
}%
\def\pgfsys@endpicture{%
\orig@pgfsys@end%
\texfourht@tikz@end%
}%
}

% Make the code inserted by tex4ht configurable

\NewConfigure{tikzpicture}{2}
\Configure{tikzpicture}{%
% \ifvmode\IgnorePar\fi\EndP%\HtmlParOff
\protect\csname nested:math\endcsname% support display math
\run@pict@cmd{}%
}{\end@pict@cmd}

\let\orig@pgfsys@begin\pgfsys@beginpicture
\let\orig@pgfsys@end\pgfsys@endpicture

\endinput

%%% Local Variables:
%%% mode: latex
%%% End:


The difference to the original driver is that it now patches directly the tikzpicture environment, instead of just patching of internal TikZ driver macros:

\AddToHook{env/tikzpicture/before}{\texfourht@tikz@begin}

Downside is that it won't work for the \tikz command.
• Thank you so much for the response, I am unable to get it to work, though. I modified the driver file and now I get this error message: [WARNING] domfilter: DOM parsing of Test2.html failed: [WARNING] domfilter: ...Programs/MiKTeX 2.9/tex/luatex/luaxml/luaxml-mod-xml.lua:175: Unbalanced Tag (/body) [char=743] when I run make4ht Test.tex "xhtml,mathjax" Mar 31 at 17:41
• @Rushi ah I see. You need to put \def\pgfsysdriver{pgfsys-dvisvgm4ht.def} before \usepackage{tikz}, because it has no effect when you put it after that. Mar 31 at 19:09