[texhax] How to write a TeX code into file literally

Yue Wu vanopen at gmail.com
Sun Oct 9 12:22:41 CEST 2011


On Sun, Oct 09, 2011 at 08:59:39AM +0200, Paul Isambert wrote:
> Le 09/10/2011 08:49, Yue Wu a écrit :
> > Then I tried to set #'s catcode to 12(other):
> >
> > \newwrite\testwrite
> > \openout\testwrite=testwrite
> > {\catcode`\#=12
> > \immediate\write\testwrite{\halign{#&#\cr
> > hello&test\cr
> > }}
> > }
> >
> > then the file will be empty.
> 
> Add \immediate before \openout, otherwise the file isn't opened yet when 
> \write is called.
> 

Thanks for figuring it out, it works now.

Another question arises, I try to let TeX not expand macros at all for a
\write, so I tried with it:

\newwrite\myout
\immediate\openout\myout=myout.tex
\long\def\myoutone{%
  \begingroup
  \catcode`\|=0
  |catcode`|\=12
  |catcode`|#=12
  |catcode`|&=12
  |immediate|write|myout{}
  |myouttwo
}
\long\def\myouttwo#1#2{%
  |immediate|write|myout{#1|endgraf#2}
  |endgroup
}

but TeX alarms: 

! Illegal parameter number in definition of \myoutone.
<to be read again> 
                   =
l.37   |catcode`|#=
                   12

-- 
Regards,
Yue Wu

Key Laboratory of Modern Chinese Medicines
Department of Traditional Chinese Medicine
China Pharmaceutical University(中國藥科大學)
No.24, Tongjia Xiang Street, Nanjing 210009, China


More information about the texhax mailing list