0

I am getting an undefined control sequence when using \col in a \foreach loop.

! Undefined control sequence.
\pgfkeyscurrentkey ->\col

\documentclass[tikz, dvipsnames]{standalone}
\usepackage{mathtools}
\usepackage{pgfplots}
\pgfplotsset{compat = 1.8}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[
    samples = 500,
    no marks,
    xlabel = $\scriptstyle x$,
    ylabel = $\scriptstyle y$
    ]
    \foreach \u/\col in {1/red, 2/blue, 3/OliveGreen}{
      \addplot+[\col, domain = -4:4, variable = \v]
      ({(exp(\u) + exp(-\u)) / 2 * cos(deg(v))},
      {(exp(\u) - exp(-\u)) / 2 * sin(deg(v))});
    }
  \end{axis}
\end{tikzpicture}
\end{document}

And also, how can I use \addlegendentry for the plot with a loop?

6
  • 1
  • 1
    As a work-around: \expandafter\addplot\expandafter+\expandafter[\col, dom…. pgfplots doesn’t process the content linear but firstly collects everything and then evaluates it. At this point \col isn’t defined anymore. Sep 5, 2013 at 21:40
  • @Qrrbrbirlbel thanks that worked. Do you know how I can use \addlegenentry when using \foreach? This part of the question is located below the code.
    – dustin
    Sep 5, 2013 at 21:44
  • 1
    @dustin You can use \addlegendentryexpanded{$u =\u$} instead of \addlegendentry. Same problem, different solution. Sep 5, 2013 at 21:46
  • @percusse I using Qrrbrbirlbel answer which isn't part of that thread.
    – dustin
    Sep 6, 2013 at 2:18

0

Browse other questions tagged .