Correct use of arguments pattern in pgfkeys/append after command in tikz?

I could not find many examples for the correct use of arguments patterns in pgfkes, but I was able to come up with the following:

\documentclass{standalone}
\usepackage{tikz}

\tikzset{dimen/.style={<->,>=latex,thin,
every rectangle node/.style={fill=white,midway}
}}

\tikzset{measuring south/.style args={from #1 to #2 is #3}{
append after command={
draw (#1.south west) -- ++(0,-1.0)
coordinate (A1) -- ++(0,-10pt)
(#2.south east) -- ++(0,-1.0) coordinate (A2) -- ++(0,-10pt)
[dimen] (A1) -- (A2) node {#3}
}
}
}

\begin{document}
\begin{tikzpicture}
\node(a)  [draw,rectangle,text=teal] at (0,0) {here};
\node(b)  [draw,rectangle,text=olive] at (3,0) {there};
\path[measuring south=from here to there is far,fill=red];

\node(x) [draw,rectangle,text=blue] at (0,-2) {Heaven};
\node(y) [draw,rectangle,text=red] at (3,-2) {Hell};
\draw (x.south west) -- ++(0,-1.0)
coordinate (A1) -- ++(0,-10pt)
(y.south east) -- ++(0,-1.0) coordinate (A2) -- ++(0,-10pt)
[dimen] (A1) -- (A2) node {sin};
\end{tikzpicture}
\end{document}


In my output, I would have liked to see the dimension lines from "here" to "there", but these are not visible.

-

From the TikZ/PGF manual (emphasis added):

Some of the path commands described in the following sections take optional arguments. For these commands, when you use this key inside these options, the path will be inserted after the path command is done.

The key here is the "some". The append after command needs a command to be appended after. Things that work are node, edge, to, and likewise. Your \path has no commands and so there is no chance of the append after command being executed. What you want here is the insert path key which sticks in the path at that point. Once you change that, then you get some output but you also find a few other (small) errors: you didn't name the nodes here and there, the fill=red command is a little odd, and the draw needs to be in brackets to be interpreted as a style.

\documentclass{article}
%\url{http://tex.stackexchange.com/q/154155/86}
\usepackage{tikz}

\tikzset{dimen/.style={<->,>=latex,thin,
every rectangle node/.style={fill=white,midway}
}}

\tikzset{measuring south/.style args={from #1 to #2 is #3}{
insert path={
[draw] (#1.south west) -- ++(0,-1.0)
coordinate (A1) -- ++(0,-10pt)
(#2.south east) -- ++(0,-1.0) coordinate (A2) -- ++(0,-10pt)
[dimen] (A1) -- (A2) node {#3}
}
}
}

\begin{document}
\begin{tikzpicture}
\node(a)  [draw,rectangle,text=teal] at (0,0) (here) {here};
\node(b)  [draw,rectangle,text=olive] at (3,0) (there) {there};
\path[measuring south=from here to there is far];

\node(x) [draw,rectangle,text=blue] at (0,-2) {Heaven};
\node(y) [draw,rectangle,text=red] at (3,-2) {Hell};
\draw (x.south west) -- ++(0,-1.0)
coordinate (A1) -- ++(0,-10pt)
(y.south east) -- ++(0,-1.0) coordinate (A2) -- ++(0,-10pt)
[dimen] (A1) -- (A2) node {sin};
\end{tikzpicture}
\end{document}


-
You were definitely faster than me ;) –  Claudio Fiandrino Jan 15 '14 at 8:01
But I missed the fact that the node names were a and b! Ooops! –  Loop Space Jan 15 '14 at 8:03
I was so frustrated with the fact that the code refused to work, that I threw in wrong node names, and lots of garbage, including color and the such. Thanks to both of you guys. –  Yossi Gil Jan 15 '14 at 13:07
@YossiGil: for colors within insert path you can have a look to my solution, which differs from Andrew's one exactly in that point. –  Claudio Fiandrino Jan 15 '14 at 14:06

The MWE example presented contains some conceptual errors.

The most relevant one, I think, is that you wish to reference nodes through their text and not through their name. That's what I read in:

\node(a)  [draw,rectangle,text=teal] at (0,0) {here};
\node(b)  [draw,rectangle,text=olive] at (3,0) {there};
\path[measuring south=from here to there is far,fill=red];


The \path syntax should contain a and b, not here and there.

Second, here the late options are used in the wrong manner: once the path is ended, that's it, you can't append stuff anymore. So, in measuring south you are willing to insert path rather than append after command. Moreover, since you are changing path options from the main path to the inserted ones, you may want to use \pgfextra.

This would have been my way to go:

\documentclass[border=3pt]{standalone}
\usepackage{tikz}

\tikzset{dimen/.style={<->,>=latex,thin,
every rectangle node/.style={fill=white,midway}
}}

\tikzset{measuring south/.style args={from #1 to #2 is #3}{
insert path={
\pgfextra{
\draw[red] (#1.south west) -- ++(0,-1.0)
coordinate (A1) -- ++(0,-10pt);
\draw[blue](#2.south east) -- ++(0,-1.0)
coordinate (A2) -- ++(0,-10pt);
\draw[dimen] (A1) -- (A2) node[midway,fill=white] {#3};
}
}
}
}

\begin{document}
\begin{tikzpicture}
\node(a)  [draw,rectangle,text=teal] at (0,0) {here};
\node(b)  [draw,rectangle,text=olive] at (3,0) {there};
\path[measuring south=from a to b is far];

\node(x) [draw,rectangle,text=blue] at (0,-2) {Heaven};
\node(y) [draw,rectangle,text=red] at (3,-2) {Hell};
\draw (x.south west) -- ++(0,-1.0)
coordinate (A1) -- ++(0,-10pt)
(y.south east) -- ++(0,-1.0) coordinate (A2) -- ++(0,-10pt)
[dimen] (A1) -- (A2) node {sin};
\end{tikzpicture}
\end{document}


The result:

-