LaTeXML
LaTeXML copied to clipboard
TikZ bounding box is not respected
Using \useasboundingbox does not achieve the desired result. In TikZ, that command sets a bounding box (\pgf@picminx etc) and stops updating it to accommodate new paths that go past the boundary. Strangely enough, LaTeXML keeps enlarging the bounding box anyway. For now, the only (?) way to get the correct bounding box is to run \pgfresetboundingbox at the end, followed by the desired \useasboundingbox.
(This has actual consequences. For example, if a figure is clipped to a small bounding box, LaTeXML will clip correctly but leave a big bounding box, resulting in lots of empty space.)
Ugly example where the two figures should be identical:
\documentclass{article}
\usepackage{tikz}
\begin{document}
text before:
\begin{tikzpicture}
\pgfresetboundingbox
\useasboundingbox (0,0) rectangle (3,2);
\draw[blue, very thick] (0,0) rectangle (3,2);
\draw[green, very thick] (-2,-2) rectangle (4,3);
\end{tikzpicture}
:text after
text before:
\begin{tikzpicture}
\draw[blue, very thick] (0,0) rectangle (3,2);
\draw[green, very thick] (-2,-2) rectangle (4,3);
\pgfresetboundingbox
\useasboundingbox (0,0) rectangle (3,2);
\end{tikzpicture}
:text after
\end{document}
HTML:
PDF:
Found the culprit: https://github.com/brucemiller/LaTeXML/blob/c3d682e1e103fa99adefff1749c477fb99cb1d9d/lib/LaTeXML/Package/pgf.sty.ltxml#L40-L43 Deleting those lines fixes the issue.
Oh, it would be great if all it takes is dropping some old lines from the initial pgf binding work!