When I make a TikZ picture, I sometimes use absolute coordinates, and when I do, I find Martin Scharrer's showgrid TikZ library very handy. (It lays "graph paper" underneath my canvas, and puts numbers along the edges.)
Here's a bit of code to illustrate that. (Note that the showgrid library has to be downloaded from Martin's website.)
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{showgrid} % http://latex.scharrer-online.de/general/wiki/showgrid
\begin{document}
\begin{tikzpicture}[show grid=all]
\draw (3,2) -- +(45:3);
\end{tikzpicture}
\end{document}
What I would like is to have a custom environment that takes a draw guides option. When draw guides is set, various debugging aids will be drawn (such as the names of nodes), and show grid=all will be activated.
The code below shows my attempt to do this. It doesn't work, and I think the problem might be to do with the fact that the show grid key resides in the /tikz/ directory, but draw guides resides in the /wickerson/ directory. I've tried to cd into that directory at the opportune time, but it doesn't seem to have helped.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{showgrid} % http://latex.scharrer-online.de/general/wiki/showgrid
\pgfkeys{/wickerson/.cd,
draw guides/.code = {%
% here do some other stuff, like enabling
% the printing of node names
\pgfkeys{/tikz/.cd,show grid=all}}
}
\newenvironment{wickersonpicture}[1][]{%
\pgfkeys{/wickerson/.cd,#1}
% do some stuff
\begin{tikzpicture}
}{%
\end{tikzpicture}
}
\begin{document}
\begin{wickersonpicture}[draw guides]
\draw (3,2) -- +(45:3);
\end{wickersonpicture}
\end{document}

show grid=allkey must be set for thetikzpicture: If you change your\pgfkeys{/tikz/.cd,show grid=all}line to\tikzset{every picture/.append style={show grid=all}}, it works as desired. (Note that\tikzset{...}is equivalent to\pgfkeys{/tikz/.cd,...}). Martin himself might be able to provide a more qualified answer, though. – Jake May 28 '13 at 16:39tikzpicture". Well, that seems to have fixed it. Do feel free to make an answer if you so wish. – John Wickerson May 28 '13 at 16:42\newenvironment{wickersonpicture}[1][]{% \begin{tikzpicture}[/wickerson/.cd,#1] }{% \end{tikzpicture} }should work. Of course supposing that you have a given set of keys under your personal path and the user is not allowed to enter keys from other paths (but with since there's also a custom environment the supposition should be valid). – Claudio Fiandrino May 28 '13 at 16:42wickersonpictureenvironment. It would only make sense to pass thedraw guideskey to thetikzpictureenvironment. – John Wickerson May 28 '13 at 16:46wickersonpictureenvironment only a wrapper for thetikzpictureenvironment, or does other stuff happen in\begin{wickersonpicture}? – Jake May 28 '13 at 16:58