# Use variable in domain of a plot in tikz

Consider the following example:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{calc,patterns,decorations.pathmorphing,decorations.markings}

\begin{document}
\begin{tikzpicture}
\foreach \t in {0,...,10} {
\pgfmathparse{8/10*\t};
\draw[color=red,domain=0:\pgfmathresult] plot (\x,{0.5*sin(2*pi*\t/10 r - 0.25*pi*\x r) - 2*\t});

}
\end{tikzpicture}
\end{document}


The point is, that I want use the variable \pgfmathresult in the domain of the plot. However it gives me TeX capacity exceeded, sorry. Any idea how to solve this?

-

## 2 Answers

First of all, the first plot is over the domain [0,0]. This causes problems. To see this, try (within a tikzpicture) :

\draw[domain=0:0] plot (\x,\x);


Start with 1 instead of 0 for the initial value of \t.

Next, to use computed values within other tikz commands, try using \pgfmathsetmacro :

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{calc,patterns,decorations.pathmorphing,decorations.markings}

\begin{document}
\begin{tikzpicture}

\foreach \t in {1,...,10} {
\pgfmathsetmacro{\sup}{8/10*\t}
\draw[color=red,domain=0:\sup] plot (\x,{0.5*sin(2*pi*\t/10 r - 0.25*pi*\x r) - 2*\t});
}
\end{tikzpicture}
\end{document}


The output is

-

Generally speaking, it is unwise to use \pgfmathresult directly in a TikZ invocation, because by the time TikZ parses that part, it might already be overwritten. However this is not the problem here. TikZ actually chokes on domain=0:0 when \t is 0. Starting the \foreach with 1 it works.

-