3

When I try to use something like

\node[node contents={Test}] at (0,0){};

an error is throw : Use of \@next doesn't match its definition.

To make it works, I can change the syntax to \path ... node, or use at key, or use a font= hack.

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
  \begin{tikzpicture}
    % \node[node contents={Test}] at (0,0){}; % <- not working
    % \node[node contents={Test}] at (1,0); % <- not working

    \path (0,0) node[node contents={Test}];
    \path (1,0) node[node contents={Test}]{};
    \node[node contents={Test}, at={(2,0)}];
    \node[node contents={Test}, at={(3,0)}]{};
    \node[font={Test}] at (4,0){};        
  \end{tikzpicture}
\end{document}

enter image description here

My question is : Is this the normal behavior, or a bug ?

2

It's the expected behavior and it's documented on page 215 of the manual (italics are mine for emphasis):

/tikz/node contents=<node contents>

When the option is used inside the options of a node, the parsing of the node stops immediately after the end of the option block. In particular, the option block cannot be followed by further option blocks or curly braces (or, rather, these do not count as part of the node specification.) Also note that the node contents may not contain fragile stuff since the catcodes get fixed upon reading the options.

4
  • Thanks ! I should read the manual before to ask ;) But why this limitation ? Why using font= key works better than the designed key ?
    – Kpym
    Oct 16 '15 at 20:03
  • @Kpym You're welcome. I have to leave now but latter I'll add some remarks. Oct 16 '15 at 20:08
  • @Kpym I gave a quick look at tikz.code.tex. the argument for node contents is assigned to \tikz@node@content which basically is the last thing the parser scans to know when a node path ends; this justifies the restrictions about its use. I hope this makes sense. Oct 16 '15 at 21:11
  • @PaulGaborit I already have shown in my question that at option works.
    – Kpym
    Oct 17 '15 at 7:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.