In TikZ one can specify a node by a command like
\path (0,0) node[node contents=A];
This is very useful if one wishes to apply a command to the text in the node, say, to avoid writing
\node at (0,0) {\contour{red}{A}};
and simply set
\path (0,0) node[node contents={\contour{red}{A}}];
(which comes very handy when used repeatedly!)
However, there are some restrictions in the syntax, because the parsing of the command stops after node contents
is found. In particular, this seems to prevent one from placing such a node on a path by means of decorations.markings
library. Below is the minimal (non-)working example:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}
\path (.5,0) node[node contents={A}];
\draw[postaction=decorate,decoration={markings,mark=at position 0.5 with \node {B};}] (0,-1) to (1,-1);
\draw[postaction=decorate,decoration={markings,mark=at position 0.5 with \node[node contents=C];}] (0,-2) to (1,-2);
\end{tikzpicture}
\end{document}
The last command raises an error "Paragraph ended before \tikz@fig@scan@options was complete. ...node[node contents=C];}] (0,-2) to (1,-2);
"
Is there a workaround?