Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

It seems that the two lines in the following code are not equivalent:

\documentclass{article}
\usepackage{tikz}
\def\coord{(0,0)}
\begin{document}
%  \tikz \coordinate at \coord;
 \tikz \node[coordinate] at \coord {};
\end{document}

Namely, the first (commented) line gives an error when used in place of the second. My understanding of the \coordinate command is that it is equivalent to \node[coordinate] {}, so am I missing something or is this a bug?

This question seems to have a similar flavor as Use macro as coordinate in pgfplots plot (among others) but this is not an issue of expandability: \coord is obviously fully expandable and indeed, works in what appears to be the same context in a nearly identical command.

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

In a normal picture \node is equivalent to \path node and \coordinate is equivalent to \path coordinate:

\node:
macro:->\tikz@path@overlay {node}

\coordinate:
macro:->\tikz@path@overlay {coordinate}

\tikz@path@overlay:
macro:#1->\let \tikz@signal@path =\tikz@signal@path \pgfutil@ifnextchar <{\tikz@path@overlayed {#1}}{\path #1}

(It is a little different for overlays, e.g. use in beamer)

The difference between both is that \node is more flexible in the syntax i.e. can have different things follow. It can have a name or not, for example and the order is not fixed. Because of this the following material is always expanded before it is parsed. This takes care of the \coord macro. However, \coordinate has quite a fixed syntax of \coordinate[<options>] (<name>) at (<position>);, and therefore are parsed differently.

Your example code doesn't have the (<name>) part which causes the first error. An unnamed coordinate doesn't make sense. However, even with the name it still generates an error. The following parsing macro is used which requires a ( somewhere after the at. The [ ] part is added using the default value beforehand if it isn't present.

\tikz@@coordinate@@at:
macro:[#1](#2)at#3(->\def \tikz@coordinate@caller {\tikz@fig ode[shape=coordinate,#1](#2)at}\tikz@scan@one@point \tikz@@coordinate@at@math (

So one way to solve this would be to move the ( ) to the outside of the \coord macro. This seems to work, at least in your MWE.

\documentclass{article}
\usepackage{tikz}
\def\coord{0,0}
\begin{document}
 \tikz \coordinate (name) at (\coord);
 \tikz \node[coordinate] at (\coord) {};
\end{document}
share|improve this answer
    
My little question is unworthy of this answer! So should I take away from this that it is accidental that \node allows macros to expand into its input syntax, or that it is unintentional that \coordinate is more rigid than it? Depending on the answer to that, what is the right way of using a presupplied at coordinate in a coordinate? –  Ryan Reich Jun 2 '11 at 17:00
    
@Ryan: The expanding while processing \node path is intentionally. The non-expansion of \node coordinate is also intensionally, most likely for efficiency. More macros would be needed otherwise. Besides using coordinate (name) at (\coord); as shown above you could use \edef to expand the command beforehand: \edef\mycommand{\noexpand\coordinate (name) at \coord;}\mycommand. –  Martin Scharrer Jun 2 '11 at 17:03
    
I think I'll go with using \node[coordinate], then, since in fact I don't want to arrange things so that the parentheses are not in \coord. Thanks! –  Ryan Reich Jun 2 '11 at 17:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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