Why does the following not compile?

The following compiles well in TeXShop on one of my Mac computer (an old one), but produces error on another one. I must have forgot to install something on the new computer, but cannot figure out what. Any ideas?

  \begin{tikzpicture}
\draw[very thin,color=gray] (1,1) ;
\foreach \x/\xtext in {0.3/a, 1.58/c, 2*pi/b}
\draw[shift={(\x,0)}] (0pt,2pt) -- (0pt,-2pt) node[below] {$\xtext$};
\draw[->] (-0.2,0) -- (9,0) node[right] {$x$};
\draw[->] (0,-0.2) -- (0,4.5) node[above] {$y$};
\draw plot[domain=0.3:2*pi]
(\x, 0.5+{0.5*(\x)+sin((\x) r)}) node[above right] {$f$};
\draw[-] [dotted]
(0.3,0.5+{0.5*(0.3)+sin((0.3) r)})--(2*pi, 0.5+{pi+sin(2*pi r)}) ;
\node at (pi/2, 0.5+{0.25*pi+1}){$\bullet$};
\draw[-] [draw=red]plot[domain=0.2:pi]
(\x, {0.5+{0.25*pi+1}+0.5*(\x-pi/2)}) node[above]  {$f'(c)={f(b)-f(a)\over b-a}$};
\end{tikzpicture}


Error Message:

<to be read again>
{
l.23 ...0.3:2*pi] (\x, 0.5+{0.5*(\x)+sin((\x) r)})
node[above right] {$f$};

-
Do you have the same version of all the packages used? Put \listfiles before \begin{document} to get a list of all the packages and their versions. I had a problem like this caused by out of date packages on a separate OS. –  Nathanael Farley Jan 12 '13 at 17:32
This is useful. Thank you! –  user24320 Jan 12 '13 at 18:19

Your code has some syntax errors with the grouping of math expressions; here's a corrected version:

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
%\draw[very thin,color=gray] (1,1) ;
\foreach \x/\xtext in {0.3/a, 1.58/c, 2*pi/b}
\draw[shift={(\x,0)}] (0pt,2pt) -- (0pt,-2pt) node[below] {$\xtext$};
\draw[->] (-0.2,0) -- (9,0) node[right] {$x$};
\draw[->] (0,-0.2) -- (0,4.5) node[above] {$y$};
\draw plot[domain=0.3:2*pi]
(\x,{0.5 + 0.5*\x + sin((\x) r)}) node[above right] {$f$};
\draw[-] [dotted]
(0.3,{0.5+0.5*(0.3)+sin((0.3) r)})--(2*pi,{0.5+pi+sin(2*pi r)}) ;
\node at (pi/2, {0.5+ 0.25*pi+1}){$\bullet$};
\draw[-] [draw=red]plot[domain=0.2:pi]
(\x, {0.5+0.25*pi+1+0.5*(\x-pi/2)}) node[above]  {$f'(c)={f(b)-f(a)\over b-a}$};

\end{tikzpicture}

\end{document}


-
I think there is one more problem with the foreach loop. It should end somewhere before the plot is drawn. As it is, the curve is drawn multiple times. Probably only the first line belongs to the loop. –  percusse Jan 12 '13 at 17:51
@percusse you're right; I've corrected the code. Thank you! –  Gonzalo Medina Jan 12 '13 at 18:03
Perfect! Thanks for the quick fix (I worked it on it long).Your code works well. I did not have pgfplots before. (When I put your modified code into my longer tex file, it produces a hitch, but then will run smoothly after a return key. The complaint is about new dim) But I'll work from here.This has been a real help. –  user24320 Jan 12 '13 at 18:12