1

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'> 
<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 rel='stylesheet' type='text/css' href='Test2.css' /> 
<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>  
</head><body>
<!-- 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.

2

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+"

Original answer:

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.
%
% See the file doc/generic/pgf/licenses/LICENSE for more details.

\ProvidesFileRCS{pgfsys-dvisvgm4ht.def}

% Driver commands for tex4ht

%
% Load common pdf commands:
%
\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
\def\pgf@sys@postscript@header#1{{\special{! #1}}}

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

\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}
\AddToHook{env/tikzpicture/after}{\texfourht@tikz@end}

Downside is that it won't work for the \tikz command.

Here is the result:

enter image description here

10
  • 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"
    – Rushi
    Mar 31 at 17:41
  • Edit: The above was with a single line of text "Testing Patterns" added to the MWE right before the tikz picture.
    – Rushi
    Mar 31 at 17:49
  • @Rushi can you please update your question with the code that fails? I cannot reproduce it.
    – michal.h21
    Mar 31 at 18:28
  • Added the code, the html, the SVG, and an image of the rendered webpage.
    – Rushi
    Mar 31 at 18:41
  • 1
    @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.
    – michal.h21
    Mar 31 at 19:09

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.