3

Consider the following code:

\documentclass[tikz]{standalone}

\begin{document}
  \begin{tikzpicture}[corner/.pic = {
    \path[pic actions] (0,0) -- (1,0) -- (0,1) --cycle;
  }]

  \pic[draw] {corner} ++(1,0) node{hi};
  \end{tikzpicture}
\end{document}

This generates the following error:

I do not know the key '/tikz/pics/hi' and I am going to ignore it. Perhaps you misspelled it. \pic[draw] {corner} ++(1,0) node{hi}

It seems that TikZ interprets the node as a pic, and as a consequence tries to find the definition of a pic called hi instead of using hi as the text inside of the node.

By contrast, \node{hi} ++(1,0) pic[draw] {corner}; works as expected.

Why is this? How can I fix it?

Bordaigorl
  • 15,135
  • 1
    You can turn off the parsing with \path {pic[draw] {corner}} ++(1,0) node {hi}; – percusse Dec 15 '14 at 00:16
  • @percusse ah that's great! If you post it as an answer I'll accept it gladly. Is there any mention of this in the manual? The reason for this misbehaviour is still not clear to me... – Bordaigorl Dec 15 '14 at 01:02
  • This seems to be a bug in TikZ (at least in 3.0.0), note that \path pic[draw] {corner} ++(1,0) node[draw] {corner}; is rendering the same as \path pic[draw] {corner} ++(1,0) pic[draw] {corner};. – TonioElGringo Dec 15 '14 at 09:27
  • @TonioElGringo has it been reported as a bug already? Should I open a ticket somewhere? – Bordaigorl Dec 15 '14 at 11:07
  • 1
    The bug has been reported here, and a possible solution is given in this TeX.SE answer – TonioElGringo Dec 15 '14 at 11:47
  • @percusse Your solution correct the bug if I use pic directly in the path, but if I intsert it using insert path= I'm not able to solve the problem this way (I use Mark Wibrow's trick in this case). – Kpym Dec 15 '14 at 12:26
  • @Kpym I'm actually not fixing the bug but limiting its effect. The node/pic parsing is designed as a greedy one but doesn't turn itself off after finishing so keeps parsing until the end. I don't think you need insert path if you are using pics though. – percusse Dec 15 '14 at 12:33
  • @percusse I would like to avoid using pic in insert path, but I don't know for the moment how to draw a point on the foreground layer without it (and without hack) : http://tex.stackexchange.com/a/217798/9335 – Kpym Dec 15 '14 at 12:37
  • I still think @percusse's trick can be very helpful as a workaround for simple cases and should be added as an answer either here or in the related question – Bordaigorl Dec 15 '14 at 12:54
  • It's already linked; it will show up to the right as a related question. – Sean Allred Dec 15 '14 at 13:30

0 Answers0