Saturday, 1 June 2013

Test for a character, no matter if active or not (futurelet token)

Test for a character, no matter if active or not (futurelet token)

I'd like to test for a character, irrespective its current catcode (i.e. active or not). This is very similar to How do I test for a character, irrespective of catcode?, however I cannot use \pdf@strcmp because I might have "half" macros (e.g. \emph without a parameter yet).
\documentclass{minimal}
\usepackage[czech]{babel}% makes - active
\begin{document}
  \def\aaa{%
    \if a\noexpand\lookahead%
      (the letter a)%
    \else\if -\noexpand\lookahead%
      (a minus)%
    \else%
      (special treatment)
    \fi\fi%
  }
  \futurelet\lookahead\aaa -
  \futurelet\lookahead\aaa a
  \futurelet\lookahead\aaa \emph{c}
\end{document}
Changing catcodes before and after is not really a solution in my case, because the original meaning would get lost just by futurelet-looking at things.

No comments:

Post a Comment