[texhax] dual-use input/output macro
Philip G. Ratcliffe
philipratcliffe at tiscali.it
Thu Nov 17 23:00:40 CET 2005
> Suppose I want to show both the TeX input and its corresponding output
> as an example. Not big files, but just small fragments. As in:
>
> \showme{hello, \relax there}
>
> and the typeset output could be, say, two lines:
>
> hello, \relax there % in typewriter
> hello, there % in roman
>
> I cannot think of any easy way to do this. About all I can imagine is
> changing all the catcodes to other before reading the argument, printing
> the arg in tt, then writing the arg to an external file, and
> reading it back with normal catcodes to get the normal output.
>
> Is there a simpler way? Has anyone programmed the above? I imagine
> e-tex's \scantokens and \readfile (or something else?) might be useful,
> but didn't see a quick application.
>
> I browsed through the fancyvrb, verbatim, etc., doc but nothing jumped
> out at me.
How about something along these lines?
\documentclass{article}
\usepackage{fancyvrb}
\begin{document}
\DefineShortVerb{\|}
\def\showme|#1|{\SaveVerb[aftersave={\UseVerb{showme} = #1}]{showme}|#1}
\showme|hello, \relax there||
\end{document}
Cheers, Phil Ratcliffe
More information about the texhax
mailing list