samcarter
I would like to use a `path picture` for all paths in a `tikzpicture`. If I manually add the `path picture` to all `\path`s, things work as expected.
Now I'm wondering if this can be automated. Naively, I tried to add the path picture via `every path/.style={...}`, but this tries to insert the image a lot more often than the three `\path`s in the `tikzpicture` and ultimately results in:
```
! TeX capacity exceeded, sorry [grouping levels=255].
<to be read again>
{
l.32 \path (0,0) rectangle ++(1,1);
```
So I guess it goes into a loop when it tried to use paths to draw the path picture?
Is there any other way to apply a `path picture` to every `\path` (there are no `\node`s or other elements in this `tikzpicture`)?
---
### Test document:
```
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
% working
\begin{tikzpicture}[
quack/.style={
path picture={%
\node[anchor=south west,inner sep=0pt] at (0,0) {\includegraphics[width=3cm,height=3cm]{example-grid-100x100bp}};
}
}
]
\path[quack] (0,0) rectangle ++(1,1);
\path[quack] (1,1) rectangle ++(1,1);
\path[quack] (2,2) rectangle ++(1,1);
\end{tikzpicture}
% working
\begin{tikzpicture}[every path/.style={draw=red}]
\path (0,0) rectangle ++(1,1);
\path (1,1) rectangle ++(1,1);
\path (2,2) rectangle ++(1,1);
\end{tikzpicture}
% problem
\begin{tikzpicture}[every path/.style={
path picture={%
\node[anchor=south west,inner sep=0pt] at (0,0) {\includegraphics[width=3cm,height=3cm]{example-grid-100x100bp}};
}
}]
\path (0,0) rectangle ++(1,1);
\path (1,1) rectangle ++(1,1);
\path (2,2) rectangle ++(1,1);
\end{tikzpicture}
\end{document}
```
### Desired result:
![document-1.png](/image?hash=df9b740140244efc557613952554a6b8c55d940d186f19837d93611c02657a7c)
Top Answer
frougon
The problem seems to arise from infinite recursion due to the `every path` style drawing paths which cause the `every path` style to be executed, which draws more paths, etc.
You can prevent said recursion by defining the `every path` style in such a way that it clears itself before drawing its own paths:
```
\documentclass[tikz,border=1mm]{standalone}
\usepackage{graphicx}
\begin{document}
\begin{tikzpicture}[
every path/.style={
every path/.style={},
path picture={
\node[anchor=south west,inner sep=0pt] at (0,0)
{\includegraphics[width=3cm,height=3cm]{example-grid-100x100bp}};
}
}]
\path (0,0) rectangle ++(1,1);
\path (1,1) rectangle ++(1,1);
\path (2,2) rectangle ++(1,1);
\end{tikzpicture}
\end{document}
```
![docu.png](/image?hash=4886587032b6357a585aa734175a3875e8830443244497c164dedd5e94980ed0)