[texhax] dual-use input/output macro

Oleg Katsitadze geolsoft at mail.ru
Fri Nov 18 13:35:17 CET 2005


On Thu, Nov 17, 2005 at 11:26:32PM +0200, Oleg Katsitadze wrote:
> As a side effect, there will be
> spaces after macro names in the verbatim text

Got another idea overnight--now I think it is possible to
avoid the extra spaces:  before we read the argument, we
change the catcode of backslash to \letter, and also do
\obeyspaces to prevent multiple spaces collapsing into one.
This is what I ended up with:

-------------------- Cut --------------------
\input eplain

\newwrite\showfile

\def\showme{\begingroup\catcode`\\=\letter \obeyspaces
            \finshowme}
\def\finshowme#1{%
  \toks0={#1}%
  \immediate\openout\showfile=show
  \immediate\write\showfile{\the\toks0}%
  \immediate\closeout\showfile
  \endgroup
  \listing{show}%
  \input show\par
}


\parindent=0pt

\showme{{hello, \relax here}}
\smallskip

\showme{\begingroup  hello,~{\it  there} $\|a_i\|^2$}
\endgroup
\smallskip

\showme{\line{hello,\hrulefill everywhere}}

\bye
-------------------- Cut --------------------

I haven't tested this thoroughly, but it seems to work with
pretty weired arguments.  Unbalanced braces won't work for
sure, but this would not be a good example to show :).

-- 
Best regards,
Oleg Katsitadze



More information about the texhax mailing list