Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

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

plots

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.