Considering TikZ code:
\begin{tikzpicture}
\draw <a square>;
\draw <an elephant>;
\draw <a toaster>;
\end{tikzpicture}
I'd like to access the coordinates of a bounding box that surrounds the elephant and toaster but that ignores the square, which must be drawn before the elephant and toaster since certain coordinates in the elephant and toaster rely on current bounding box
, and this bounding box must include the square.
The problem is that the elephant and toaster are actually complex procedures that draw and fill many TikZ paths, create many nodes, etc., and these procedures are (generally speaking) unable to report back their topmost, leftmost, etc. coordinates. Hence what is needed is a facility:
\begin{tikzpicture}
\draw <a square>;
<do something here to mark start of scope>
\draw <an elephant>;
\draw <a toaster>;
<do something here to mark end of scope>
\draw[red] ($(scoped bounding box.south west) - (2mm,2mm)$)
rectangle ($(scoped bounding box.north east) + (2mm,2mm)$);
\end{tikzpicture}
to draw a red box around the elephant and toaster (with a 2mm inner margin) where scoped bounding box
works exactly like current bounding box
except that it only considers the objects drawn by code between the designated start and end of scope.
I don't require this specific syntax, setup, or command order. Anything that yields the coordinates for the "partial" bounding box in a format that can be used in TikZ point arithmetic will suffice, with the lone caveat being that whatever code is injected must not alter the coordinate frames or style options of commands in the subroutines to render the elephant and toaster. Also, it would be greatly preferred if the none of the code in the elephant and toaster subroutines needed to be altered, although I understand this may be necessary.