# [texhax] To not expanding macros, is there anything else besides \string?

Uwe Lueck uwe.lueck at web.de
Wed Jan 5 18:47:08 CET 2011

"Barhorst, Alan" <ALAN.BARHORST at ttu.edu>, 05.01.2011 00:29:14:
> I am trying to use \immediate\write on file 14 and 15
> for information that is generated/input in my main LaTeX session.
> They are solutions to problems that I want to assemble in an appendix.
> The problem is that any macro I pass to the write command
> gets immediately expanded, and all I have found in the literature is
> that I need to put \string in front of every macro.  What I am hoping is
> that there is one big wrapper macro I can place around anything
> I want to write to a file for later expansion.

In my view: yes, there is, \@onelevel at sanitize from latex.ltx
has been made for exactly this purpose:

\makeatletter
\def\sanewrite#1#2{% #1 output stream, #2 text
\def\tobewritten{#2}%
\@onelevel at sanitize\tobewritten
\immediate\write#1{\tobewritten}}
\makeatother

Cheers,

Uwe.