[texhax] Alignment in a \newwrite file?

geolsoft at mail.ru geolsoft at mail.ru
Sat Aug 21 11:50:58 CEST 2004


On Fri, Aug 20, 2004 at 10:49:13PM +0200, Rodolfo Medina wrote:
> Now, I would like all the stuff that gets into bluefile.tex to be aligned
> according, e.g., to the template
> 
> \halign{#&#\cr}
> 
> , i.e. all the bluefile.tex to be structured according to that alignment
> template.
> Is it possible to achieve this, and how?


If I got you right, the following does the job:


%%%%%%%%%%%%%%%%%%%%begin of myfile.tex%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newwrite\blue

\immediate\openout\blue=bluefile

\outer\def\putstuffoverthere#1#2{\immediate\write\blue{#1,& #2!\cr}}

\putstuffoverthere{Hallo}{folks}
\putstuffoverthere{Goodbye}{folks}

\immediate\closeout\blue

{\catcode`@=11 \halign{#&#\cr\input bluefile }}

\bye
%%%%%%%%%%%%%%%%%%%end of myfile.tex%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


(If you don't need the \catcode`@=11, the example above can
work without it)

Another solution:  if you want \halign to be written out to
bluefile.tex, try this (I use \lbracechar and \rbracechar
from eplain package):


%%%%%%%%%%%%%%%%%%%%begin of myfile.tex%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\input eplain

\newwrite\blue

\immediate\openout\blue=bluefile
{\catcode`#=11 \immediate\write\blue{\halign\lbracechar #&#\cr}}

\outer\def\putstuffoverthere#1#2{\immediate\write\blue{#1, #2!\cr}}

\putstuffoverthere{Hallo}{folks}
\putstuffoverthere{Goodbye}{folks}

\immediate\write\blue{\rbracechar}
\immediate\closeout\blue

\input bluefile

\bye
%%%%%%%%%%%%%%%%%%%%end of myfile.tex%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


(The \catcode`#=11 is to prevent TeX from doubling the `#'
in the bluefile.tex)

And another one.  Here, you can control what your alignment
entries look like by redefining \alignentry, it seems to me
more general than the previous two:


%%%%%%%%%%%%%%%%%%%%begin of myfile.tex%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\input eplain

\newwrite\blue

\immediate\openout\blue=bluefile

\outer\def\putstuffoverthere#1#2{\begingroup\toks0{#1}\toks2{#2}%
  \immediate\write\blue{\noexpand\alignentry{\the\toks0}{\the\toks2}}\endgroup}

\putstuffoverthere{Hallo}{folks}
\putstuffoverthere{Goodbye}{fo\thinspace lks}

\immediate\closeout\blue

\def\alignentry#1#2{#1,&#2!\cr}
\halign{#&#\cr\input bluefile }

\bye
%%%%%%%%%%%%%%%%%%%%end of myfile.tex%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


(The tricks with \toks0 and \toks2 are to prevent expansion
of any expandables in the text of the parameters; for
instance, the \thinspace in `Goodbye, fo\thinspace lks!'
gets written out into bluefile.tex as `\thinspace', not as
`\kern <something>')

If you need a more sophisticated processing of parameters of
\putstuffoverthere, see \writenumberedcontentsentry in
xeplain.tex of eplain package, or maybe even use their
\definecontentsfile mechanism.


Best regards,
Oleg Katsitadze



More information about the texhax mailing list