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

    Testing patterns:
            \fill[pattern = north east lines] (-1,2) rectangle (-2,-2);

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' /> 
<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>  
<!-- l. 6 --><p class='noindent'>Testing patterns:
</p><!-- l. 8 --><p class='indent'>   <img src='Test20x.svg' alt='  ' />

and an empty SVG file.



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.


% Driver commands for tex4ht

% Load common pdf commands:
\input pgfsys-dvisvgm.def
%\input pgfsys-dvips.def

  \ifdefined\inside@pict@cmd% handle nested uses
  \def\run@pict@cmd{}% insert the \Picture hooks only in the top nesting level
  % use different version of \Picture depending on the vertical mode
  % command used to detect nesting
  \csname a:tikzpicture\endcsname%

  \csname b:tikzpicture\endcsname%

  % configure the output picture format to svg
  % insert tex4ht hook to the code used at the start and end of each TikZ picture

% Make the code inserted by tex4ht configurable

  % \ifvmode\IgnorePar\fi\EndP%\HtmlParOff
  \protect\csname nested:math\endcsname% support display math

\def\pgf@sys@postscript@header#1{{\special{! #1}}}



%%% 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:


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

Here is the result:

enter image description here

  • 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.