1

When I use make4ht index.tex "xhtml" to compile the file

\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}

the SVG file corresponding to the second rectangle does not compile correctly, so it is not rendered. If I place the two rectangles one below the other instead of side by side (by adding a blank line between the two TikZ pictures)

\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}

then everything works as expected. The PDF compiles correctly using pdflatex in either case. Is this a bug, either in tex4ht or in the dvisvgm driver, or am I not using it right?

1 Answer 1

2

This is a bug in the dvisvgm4ht driver. It uses different TeX4ht commands for converting TeX code to images depending on the vertical mode. It should run the same command in all cases. Here is the updated version:

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

To get the figures side by side, use this configuration file:

\Preamble{xhtml}
\Css{figure.float img, figure.figure img {display: inline;}}
\begin{document}
\EndPreamble

This is the result: enter image description here

2
  • That fixes it, but now these are not side by side like they are in the pdf. I suppose I have to force that using minipages?
    – Rushi
    Oct 17, 2021 at 21:51
  • 1
    @Rushi no, just simple CSS is needed. See the edited answer.
    – michal.h21
    Oct 18, 2021 at 7:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .