I am looking for a way to peek at the next command within a command definition. Let me try to explain what I mean.
Consider that I have a command \cmd which prints something, say foobar. Now I'd like the command to only print foobar if the following command is not \nofoobar. That is
\cmd followed by some text or another command such as \cmd\foo should print foobar
However,
\cmd\nofoobar should not print foobar.
Ideally, it should also be the case that spaces are ignored. That is,
\cmd \nofoobar should also not print foobar
I have no idea if that is at all possible but my guess is that there is some tex magic that allows to implement the functionality. Any help is much appreciated.
Following is a complete example.
\documentclass{article}
\newcommand{\cmd}{%
%If next command after cmd is \nofoobar print nothing, else print foobar
foobar}
\newcommand{\nofoobar}{%
}
\begin{document}
\cmd this should say foobar% prints foobar
\cmd\nofoobar this should not say foobar % does not print foobar
\cmd \nofoobar ideally this should also not say foobar % that is, spaces should be ignored
\end{document}

