# Missing \$ error

Why doesn't this code compile?

% Oxidation and reduction
% Author: Arne Röhrs
% Note that two compilations are necessary.
\documentclass{article}

\usepackage{tikz}
\usepackage[version=3,arrows=pgf]{mhchem}
\begin{document}

% Insert a named coordinate for later reference.
% Usage:
% \ncoord{name}
% \ncoord[1em,2em]{name}
\newcommand\ncoord[2][0,0]{%
\tikz[remember picture,overlay]{\path (#1) coordinate (#2);}%

}

% Define a handful of special cases of \ncoord
\newcommand\ccoord[1]{\ncoord[0.5em,0.9em]{#1}}%
\newcommand\bcoord[1]{\ncoord[0.4em,-0.3em]{#1}}%

\newcommand\dcoord[1]{\ncoord[0.9em,1.5em]{#1}}%
\newcommand\ecoord[1]{\ncoord[0.9em,-0.3em]{#1}}%

\tikzset{
oxidation/.style={thick,red!80!black},
reduction/.style={thick,blue!80!black},
}

~

% First reaction
$\ce{{\ccoord{a}} Na + {\bcoord{c}} Cl -> {\ccoord{b}} Na+ + {\bcoord{d}} Cl-}$
\tikz[overlay,remember picture] {
\draw[oxidation,->] (a) -- ++(0,0.7em) -| (b)
node[above, near start] {Oxidation};
\draw[reduction,->] (c) -- ++(0,-0.7em) -| (d)
node[below, near start] {Reduktion};

}
\$0.5cm] % add some extra vertical spacing % Second reaction \[ \ce{% {\dcoord{a}} \overset{\text{0}}{\text{2\,Na}} +{\ecoord{c}}\overset{\text{0}}{\text{Cl_2}} -> {\dcoord{b}} \overset{\text{+I}}{\text{2\,Na^+}} + {\ecoord{d}} \overset{\text{-I}}{\text{2\,Cl^-}}}$
\tikz[overlay,remember picture] {
\draw[oxidation,->] (a) -- ++(0,0.7em) -| (b)
node[above, near start] {Oxidation};
\draw[reduction,->] (c) -- ++(0,-0.7em) -| (d)
node[below, near start] {Reduktion};

}

\end{document}

-
Your example is not minimal. Try to make it as short as possible and still demonstrate the problem you're having. As to what is minimal working example (MWE), see this: meta.tex.stackexchange.com/questions/228/… – Martin Tapankov May 14 '11 at 6:18

do not use empty lines in definitions!

\newcommand\ncoord[2][0,0]{%
\tikz[remember picture,overlay]{\path (#1) coordinate (#2);}}


or at least

\newcommand\ncoord[2][0,0]{%
\tikz[remember picture,overlay]{\path (#1) coordinate (#2);}%
}

-
I'd looked at a lot of the blank lines and removed them, but I'd missed this one. (I had a feeling they are the issue). – Joseph Wright May 14 '11 at 6:39
Thanks Herbert; I hadn't realised it mattered. I always wondered why people put a % at the end of the line. – ptrcao May 14 '11 at 7:05