# Expanding arguments to pgf/tikz styles

In an answer on this site is proposed a method to draw arrows on paths. For example, using the style [arrow inside={pos=0.2}] will put an arrow at position 0.2 on the path :

\begin{tikzpicture}
\tikzset{
set arrow inside/.code={\pgfqkeys{/tikz/arrow inside}{#1}},
set arrow inside={pos/.initial=.5, end/.initial=>},
arrow inside/.style={
set arrow inside={#1},
postaction={
decorate,
decoration={
markings,
mark=at position \pgfkeysvalueof{/tikz/arrow inside/pos} with \arrow{\pgfkeysvalueof{/tikz/arrow inside/end}}
}
}
},
}

\draw[arrow inside={pos=0.2}] (0,0) -- (5cm,5cm);
\end{tikzpicture}

Now, I would like to do something like

\draw[arrow inside={pos=0.2}, arrow inside={pos=0.8}] (0,0) -- (5cm,5cm);

and end up with two arrows, one at position 0.2 and the other at position 0.8. This does not work, because the second call to set arrow inside modifies the value of the key /tikz/arrow inside/pos and hence the style (only the second arrow is drawn). I tried to play with expansion rules, but I fail to wrap my mind around these things, so I hope perhaps somebody else will manage to do so (or perhaps the problem is somewhere else, and then I hope somebody will point out where !).

For the record, the original answer also provides another way to circumvent this problem by modifying the syntax a little, and that solution may be useful in practice. (However, I for one am interested in a solution to the evaluation order problem.) Thanks in advance !

• Last setting always win. So, IMHO is not that easy to keep the same syntax as you're going to exploit the same keys several times. – Claudio Fiandrino Sep 12 '14 at 8:23
• Yes, it is tricky. What I believe I need to do is to first parse the pgfkeys arguments to set the relevant macros (or pgf keys values), and then to produce an expanded style and to use it. Then, the contents of the macros/keys can change without affecting the style (because they were expanded). However, I don't know how to do that, hence my question. – Georg Sievelson Sep 12 '14 at 22:45

Do you mean some thing like this?

\documentclass[tikz]{standalone}
\usetikzlibrary{decorations.markings}
\tikzset{
arrowmark/.style 2 args={postaction={decorate},decoration={markings,mark=at position #1 with \arrow{#2}}}
}

\begin{document}
\begin{tikzpicture}
\draw[arrowmark={.2}{<},arrowmark={.8}{>}] (0,0) -- (5cm,5cm);
\end{tikzpicture}
\end{document}

• Ah, no. I want to keep the syntax arrow inside={pos=0.2} and to be able to use several of them. I know there are several other options ! However, I am interested in this specific problem :) Thanks anyway ! – Georg Sievelson Sep 12 '14 at 8:08