Similar answer to egreg but using the TeX primitive \futurelet
\documentclass{article}
\begin{document}
\def\myspacetwo{}
\def\myspaceone{%
\futurelet\ifoptions
\choosemacro
}
\def\choiceone{\rule{20pt}{20pt}}
\def\choicetwo{}
\def\choosemacro{%
\ifx\ifoptions\myspacetwo%
\let\choice = \choiceone
\else
\let\choice = \choicetwo
\fi
\choice
}
\myspaceone\myspacetwo
\myspaceone
\end{document}
A \futurelet takes normally three tokens:
\futurelet\tokena\tokenb\tokenc
TeX executes a let\tokena=\tokenc generating a copy of \tokenc stored under the name of \tokena.
It then removes \tokena from the main token list. Following TeX expands \tokenb.
This token is for all practical purposes a macro with the following
properties:
- The macro will use
\tokena, which is a copy of \tokenc, to find
out what \tokenc is, in other words what token is to be expected
later.
- It then causes another macro to be expanded which will ultimately
absorb
\tokenc.
\documentclassand the appropriate packages so that those trying to help don't have to recreate it. This will also serve as a test case and ensure that the solution actually works for you. – Peter Grill Mar 13 '12 at 14:46