当我使用make4ht index.tex "xhtml"
编译文件时
\documentclass{report}
\ifdefined\HCode
\def\pgfsysdriver{pgfsys-dvisvgm4ht.def}
\fi
\usepackage{tikz}
\begin{document}
\begin{figure}
\begin{center}
\begin{tikzpicture}
\draw (0,0) rectangle (3,3);
\end{tikzpicture}
\begin{tikzpicture}
\draw (0,0) rectangle (3,3);
\end{tikzpicture}
\end{center}
\caption{Test.\label{fig:test}}
\end{figure}
\end{document}
第二个矩形对应的 SVG 文件无法正确编译,因此无法渲染。如果我将两个矩形一个放在另一个下面而不是并排放置(通过在两个 TikZ 图片之间添加一个空白行)
\documentclass{report}
\ifdefined\HCode
\def\pgfsysdriver{pgfsys-dvisvgm4ht.def}
\fi
\usepackage{tikz}
\begin{document}
\begin{figure}
\begin{center}
\begin{tikzpicture}
\draw (0,0) rectangle (3,3);
\end{tikzpicture}
\begin{tikzpicture}
\draw (0,0) rectangle (3,3);
\end{tikzpicture}
\end{center}
\caption{Test.\label{fig:test}}
\end{figure}
\end{document}
pdflatex
然后一切都按预期工作。无论哪种情况,PDF 都可以正确编译。这是一个错误吗tex4ht
?司机dvisvgm
,还是我用的不正确?
答案1
这是驱动程序中的一个错误dvisvgm4ht
。它根据垂直模式使用不同的 TeX4ht 命令将 TeX 代码转换为图像。它应该在所有情况下运行相同的命令。以下是更新的版本:
% 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:
%
% we load the dvips driver by default. it doesn't support patterns and some other stuff,
% but it handles better nested images and some formatting. if you use patterns or if you
% have other issues with the default method, pass the "tikz-dvisvgm" option to make4ht.
\ifdefined\ifOption
\ifOption{tikz+}{\input pgfsys-dvisvgm.def}{\input pgfsys-dvips.def}
\else
% load the dvips driver by default
\input pgfsys-dvips.def
\fi
\def\texfourht@tikz@begin{%
\bgroup%
\def\run@pict@cmd{}% insert the \Picture hooks only in the top nesting level
\def\end@pict@cmd{}%
\ifdefined\EndPicture\else% We are already inside command that uses \Picture
\ifdefined\inside@pict@cmd% handle nested uses
\else
% use different version of \Picture depending on the vertical mode
\run@pict@cmd{\Picture*}%
\def\end@pict@cmd{\EndPicture}%
\fi\fi%
% command used to detect nesting
\def\inside@pict@cmd{}%
\csname a:tikzpicture\endcsname%
}
\def\texfourht@tikz@end{%
\csname b:tikzpicture\endcsname%
\egroup%
}
\AtBeginDocument{
\NewConfigure{tikzpicture}{2}
\catcode`\:=11
\Configure{tikzpicture}{%
\protect\csname nested:math\endcsname% support display math
\run@pict@cmd{}%
}{\end@pict@cmd}
% configure the output picture format to svg, as it will require dvisvgm
% post processing.
\Configure{Picture}{.svg}
% insert tex4ht hooks around TikZ picture box
\def\pgfsys@typesetpicturebox#1{%
\texfourht@tikz@begin%
\orig@pgfsys@typesetpicturebox{#1}%
\texfourht@tikz@end%
}
%
\ConfigureEnv{tikzpicture}{\Picture*{}\def\inside@pict@cmd{}}{\EndPicture}{}{}
\ConfigureEnv{pgfpicture}{\Picture*{}\def\inside@pict@cmd{}}{\EndPicture}{}{}
\catcode`\:=12
}
% Make the code inserted by tex4ht configurable
%
\let\orig@pgfsys@typesetpicturebox\pgfsys@typesetpicturebox
%\def\pgf@sys@postscript@header#1{{\special{! #1}}}
\endinput
%%% Local Variables:
%%% mode: latex
%%% End:
为了并排获取图形,请使用此配置文件:
\Preamble{xhtml}
\Css{figure.float img, figure.figure img {display: inline;}}
\begin{document}
\EndPreamble