loopspace / spath3

TikZ/PGF package for manipulating soft paths, includes the knots and calligraphy TikZ libraries.
16 stars 2 forks source link

Path that is saved to aux file is not set global and empty. #21

Closed Qrrbrbirlbel closed 1 year ago

Qrrbrbirlbel commented 1 year ago

Consider the following document.

\documentclass[border=5pt, tikz]{standalone}
\usetikzlibrary{spath3}
\begin{document}
\begin{tikzpicture}
  \fill[left color=blue, right color=green] (0,0) rectangle (2,1);
  \draw[spath/use=box];
  \draw (0,0) -- (2,1);
  \path[spath/save=box] (0.5, 0) rectangle (1.5, 1);
  \tikzset{spath/save to aux=box}
\end{tikzpicture}
\end{document}

This will save the following to the aux file (line formatted, of course).

\ExplSyntaxOn
\tl_clear_new:N \tikz@intersect@path@name@box
\tl_set:Nn \tikz@intersect@path@name@box {
  \pgfsyssoftpath@movetotoken {14.22636pt}{0.0pt}
  \pgfsyssoftpath@movetotoken {14.22636pt}{0.0pt}
  \pgfsyssoftpath@linetotoken {14.22636pt}{28.45274pt}
  \pgfsyssoftpath@linetotoken {42.67911pt}{28.45274pt}
  \pgfsyssoftpath@linetotoken {42.67911pt}{0.0pt}
  \pgfsyssoftpath@closepathtoken {14.22636pt}{0.0pt}
  \pgfsyssoftpath@movetotoken {42.67911pt}{28.45274pt}
}
\ExplSyntaxOff 

However, the log file will contain

Package spath3 Warning: Soft path box is empty on line 11

even after the second compilation.

And indeed, \tikz@intersect@path@name@box is empty (not undefined because \tl_clear_new:N makes sure the tl exists globally).

With the following patch to \spath_save_to_aux:Nn where everything is done globally, it works as I expected it to. (The first patch is maybe not even necessary because even \tl_clear_new:N makes sure the tl exists globally but this is too deep into L3 territory for me …)

\documentclass[border=5pt, tikz]{standalone}
\usetikzlibrary{spath3}
\usepackage{etoolbox}
\ExplSyntaxOn
\patchcmd \spath_save_to_aux:Nn { \tl_clear_new:N }{ \tl_gclear_new:N }{}{} % L1682
\patchcmd \spath_save_to_aux:Nn { \tl_set:Nn      }{ \tl_gset:Nn      }{}{} % L1683
\ExplSyntaxOff
\begin{document}
\begin{tikzpicture}
  \fill[left color=blue, right color=green] (0,0) rectangle (2,1);
  \draw[spath/use=box];
  \draw (0,0) -- (2,1);
  \path[spath/save=box] (0.5, 0) rectangle (1.5, 1);
  \tikzset{spath/save to aux=box}
\end{tikzpicture}
\end{document}

For reference:

https://github.com/loopspace/spath3/blob/bb6dc5037c9cb63a9c1ef59f6c973acdac9da5d8/spath3_code.dtx#L1676-L1690


I don't know much about the aux file but it looks like LaTeX usually \gdefs stuff there which makes me think global definition is needed and it works the way I did it in this answer on TeX.SE before I realized, spath3 has save to aux.

loopspace commented 1 year ago

You're right, looking at latex.ltx then there are the lines:

\begingroup\@floatplacement\@dblfloatplacement
    \makeatletter\let\@writefile\@gobbletwo
    \global \let \@multiplelabels \relax
    \@input{\jobname.aux}%
  \endgroup

so the aux file is read while within a group. The clearing and setting should therefore both be global. The \tl_clear_new:N doesn't strictly have to be global, but LaTeX3 tries to avoid mixing local and global with the same variable so gclear is better.

loopspace commented 1 year ago

594a13e