[texhax] \protect in Plain TeX

Joseph Wright joseph.wright at morningstar2.co.uk
Sun Oct 16 12:16:32 CEST 2011


On 16/10/2011 08:18, Vafa Khalighi wrote:
> \protect is defined in LaTeX but not in Plain TeX. I was wondering if one
> also would need to use \protect in Plain TeX for making macro definitions
> with moving arguments. If so, then what should you use instead \protect in
> Plain TeX or how should \protect be defined for Plain TeX?
> 
> In LaTeX, \show\protect gives \relax at the beginning of the document.
> 
> Thanks

Paul has already observed that \protected is available if you enable the
e-TeX extensions, and that this mechanism is easier to use and more
reliable than LaTeX's system.

LaTeX provides a protection mechanism as it 'wraps up' quite a bit of
material inside 'user' macros. Normally, plain users will do that work
themselves, and so the need for this mechanism is less necessary.

If you do want a LaTeX-like protection mechanism in plain TeX, you need
to remember that it is not just \protect that is needed. LaTeX has

   \protected at edef
   \protected at xdef
   \protected at write

and these, amongst other things, alter the meaning of \protect such that
it 'works' when needed. For example, inside \protected at edef, you'll find
that \protect is defined as

   \noexpand \protect \noexpand

which means that the protection stays in place and that the protected
token is unchanged.
-- 
Joseph Wright


More information about the texhax mailing list