6

I'm not fully grasping how the \ifx command handles types.

How should the following def's read to make the \ifx statement true when pdflastypos is at the zero coordinate?

\def\nothingness{0}
\def\lastypos{\pdflastypos}

\ifx\lastypos\nothingness
  TRUE \newline
\else
  FALSE \newline
\fi
2
  • I had to read @HeikoOberdiek's solution to understand why there was a command giving the last typo, and why it was misspelt.
    – LSpice
    Jan 16 '19 at 22:05
  • @LSpice As you've probably noticed, it is the 'LastYPos' or rather the 'Last Y-Position' not 'Last Typo'.
    – McGafter
    Jan 28 '19 at 16:05
8

No, \ifx will be false for that definition. TeX doesn't really believe in types. \ifx just compares the token lists in the definition and the token 0 is not the same as the token \pdflastypos

\ifnum\pdflastypos=\nothingness\relax

would test to true as \ifnum expands tokens to find a <number>

7

The explicit question is already answered by David Carlisle. Thus this answer adds a more complete use case. \pdflastxpos and \pdflastypos cannot be used in a direct way. Previously \pdfsavepos must be called and the positions are availabe at shipout time. Thus the values \pdflastxpos and \pdflastypos needs to be written to a auxiliary file. Then in the next LaTeX run the stored values from the auxiliary file can be used. Package zref-savepos (of project zref) provides an interface for the \pdfsavepos feature that remembers the values in references:

\documentclass{article}
\usepackage{zref-savepos}[2010/03/26]
\begin{document}
Somewhere\zsavepos{somewhere}

\zifrefundefined{somewhere}{%
  \typeout{Y-position: unknown}%
}{%
  \ifnum\zposy{somewhere}=0 %
    \typeout{Y-position: zero}%
  \else
    \typeout{Y-position: \zposy{somewhere}sp}%
  \fi
}
\end{document}

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.