Skip to content

Commit

Permalink
Update pgfsys-dvisvgm4ht.def
Browse files Browse the repository at this point in the history
- fixed support for the inline \tikz command
- added support for the alt text
  • Loading branch information
michal-h21 authored and hansonchar committed Nov 6, 2024
1 parent 3812227 commit 84284bf
Showing 1 changed file with 39 additions and 50 deletions.
89 changes: 39 additions & 50 deletions tex/generic/pgf/systemlayer/pgfsys-dvisvgm4ht.def
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Copyright 2021 by Michal Hoftich
% Copyright 2021-2024 by Michal Hoftich
% Copyright 2006 by Till Tantau
%
% This file may be distributed and/or modified
Expand All @@ -16,66 +16,55 @@
% 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.
% we switched to dvisvgm driver by default. it supports patterns and other features
% dvips driver is available through the tikz+ option. It doesn't support everything,
% but it worked better with nested pictures in the past.
\ifdefined\ifOption
\ifOption{tikz+}{\input pgfsys-dvisvgm.def}{\input pgfsys-dvips.def}
\ifOption{tikz+}{\input pgfsys-dvips.def}{\input pgfsys-dvisvgm.def}
\else
% load the dvips driver by default
\input pgfsys-dvips.def
\input pgfsys-dvisvgm.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\else% handle nested uses
\ifdefined\tikzexternalize\else% Support externalize library
\def\run@pict@cmd{\Picture*}%
\def\end@pict@cmd{\EndPicture}%
\fi\fi\fi%
% command used to detect nesting
\def\inside@pict@cmd{}%
\csname a:tikzpicture\endcsname%
}

\def\texfourht@tikz@end{%
\csname b:tikzpicture\endcsname%
\egroup%
}
\catcode`\:=11%

% we must call most of these redefinitions in \AtBeginDocument, because \HLet is available
% only at that moment
\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}{\texfourht@tikz@begin}{\texfourht@tikz@end}{}{}%
\ConfigureEnv{pgfpicture}{\texfourht@tikz@begin}{\texfourht@tikz@end}{}{}%
\catcode`\:=12%
% configure the output picture format to svg, as it will require dvisvgm
% post processing.
\Configure{Picture}{.svg}%

% insert picture hooks to pgfsys commands
% these redefinitions are usually called only with the \tikz command,
% they are ignored in tikzpicture environment
\def\:tempa#1{%
\texfourht@tikz@begin%
\csname o:pgfsys@typesetpicturebox:\endcsname{#1}
\texfourht@tikz@end%
}
\HLet\pgfsys@typesetpicturebox\:tempa

% we must remove Picture-alt in \pgfsys@beginpicture, because it can result in alt text included in the image
\def\:tempa{\Configure{Picture-alt}{}\texfourht@tikz@begin\o:pgfsys@beginpicture:}
\HLet\pgfsys@beginpicture\:tempa
\let\o:pgfsys@endpicture:\pgfsys@endpicture
\def\:tempa{\o:pgfsys@endpicture:}
\HLet\pgfsys@endpicture\:tempa

% start picture around TikZ and PGF environments
\ConfigureEnv{tikzpicture}{\begingroup\texfourht@tikz@begin}{\texfourht@tikz@end\endgroup}{}{}%
\ConfigureEnv{pgfpicture}{\begingroup\texfourht@tikz@begin}{\texfourht@tikz@end\endgroup}{}{}%
}

\def\texfourht@tikz@begin{
\protect\csname nested:math\endcsname% support display math
\Picture+[\csname a:Picture-alt\endcsname]{}%
}
\def\texfourht@tikz@end{\EndPicture}

% Make the code inserted by tex4ht configurable
%


\let\orig@pgfsys@typesetpicturebox\pgfsys@typesetpicturebox
%\def\pgf@sys@postscript@header#1{{\special{! #1}}}
\catcode`\:=12%


\endinput
Expand Down

0 comments on commit 84284bf

Please sign in to comment.