I suggest a different approach, not optimal (see What do the pgfkeys key handlers .get and .store in do?), but it works. Indeed, one problem in your code is that, inside arrow style
the keys do not inherit the correct path /tikz/arrow inside/key-name
. To make it working you can do something like:
\[ \int_{
\tikz[scale=0.3]{
\path[fill=lightgray] (0,0) rectangle (1,1);
\draw (1.5,1) -- (0,1) -- (0,0) -- (1.5,0);
\draw[/tikz/arrow inside/pos = 0.4,/tikz/arrow inside/end = |,arrow inside] (1,-0.5) -- (1,1.5);
}
} \vec{B} \cdot \vec{n} \, df \]
which is not so convenient IMHO. The other problem is that if you define a style doing something with keys, those keys have to be set not inside the style, but before as I did with the above code. Notice that:
\[ \int_{
\tikz[scale=0.3]{
\path[fill=lightgray] (0,0) rectangle (1,1);
\draw (1.5,1) -- (0,1) -- (0,0) -- (1.5,0);
\draw[arrow inside={/tikz/arrow inside/pos = 0.4,/tikz/arrow inside/end = |}] (1,-0.5) -- (1,1.5);
}
} \vec{B} \cdot \vec{n} \, df \]
does not do anything as the keys still have the values 0.5
and >
respectively.
So, my approach will be based on the "triple" handlers initial
, get
and store in
and will let you use:
arrow inside={pos = 0.4,end = |}
inside \draw
.
First I would define the keys:
\pgfkeys{/arrow inside/.cd,
pos/.initial = 0.5,
pos/.get = \arrow@inside@pos,
pos/.store in = \arrow@inside@pos,
end/.initial = >,
end/.get = \arrow@inside@end,
end/.store in = \arrow@inside@end,
}
They are under the path /arrow inside/
so later on we should take care of this.
Second, I would define a style to place the arrow:
place arrow/.style = {
postaction = {
decorate,
decoration={
markings,
mark=at position \arrow@inside@pos with {\arrow{\arrow@inside@end}}
}
}
},
Rather than the keys, the style belongs to the usual /tikz/
path. To combine the keys and the aforementioned style, I define:
arrow inside/.style={place arrow,/arrow inside/.cd,#1}
as a style which "places" the arrow and, by changing the default /tikz/
path, allows you to use the previously defined keys.
A mwe:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\makeatletter
\pgfkeys{/arrow inside/.cd,
pos/.initial = 0.5,
pos/.get = \arrow@inside@pos,
pos/.store in = \arrow@inside@pos,
end/.initial = >,
end/.get = \arrow@inside@end,
end/.store in = \arrow@inside@end,
}
\tikzset{arrow inside/.style={place arrow,/arrow inside/.cd,#1},
place arrow/.style = {
postaction = {
decorate,
decoration={
markings,
mark=at position \arrow@inside@pos with {\arrow{\arrow@inside@end}}
}
}
},
}
\makeatother
\begin{document}
\[ \int_{
\tikz[scale=0.3]{
\path[fill=lightgray] (0,0) rectangle (1,1);
\draw (1.5,1) -- (0,1) -- (0,0) -- (1.5,0);
\draw[arrow inside={pos = 0.4,end = |}] (1,-0.5) -- (1,1.5);
}
} \vec{B} \cdot \vec{n} \, df \]
\[ \int_{
\tikz[scale=0.3]{
\path[fill=lightgray] (0,0) rectangle (1,1);
\draw (1.5,1) -- (0,1) -- (0,0) -- (1.5,0);
\draw[arrow inside={pos = 0.7,end = stealth}] (1,-0.5) -- (1,1.5);
}
} \vec{B} \cdot \vec{n} \, df \]
\end{document}
The result:

Notice that the keys now update correctly their values.