I've written the following code:
\newif\ifconsecutive
\consecutivefalse
\newcommand{\myfirst}[1]{#1\consecutivetrue\expandafter\consecutivefalse}
\newcommand{\mysecond}[1]{\ifconsecutive $\longrightarrow$\fi #1}
The idea was that if I write
\myfirst{A}\mysecond{B}
I get the equivalent of
A $\longrightarrow$ B
while if I type something in between, like
\myfirst{A} then \mysecond{B}
I instead get the equivalent of
A then B
The idea was that \expandafter would cause the text following the invocation of \myfirst (either an invocation of \mysecond or some arbitrary other code) to be expanded while \consecutivetrue is in effect, so if the next thing is a \mysecond invocation, the \ifconsecutive will be executed and the arrow generated, while if something else follows, it will not care about \consecutivetrue. After that expansion, \consecutivefalse should be called, causing any later invocation of \mysecond to not generate the arrow.
However what actually happens is that the arrow never gets inserted, no matter whether the macros are consecutive or not.
Now my question is: Why does this pair of macros not work as intended?
Here's a complete compilable code:
\documentclass{article}
\newif\ifconsecutive
\consecutivefalse
\newcommand{\myfirst}[1]{#1\consecutivetrue\expandafter\consecutivefalse}
\newcommand{\mysecond}[1]{\ifconsecutive $_$\fi #1}
\begin{document}
\myfirst{A}\mysecond{B}
\myfirst{A} then \mysecond{B}
\end{document}


\documentclass{...}, the required\usepackage's,\begin{document}, and\end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – jub0bs May 14 '14 at 17:52\mysecond, executes\consecutivefalseand then continues with the expanded\mysecond. See this post for tracking/tracing LaTeX: http://tex.stackexchange.com/questions/538/how-to-best-debug-latex – nickpapior May 14 '14 at 17:54