The code below works fine
\begin{tikzpicture}
\begin{axis}
[
ticks = none, axis lines = middle,
xmin = -5, xmax = 5,
ymin = -5, ymax = 5,
]
\foreach \p in {1,2}{
\draw[red] (-5,1)--(5,1);
}
\end{axis}
\end{tikzpicture}
However, as soon as I try to use the variable \p inside the loop, as in
\begin{tikzpicture}
\begin{axis}
[
ticks = none, axis lines = middle,
xmin = -5, xmax = 5,
ymin = -5, ymax = 5,
]
\foreach \p in {1,2}{
\draw[red] (-5,\p)--(5,\p);
}
\end{axis}
\end{tikzpicture}
I get an undefined control sequence error. This persists no matter what I use instead of \p.
