# why does latex report errors when using styles in a tikz pgf picture?

I get three errors when attempting to build the following example (with the tikzpicture taken from the tikz pgf manual). Why does this happen, and what am I doing wrong?

\documentclass[12pt]{article}

\usepackage{tikz}

\begin{document}

\begin{figure}

\begin{tikzpicture}

[Karl's grid/.style ={help lines,color=#1!50},
Karl's grid/.default=blue]

\draw[Karl's grid] (0,0) grid (1.5,2);

\draw[Karl's grid=red] (2,0) grid (3.5,2);

\end{tikzpicture}

\end{figure}

\end{document}


[Loading MPS to PDF converter (version 2006.09.02).]
\scratchcounter=\count107
\scratchdimen=\dimen148
\scratchbox=\box35
\nofMPsegments=\count108
\nofMParguments=\count109
\everyMPshowfont=\toks24
\MPscratchCnt=\count110
\MPscratchDim=\dimen149
\MPnumerator=\count111
\everyMPtoPDFconversion=\toks25
)
Missing character: There is no [ in font nullfont!
Missing character: There is no K in font nullfont!
Missing character: There is no a in font nullfont!
Missing character: There is no r in font nullfont!
Missing character: There is no l in font nullfont!
Missing character: There is no ' in font nullfont!
Missing character: There is no s in font nullfont!
Missing character: There is no g in font nullfont!
Missing character: There is no r in font nullfont!
Missing character: There is no i in font nullfont!
Missing character: There is no d in font nullfont!
Missing character: There is no / in font nullfont!
Missing character: There is no . in font nullfont!
Missing character: There is no s in font nullfont!
Missing character: There is no t in font nullfont!
Missing character: There is no y in font nullfont!
Missing character: There is no l in font nullfont!
Missing character: There is no e in font nullfont!
Missing character: There is no = in font nullfont!
Missing character: There is no h in font nullfont!
Missing character: There is no e in font nullfont!
Missing character: There is no l in font nullfont!
Missing character: There is no p in font nullfont!
Missing character: There is no l in font nullfont!
Missing character: There is no i in font nullfont!
Missing character: There is no n in font nullfont!
Missing character: There is no e in font nullfont!
Missing character: There is no s in font nullfont!
Missing character: There is no , in font nullfont!
Missing character: There is no c in font nullfont!
Missing character: There is no o in font nullfont!
Missing character: There is no l in font nullfont!
Missing character: There is no o in font nullfont!
Missing character: There is no r in font nullfont!
Missing character: There is no = in font nullfont!

! You can't use macro parameter character #' in restricted horizontal mode.
l.24     [Karl's grid/.style ={help lines,color=#
1!50},
Sorry, but I'm not programmed to handle this case;
I'll just pretend that you didn't ask for it.
If you're in the wrong mode, you might be able to
return to the right one by typing I}' or I\$' or I\par'.

Missing character: There is no 1 in font nullfont!
Missing character: There is no ! in font nullfont!
Missing character: There is no 5 in font nullfont!
Missing character: There is no 0 in font nullfont!
Missing character: There is no , in font nullfont!
Missing character: There is no K in font nullfont!
Missing character: There is no a in font nullfont!
Missing character: There is no r in font nullfont!
Missing character: There is no l in font nullfont!
Missing character: There is no ' in font nullfont!
Missing character: There is no s in font nullfont!
Missing character: There is no g in font nullfont!
Missing character: There is no r in font nullfont!
Missing character: There is no i in font nullfont!
Missing character: There is no d in font nullfont!
Missing character: There is no / in font nullfont!
Missing character: There is no . in font nullfont!
Missing character: There is no d in font nullfont!
Missing character: There is no e in font nullfont!
Missing character: There is no f in font nullfont!
Missing character: There is no a in font nullfont!
Missing character: There is no u in font nullfont!
Missing character: There is no l in font nullfont!
Missing character: There is no t in font nullfont!
Missing character: There is no = in font nullfont!
Missing character: There is no b in font nullfont!
Missing character: There is no l in font nullfont!
Missing character: There is no u in font nullfont!
Missing character: There is no e in font nullfont!
Missing character: There is no ] in font nullfont!

! Package pgfkeys Error: I do not know the key '/tikz/Karl's grid' and I am goi
ng to ignore it. Perhaps you misspelled it.

See the pgfkeys package documentation for explanation.
Type  H <return>  for immediate help.
...

l.27     \draw[Karl's grid]
(0,0) grid (1.5,2);
This error message was generated by an \errmessage
command, so I can't give any explicit help.
Pretend that you're Hercule Poirot: Examine all clues,
and deduce the truth by order and method.

! Package pgfkeys Error: I do not know the key '/tikz/Karl's grid' and I am goi
ng to ignore it. Perhaps you misspelled it.

See the pgfkeys package documentation for explanation.
Type  H <return>  for immediate help.
...

l.29     \draw[Karl's grid=red]
(2,0) grid (3.5,2);
(That was another \errmessage.)


I'm using tikz 2010/10/13 v2.10 (rcs-revision 1.76), and am using MikTex on Windows XP in conjunction with Texniccenter.

-

The problem is caused by the empty line after you opened the tikzpicture environment. Note, that an empty line usually means a paragraph break, so don't use it in the document code just because of readability. If you would like to use (nearly) empty lines for separation, set at least a % into the line to comment it out.

It works this way:

\begin{tikzpicture}
[Karl's grid/.style ={help lines,color=#1!50},
Karl's grid/.default=blue]

-
@crobar Also if you look at the error message it spells out a part of your code vertically. This can help you in the future to see that something is at a place where it's not supposed to be. –  percusse Jan 19 '12 at 10:59
Thanks everyone, this never occurred to me. –  crobar Jan 19 '12 at 16:05
@percusse I knew the error was first detected on the Karl's Grid line, but not what was causing it. –  crobar Jan 19 '12 at 16:16
If you insert a % into the line, can it be indented or does it have to be in the beginning of the line (i.e. no space or tab before it)? –  StrawberryFieldsForever Aug 21 '13 at 12:49