[texhax] [solved] Re: Problems with \halign within a \write environment

Rodolfo Medina rodolfo.medina at gmail.com
Tue Sep 18 20:10:00 CEST 2007


Rodolfo Medina <rodolfo.medina at gmail.com> writes:

> If I process test.tex:
>
> ----------------------------->%--------------------------------
> \newwrite\myfile
>
> \newread \testin
> \openin \testin myfile
> \ifeof\testin
>   \closein \testin % file didn't exist
> \else
>   \read\testin to \temp
>   \ifeof\testin
>     \closein \testin % file empty
>   \else
>     \closein \testin
>     {\catcode`@=11 \input myfile }%
>   \fi
> \fi
> \vfill\eject 
>
> \immediate\openout\myfile=myfile
>
> \immediate\write\myfile{\halign{#&#\cr a&b\cr}}
>
> \immediate\closeout\myfile
>
> \end
> -----------------------------%<--------------------------------
>
> , I get the following error:
>
>
> $ tex test
> This is TeX, Version 3.14159 (Web2C 7.4.5)
> (./test.tex (./myfile.tex
> ! Only one # is allowed per tab.
> l.1 \halign {##
>                &##\cr a&b\cr }
> ? h
> There should be exactly one # between &'s, when an
> \halign or \valign is being set up. In this case you had
> more than one, so I'm ignoring all but the first.
>
> ?
>
>
> And in fact, in myfile.tex there are two `##' instead of one.
> Can anybody suggest a possible solution to avoid that?



Oleg Katsitadze <olegkat at gmail.com> writes:

> To avoid the doubled `#' in \write, define this:
>
>   {\catcode`\#=12
>   \gdef\hash{#}}
>
> and then say
>
>   \immediate\write\myfile{\halign{\hash&\hash\cr a&b\cr}}
>
> (\write doubles the macro parameter character (catcode 6), which is
> `#' in plain TeX).



Thanks indeed, that was helpful.

Cheers
Rodolfo



More information about the texhax mailing list