summaryrefslogtreecommitdiff
path: root/info/digests/ttn/ttn2n3-gather.sty
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /info/digests/ttn/ttn2n3-gather.sty
Initial commit
Diffstat (limited to 'info/digests/ttn/ttn2n3-gather.sty')
-rw-r--r--info/digests/ttn/ttn2n3-gather.sty89
1 files changed, 89 insertions, 0 deletions
diff --git a/info/digests/ttn/ttn2n3-gather.sty b/info/digests/ttn/ttn2n3-gather.sty
new file mode 100644
index 0000000000..73e55b9b60
--- /dev/null
+++ b/info/digests/ttn/ttn2n3-gather.sty
@@ -0,0 +1,89 @@
+%% 8 JUN 93: this file needed to run Johannes Braams' article in TTN
+%% 2,3 (Ch.)
+
+
+%% 7 JUL 93: This file renamed ttn2n3-gather.sty to show its
+%% relationship with TTN 2,3 files (Ch.)
+
+% gather.sty
+
+%
+% The following macro hackery I use to extract the macrocode
+% from the source of the article in order to use it later on.
+%
+\newwrite\codefile % To gather all the code together
+\newwrite\tmpfile % Temporary file for typesetting the code
+%
+{\catcode`\%=12 \gdef\comment{%% }}
+\chardef\other=12
+\def\myverbatim{\begingroup
+ \catcode`\\=\other\catcode`\&=\other\catcode`\$=\other
+ \catcode`\{=\other\catcode`\}=\other\catcode`\#=\other
+ \catcode`\^=\other\catcode`\~=\other\catcode`\%=\other
+ \catcode`\"=\other\catcode`\<=\other\catcode`\>=\other
+ \catcode`\_=\other\catcode`\|=\other \obeyspaces}
+% Macro to write code to the codefile *and* to the temporary file
+\def\spaces{\space\space\space\space}
+%
+% DOUBLE DANGEROUS BEND::
+% I make the ^^M an active character
+% I use it to write macrocode line by line to the files.
+\begingroup
+ \catcode`\^^M\active% Hide all ^^M's from TeX...
+%
+% I also have to temporarily change some other category codes,
+% in order to be able to scan for the line containing
+% the string "\end{code}"
+%
+ \begingroup%
+ \catcode`\[=1 \catcode`\]=2 \catcode`\|=0%
+ \catcode`\{=12 \catcode`\}=12 \catcode`\\=12%
+ |gdef|writeit#1^^M[|endgroup|def|tempa[#1]|def|tempb[\end{code}]%
+ |ifx|tempa|tempb%
+ |def|next[|end[code]]%
+ |else%
+ |def|next[|immediate|write|codefile[#1]%
+ |immediate|write|tmpfile[|spaces#1]^^M]%
+ |fi|next]%
+ |endgroup%
+% Here is a new LaTeX environment which can contain TeX macrocode
+% The code will be written to two files, the file to gather all code
+% in and the temporary fill that is \input at the end of the
+% environment. In that file the code will be in a normal verbatim
+% environment.
+ \gdef\code{\bgroup\catcode`\^^M\active%
+ \def^^M{\myverbatim\writeit}%
+ \immediate\openout\tmpfile=tmp%
+ \immediate\write\tmpfile{\string\begin{verbatim}}}%
+% And an environment to typeset the examples
+ \gdef\example{\bgroup\catcode`\^^M\active%
+ \def^^M{\myverbatim\writeit}%
+ \immediate\openout\tmpfile=tmp%
+ \immediate\openout\codefile=tmpb%
+ \immediate\write\tmpfile{\string\begin{verbatim}}}%
+\endgroup% Now the ^^M is no longer active
+\def\endcode{\egroup
+ \immediate\write\tmpfile{\string\end{verbatim}}
+ \immediate\closeout\tmpfile
+ \input{tmp}}
+\def\endexample{\egroup
+ \immediate\write\tmpfile{\string\end{verbatim}}
+ \immediate\closeout\tmpfile
+ \immediate\closeout\codefile
+ \leavevmode
+ \begin{minipage}[c]{.45\textwidth}\small\input{tmp}\end{minipage}%
+ \hfil
+ \begin{minipage}[c]{.45\textwidth}\small\input{tmpb}\end{minipage}}
+\def\startgather#1{%
+ \immediate\openout\codefile=#1
+ \immediate\write\codefile{\comment File : #1.tex}
+ \immediate\write\codefile{\comment Author: J.L. Braams}
+ {\let~\space
+ \immediate\write\codefile{\comment Date : \today}}
+}
+\def\endgather{%
+ \immediate\write\codefile{\string\endinput}
+ \immediate\write\codefile{\comment the rest of this file is ignored.}
+ \immediate\closeout\codefile}
+ \def\startexamples{\let\code\example\let\endcode\endexample
+ \def\spaces{}}