[comp.text.tex] Help wanted: defining `invisible' macros

sra@ecs.soton.ac.uk (Stephen Adams) (06/11/90)

Here is a puzzle for TeXnicians:

How do you define a macro than can be inserted anywhere in
an error free latex document and guarantee that no errors
will be introduced into the document?


Consider the macro \nothing:

\def\nothing{}

I can put \nothing almost anywhere in a LaTeX document.
Now consider \mark:

\def\mark{...do something...}

Unfortunately, I have to be more careful where I put \mark.
I need to be able to put \mark anywhere that I can put
\nothing, but \mark must do something, for example, set a
counter.

The puzzle can be refined into two sub-puzzles:

a) How do you define a macro as above, but the macro must do
   something simple and `invisible' like advance a counter.

b) How do you define a macro as above, but the macro must do
   an arbitrary amount of box-bashing (but still producing
   no output at this point).

A simple attempt at (a) follows.  If \mark is defined as
anything except \nothing then it fails with a `Misplaced
\noalign.'

------------------------------
\documentstyle[]{article}
\begin{document}

\newcount\foo \foo=0
\def\nothing{}
\def\mark{\advance\foo by 1}

\section{Some section}

Duck frog cat tree hill \mark valley fence. 
Duck frog cat tree hill valley fence. 

  \begin{tabular}{|l|l|}
    \mark \hline
    Frog & amphibian \\
    Duck & bird \\
    \hline
  \end{tabular}

\end{document}