Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TikZ bounding box is not respected #2399

Open
xworld21 opened this issue Aug 18, 2024 · 2 comments · May be fixed by #2401
Open

TikZ bounding box is not respected #2399

xworld21 opened this issue Aug 18, 2024 · 2 comments · May be fixed by #2401

Comments

@xworld21
Copy link
Contributor

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

PDF:
image

@xworld21
Copy link
Contributor Author

Found the culprit:

# This makes this conditional always true; Why???
DefConditionalI('\ifpgf@relevantforpicturesize', undef, sub { 1; });
DefMacroI('\pgf@relevantforpicturesizefalse', undef, '');
DefMacroI('\pgf@relevantforpicturesizetrue', undef, '');

Deleting those lines fixes the issue.

@dginev
Copy link
Collaborator

dginev commented Aug 18, 2024

Oh, it would be great if all it takes is dropping some old lines from the initial pgf binding work!

@xworld21 xworld21 linked a pull request Aug 18, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants