[Tex/LaTex] “Missing \cr inserted”, but it looks to me like it’s already there!


I'm trying to create a Plain TeX macro for typesetting two-column proofs with automatic step-numbering and step cross-referencing; currently, the "best" I have is:

 \everycr={\advance\stepno by 1}
    \expandafter \ifx \csname##1step\endcsname \relax%
    \else \message{^^JWarning: attempt to define ##1 more than once^^J^^J}%
    \expandafter \ifx \csname##1step\endcsname \relax {\tt[##1]}%
    \else \csname##1step\endcsname%
   \strut\the\stepno. ##\hfil & \vrule ##\hfil\cr%
   #1 \cr

 \mkstep{A} $(p\to q)\land (q\to r)$ & premise \cr
 \mkstep{B} $p\to (q\land(q\to r))$ & \stepref{A}, logic07 \cr
 $p\to r$ & \stepref{B}, {\it modus ponens}


Unfortunately, trying to typeset this yields the following inexplicable error:

This is pdfTeXk, Version 3.141592-1.40.3 (Web2C 7.5.6)
 %&-line parsing enabled.
entering extended mode
! Missing \cr inserted.
<inserted text>
<to be read again>
\twocols ... ##\hfil & \vrule ##\hfil \cr #1 \cr }
l.28 }

? X
No pages of output.
Transcript written on twocols02.log.

Why is it claiming there's a missing \cr where there clearly appears to be one? I've tried removing the \cr from the macro definition and adding a \cr to the end of the macro argument, replacing the \cr with \crcr, removing the newline between the two closing braces there, using two \crs, dispensing with the macro and trying to typeset what it should expand to, and various combinations thereof, yet I keep getting this error, and I'm out of ideas. What's going on?

(Also, I suspect that using \mkstep the way I am will cause the resulting reference macros to be scoped to just the column in which \mkstep is used, rather than to the whole \twocols; is there a way to fix that without making the reference macros global?)

Best Answer

 \everycr={\noalign{\global\advance\stepno by 1}}%

you are inserting tokens after the last explicit \cr so need to make sure they don't start a new row.