1

While was looking at the source code for pgffor, I noticed the macro \pgffor@stop is defined as

\def\pgffor@stop{\pgffor@stop}

I think the macro is used to stop argument parsing. If that's the case, what is the benefit of defining it recursively? Won't that cause an infinite loop if it is ever (accidentally) expanded? Why isn't it defined as {} or maybe even \relax?

mdm
  • 229
  • 1
  • 4

1 Answers1

2

The macro is \ifx equal to itself even if stored inside another macro

\def\some@store{\pgffor@stop}
\ifx\some@store\pgffor@stop
 % TRUE
\fi

This makes it useful for fast tests that are used with macros-as-variables.

Note that if you need to be sure of a unique ID, you can't use \relax or {}, at least if you are testing using \ifx. (With a modern TeX system you can do an expandable string test, so you can check the name of the token.)

\def\pgffor@stop@bad{}
\def\foo#1{\ifx#1\pgffor@stop@bad ...}
\foo\@empty % Oops
Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036