[Tex/LaTex] Correct use of arguments pattern in pgfkeys/append after command in tikz

pgfkeystikz-pgftikz-styles

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.

Above: what I currently have; below: what I would like to achieve

Best Answer

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}

From here to there