5

In the following tikzpicture why does the commented-out line not work instead of the line that follows it? If I uncomment that line and comment out the line following it, I get error in line 16, "Missing number, treated as zero.

                   \pgf@size@hook@x
l. 16 \path[spath/use=pathX];

Here's the code:

\documentclass[tikz,border=0pt]{standalone}
\usetikzlibrary{calc,spath3}
\begin{document}

\begin{tikzpicture}

\coordinate (X1) at (0,0);
\coordinate (X2) at (2,2);
\coordinate (X3) at (4,1);
\coordinate (X4) at (3,-1);
\coordinate (X5) at (1,-1.5);
\path[spath/save=pathX,smooth cycle,tension=1] (X1) to[out=90,in=180] (X2) to[out=0,in=90] (X3) to[out=270,in=90] (X4) to[out=270,in=0] (X5) to [out=180,in=270] cycle;
\begin{scope}[local bounding box=regionX]
    %\path[spath/use=pathX]; % WHY NOT THIS INSTEAD OF NEXT LINE?
    \path (X1) to[out=90,in=180] (X2) to[out=0,in=90] (X3) to[out=270,in=90] (X4) to[out=270,in=0] (X5) to [out=180,in=270] cycle;
\end{scope}

\draw[thick,red] (regionX.west |- 0,-2) -- (regionX.south east |- 0,-2);

\filldraw[spath/use=pathX];
\end{tikzpicture}

\end{document}
1
  • 1
    I've adjusted your title to reflect what the core problem is to aid searching. Hope that's okay. Commented May 28 at 22:39

1 Answer 1

6

sigh, it's a bug.

There is a command \pgf@protocolsizes which PGF uses to adjust the bounding box of a path. It takes two arguments, an x-coordinate and a y-coordinate, and adjusts the bounding box to ensure that the point with those coordinates is inside the path.

When local bounding box is in force then it also does a bit of extra work to ensure that the local bounding box is updated.

When a path is inserted via the spath3 library then the spath3 library has to feed appropriate coordinates to this command to ensure that the inserted path adjusts the bounding box(es) appropriately. I'd assumed that I could just feed the two coordinates to the \pgf@protocolsizes command as values to its arguments. And that worked.

Except I hadn't tested it with local bounding box in force. For the path bounding box then passing the coordinates as values was fine. But the extra stuff requires them to be passed as lengths (or dims).

It's not hard to fix, and I've fixed it (and will upload it to github momentarily). If you'd rather not download the latest version, fixing it in-file is okay:

\documentclass[tikz,border=0pt]{standalone}
%\url{https://tex.stackexchange.com/q/719125/86}
\usetikzlibrary{calc,spath3}

\makeatletter
\ExplSyntaxOn
\cs_set_protected_nopar:Npn \spath_protocol_path:n #1
{
  \spath_minbb:Nn \l__spath_tmpa_tl {#1}
  \dim_set:Nn \l__spath_tmpa_dim {\tl_item:Nn \l__spath_tmpa_tl {1}}
  \dim_set:Nn \l__spath_tmpb_dim {\tl_item:Nn \l__spath_tmpa_tl {2}}
  \pgf@protocolsizes\l__spath_tmpa_dim\l__spath_tmpb_dim

  \spath_maxbb:Nn \l__spath_tmpa_tl {#1}
  \dim_set:Nn \l__spath_tmpa_dim {\tl_item:Nn \l__spath_tmpa_tl {1}}
  \dim_set:Nn \l__spath_tmpb_dim {\tl_item:Nn \l__spath_tmpa_tl {2}}
  \pgf@protocolsizes\l__spath_tmpa_dim\l__spath_tmpb_dim
}
\cs_generate_variant:Nn \spath_protocol_path:n {V}
\ExplSyntaxOff
\makeatother

\begin{document}
\begin{tikzpicture}

\coordinate (X1) at (0,0);
\coordinate (X2) at (2,2);
\coordinate (X3) at (4,1);
\coordinate (X4) at (3,-1);
\coordinate (X5) at (1,-1.5);
\path[spath/save=pathX,smooth cycle,tension=1] (X1) to[out=90,in=180] (X2) to[out=0,in=90] (X3) to[out=270,in=90] (X4) to[out=270,in=0] (X5) to [out=180,in=270] cycle;
\begin{scope}[local bounding box=regionX]
\message{this path}
\path[spath/use=pathX]; % WHY NOT THIS INSTEAD OF NEXT LINE?
\message{that path}
%    \path (X1) to[out=90,in=180] (X2) to[out=0,in=90] (X3) to[out=270,in=90] (X4) to[out=270,in=0] (X5) to [out=180,in=270] cycle;
\end{scope}

\draw[thick,red] (regionX.west |- 0,-2) -- (regionX.south east |- 0,-2);

\message{this path}
\filldraw[spath/use=pathX];
\message{that path}
\end{tikzpicture}

\end{document}
3
  • Yes, that works around the bug. So glad I wasn't misunderstanding the syntax and semantics of local bounding box or spath3!
    – murray
    Commented May 29 at 1:24
  • When will the fixed version of spath3 be available via TeXLive on CTAN?
    – murray
    Commented May 29 at 14:53
  • It's now on CTAN. It should be on TeXLive shortly - if it isn't already there. Commented Jun 1 at 18:43

You must log in to answer this question.

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