1

I'm trying to use this answer to extract the coordinates of a point without the pt. But why is the following not working? The first \JustNumber works as exected, but the second not, although \show\X gives > \X=macro:->0.0pt..

\documentclass{article}
\usepackage{tikz}
\def\JustNumber#1pt{#1}
\begin{document}
    \JustNumber0.0pt.
    \begin{tikzpicture}
        \path (0,0);
        \pgfgetlastxy{\X}{\Y}
        \show\X
        \xdef\X{\expandafter\JustNumber\X}
    \end{tikzpicture}
\end{document}

Why do I want this? I want to fill the rectangle between two points with a dotted grid. Because patterns seem to cause various problems when it comes to precise positioning, I thought of extracting the coordinates (without the pt) and feeding them into a \foreach.

Bubaya
  • 2,279

1 Answers1

2

The reason why it does not work is:

With your definition of \JustNumber the argument delimiter pt is tokenized while reading from the .tex-input-file.
Hereby you get two explicit character tokens of category 11(letter), i.e., p11t11.
But character tokens delivered via \pgfgetlastxy seem to come from \the which in turn delivers explicit character tokens of category 12(other), i.e., p12t12. (Exception: spaces delivered by \the are of category 10(space).)
Thus TeX does not find a matching delimiter.

With your definition ensure that the explicit character tokens forming the delimiter of the argument are of category 12(other):

\documentclass{article}
\usepackage{tikz}

% \string delivers explicit character tokens with the same catcode-régime % as \the, so let's stringify the delimiter: \csname @ifdefinable\endcsname\JustNumber{% \edef\JustNumber{##1\string p\string t}% \expandafter\def\expandafter\JustNumber\JustNumber{#1}% }%

\begin{document} \begin{tikzpicture} \path (0,0); \pgfgetlastxy{\X}{\Y} \show\X \xdef\X{\expandafter\JustNumber\X} \show\X \end{tikzpicture} \end{document}

Ulrich Diez
  • 28,770
  • Although https://tex.stackexchange.com/q/15001/47927 solves my aims better, this answer explains well while my attempt failed. – Bubaya Mar 09 '24 at 18:03