15

Why is a missing coordinate considered as 1 (and not 0 for example)? Is this by design choice or a simple coincidence?

\documentclass[tikz,border=7pt]{standalone}
\begin{document}
  \begin{tikzpicture}
    \path[red]
        (0,0) node{(0,0)}
        (,0)  node{(1,0)}
        (0,)  node{(0,1)}
        (,)   node{(1,1)}
      ;
  \end{tikzpicture}
\end{document}

Enter image description here

Note: This is very useful question for code golfing ;)

2
  • 2
    Code golfing your code: (0,0) is superflous.
    – Ignasi
    May 10, 2018 at 7:51
  • @Ignasi Indeed ;)
    – Kpym
    May 10, 2018 at 7:57

1 Answer 1

16

This is due to how \pgfpointxy{}{} works. When TikZ encounters (...) it basically looks for the typical is it a polar syntax, is it a coordinate system point etc checks and then assumes that it is a regular point. After checking for 3D (x,y,z) syntax, it sends it down to one of those @ populated scan point macros (\tikz@@@parse@regular if I'm not mistaken)

But the actual number comes from this bit

\def\pgfpointxy#1#2{%
  \pgfmathparse{#1}%  <============= This is \pgfmathparse{} in our example
  \let\pgftemp@x=\pgfmathresult%
  \pgfmathparse{#2}%
  \let\pgftemp@y=\pgfmathresult%
  \pgf@x=\pgftemp@x\pgf@xx% <================So this becomes ={\empty}{current xvec}
  \advance\pgf@x by \pgftemp@y\pgf@yx%
  \pgf@y=\pgftemp@x\pgf@xy%
  \advance\pgf@y by \pgftemp@y\pgf@yy}

Long story short, the coordinate syntax is chewed by \pgfpointxy and the entries become scalar factor to the current x,y vectors. And having no factor is taken as the current unit vector length itself due to TeX dimen register scaling behavior.

4
  • 2
    (+1) Yes, empty multiple of the base vector is the base vector ! That it is ;)
    – Kpym
    May 10, 2018 at 8:10
  • @Kpym More like how \somedimen=\empty\otherdimen works :) This really confused me for a while.
    – percusse
    May 10, 2018 at 8:46
  • Now the question is : Why the result of \pgfmathparse{} is \empty and not 0? This is probably a design choice but it is not very consistent with the manual who says "The result stored in the macro \pgfmathresult is a decimal without units". And empty is not a decimal ;). But it is consistent with the multiplication : product over empty set is 1
    – Kpym
    May 10, 2018 at 9:52
  • @Kpym I really don't have an answer, probably simplifies things somewhere else. But to be super pedantic, when there is no calculation there is no result so semantically still OK.
    – percusse
    May 10, 2018 at 11:35

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.