"Clever tricks" for using \outer macros

As egreg said, the standard way is with \csname: as long as there is no \outer token at the time of the definition, you are safe.

So another possibility is, in a group, make the macro non-outer, define your macro, and then reset everything:

\begingroup
  \let\newdimen\relax
  \gdef\makedimenandgivevalue#1#2{%
    \newdimen#1%
    #1=#2\relax}
\endgroup

The problem with this version is that if you need to pass the \outer macro as argument to an auxiliary, you can't. A handier version is to define a non-outer wrapper to the \outer macro, then you can use it freely:

\edef\mynewdimen{\noexpand\newdimen}
%
\def\makedimenandgivevalue#1#2{%
  \mynewdimen#1%
  #1=#2\relax
}

The standard trick is \csname:

\def\makedimenandgivevalue#1#2{%
  \csname newdimen\endcsname#1%
  #1=#2\relax
}

Or \noexpand:

\edef\myproclaim#1#2\endmyproclaim{\noexpand\proclaim #1. \ignorespaces #2\par}

\myproclaim{Theorem}
This is better syntax.
\endmyproclaim

\proclaim Theorem.
This is worse syntax.

\bye

enter image description here


The famous \cleartabs, \settabs and \+ macros from plain.tex show one such trick (TeXbook p. 354):

\let\+=\relax % in case this file (plain.tex) is being read in twice
\def\sett@b{\ifx\next\+ \let\next=\relax % turn off \outerness
    \def\next{\afterassignment\s@tt@b\let\next}%
  \else\let\next=\s@tcols\fi\next}

...

\outer\def\+{\tabalign}
  1. \let\+=\relax is done before defining \sett@b in case \+ would already be an \outer token (otherwise, the \+ token in the replacement text of \sett@b would cause an error when \sett@b is defined).

  2. When the \ifx\next\+ test is true during normal usage of \settabs in the document, \next is an \outer token since in normal usage, \+ is \outer. Thus, Knuth does \let\next=\relax before redefining \next with \def\next{\afterassignment\s@tt@b\let\next}, otherwise the \next token at the end of the replacement text in this definition would cause an error.