[texhax] Alignment in a \newwrite file?
geolsoft at mail.ru
geolsoft at mail.ru
Sat Aug 21 20:44:56 CEST 2004
On Sat, Aug 21, 2004 at 06:35:04PM +0200, Rodolfo Medina wrote:
> The first solution you suggested,
> the one I prefer because it only uses plain TeX commands,
> seems to work fine.
To avoid reading in eplain, you can always add the
definitions for \lbracechar and \rbracechar to your
(macro)file. You can even add a definition for \hashchar so
you don't need to \catcode`#=11 before you write out the
preamble of \halign:
\begingroup
\catcode`\# = 11
\gdef\hashchar{#}%
\catcode`\{ = 12 \catcode`\} = 12
\catcode`\[ = 1 \catcode`\] = 2
\gdef\lbracechar[{]%
\gdef\rbracechar[}]%
\endgroup
Now you can write out the preamble like this (no prior
`\input eplain' required):
\immediate\write\blue{\halign\lbracechar\hashchar&\hashchar\cr}%
If you are not comfortable with the above definitions, here
is a clue: we temporarily change category codes of special
chars while we define macros for them. We do this in a
group so that catcodes will revert to the original values
after the group ends. Later, these macros will expand to
those same characters, but with category codes they had at
the time of definition, not category codes they will have at
the time of expansion (we kind of `freeze' category codes of
these chars within definitions of macros).
> But I actually need bluefile.tex to be input *before* the \putstuffoverthere
> occurrencies.
> I tried with:
>
> %%%%%%%%%%%%%%%%%%%%%%%%begin of
> myfile.tex%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> \newwrite\blue
>
> \outer\def\putstuffoverthere#1#2{\immediate\write\blue{#1,& #2!\cr}}
>
> {\catcode`@=11
> \halign{#&#\cr \input bluefile }%
> }
>
> \immediate\openout\blue=bluefile
>
> \putstuffoverthere{Hallo}{folks}
> \putstuffoverthere{Goodbye}{folks}
> \putstuffoverthere{Goodbye}{folks}
>
> \immediate\closeout\blue
>
> \bye
> %%%%%%%%%%%%%%%%%%%%%%end of myfile.tex%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>
> , but it doesn't work: I get a message of `Missing \cr inserted'.
> Possible to work this problem out?
Actually, it seems you get this message only when
bluefile.tex exists but is empty. If no bluefile.tex exists
at all (i.g., at the first run of TeX over source file), you
get a fatal
! I can't find file `bluefile'.
l.9 \halign{#&#\cr \input bluefile
}%
Please type another input file name
Once again, to work this out I suggest using eplain's
\testfileexistence macro. If you absolutely need to avoid
using eplain, you can maybe copy definitions from the
sources of eplain. Anyway, now the part which reads in
bluefile.tex will look like this:
\testfileexistence[bluefile]{tex}% you may omit `tex' (give {})
\iffileexists{\catcode`@=11
\halign{#&#\cr \input bluefile }%
}\fi
Best regards,
Oleg Katsitadze
More information about the texhax
mailing list