TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following code:

    \addplot {x};
    %\draw (\a,20)--(axis cs:20,0);
    \node at (axis cs:30,30) {\a};

The node gives me the correct output, while the draw command won't work as expected. Why? (Uncommenting \draw breaks the code.)

share|improve this question
up vote 6 down vote accepted

The \pgfmathparse macro is not expandable and can't be used inside coordinates. Placing \pgfmathresult behind it, inside another macro like \a or on its own doesn't change anything on that. You need to place the result, like \pgfmathresult, which is expandable in the coordinates. However \pgfmathresult is overwritten by any internal math operation and therefor should not be used! Either use \let\a=\pgfmathresult (the = is optional) or \pgfmathsetmacro{\a}{1+1} (recommended) as already posted by you and Jake, respectively, or \edef\a{\pgfmathresult} to store the current value of \pgfmathresult into \a which then can be used safely inside an coordinate.

The reason why your original \a works inside the node content ({\a}) is that this part is typeset as a box. The content of a box do not need to be fully expandable, but is executed, i.e. the \pgfmathparse is executed as normal and then \pgfmathresult is typeset right away before it can be changed by any other code.

share|improve this answer

I can't really say why, but the following works fine:

share|improve this answer

Your Answer


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.