# Define command that can only be used in the preamble

I remember there was a LaTeX macro used internally to define commands that can only be used in the preamble, but I cannot remember its name nor look it up.

Which is that command, and how is it used?

The command you're looking for is \@onlypreamble:

\documentclass{article}

\def\ACommand{\def\Example{}}

\makeatletter
\@onlypreamble\ACommand
\makeatother

\ACommand % ok

\begin{document}

\ACommand % error

\end{document}


output:

! LaTeX Error: Can be used only in preamble.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
...

l.15 \ACommand
% error
?