该dvisvgm4ht
驱动程序是否make4ht
支持 TikZ Patterns 库?以下 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}
生成 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>
和一个空的 SVG 文件。
答案1
编辑:
我已经更新了dvisvgm4ht
驱动程序。可以在dvips
(默认)和dvisvgm
后端之间进行选择。dvisvgm
后端支持 TikZ 模式,但它无法处理一些复杂的图片,因此默认情况下不使用它。要选择它,请使用以下选项tikz+
:
make4ht -m draft filename.tex "tikz+"
原始答案:
该dvisvgm4ht
驱动程序内部使用了另一个驱动程序pgfsys-dvips.def
。它似乎不支持模式。它不使用pgfsys-dvisvgm4ht.def
,因为它没有正确记录图像尺寸,因此它们被设置为零。因此,即使 SVG 文件包含图形,也无法显示。
我终于找到了正确使用驱动程序并保持图像尺寸的方法dvisvgm
。这是新版本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:
与原始驱动程序的区别在于,它现在直接修补环境tikzpicture
,而不仅仅是修补内部 TikZ 驱动程序宏:
\AddToHook{env/tikzpicture/before}{\texfourht@tikz@begin}
\AddToHook{env/tikzpicture/after}{\texfourht@tikz@end}
缺点是它不适用于该\tikz
命令。
结果如下: