The following code \node at ($(tag-node) + (2.5,0)$) allows to place a node by calculating $(tag-node) + (2.5,0)$.

Does TikZ do that by changing the catcode of $ ?


No, TikZ doesn't change the \catcode of $. Indeed, if you try to change yourself the \catcode of $ TikZ will give an error:

! Package tikz Error: Sorry, some package has redefined the meaning of the math
-mode dollar sign. This is incompatible with tikz and its calc library and migh
t cause unrecoverable errors.

TikZ assumes that $ is a math-shift character and uses a parser to check for that. In tikz.code.tex there is this code:


The \tikz@ensure@dollar@catcode is responsible for giving the error above in case \catcode`$ != 3. Then \pgfutil@ifnextchar{$} checks if the character following the ( is a $, and uses \tikz@parse@calculator in that case.

In tikzlibrarycalc.code.tex there is the definition of \tikz@parse@calculator:

    % Parse main computation. It's a series of optional factors in front
    % of coordinates.
    \pgf@xa=0pt% We accumulate the result in here.

    % Ok, we found the end...
      % Ok, we found a coordinate...
        \tikzerror{+ or - expected}%

The macro \tikz@parse@calculator will use \tikz@cc@parse which will parse the expression and eventually check for the ending $ and finish the calculation. All of that assuming \catcode`$=3.

  • 1
    What an answer ! Thanks for all the details. :-) – projetmbc Oct 19 at 22:25

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.