This post gives the TeX source for a previous post on Category codes in TeX Save this text in a "hash-in-refs.tex" file and process it with the following command:
tex hash-in-refs.tex \input eplain
\enablehyperlinks
\newcount\exno
\exno=0
\newcount\answ
\answ=0
{
\catcode`#=12
\catcode`!=6
\gdef\exercise{
\global\advance\exno by 1 \href{#ex\the\exno}{Exercise \the\exno}
}
\gdef\exercisearg!1{
\global\advance\exno by 1 \href{#ex\the\exno}{Exercise \the\exno} ({\it !1})
}
}
\def\answer{
\global\advance\answ by 1
{\xrdef{ex\the\answ} Answer of exercise \the\answ}
}
\exercise
This is the first exercise.
\medskip
\exercise
This is the second exercise.
\medskip
\exercisearg{Category codes\dots}
\par
{
An exercise on category codes: how to use '/' for commands instead of
\catcode`/=0
\catcode`\\=12
'{/tt \}' ?
% '$/backslash$'?
}
(For instance, {\tt /def/a$\{$macro a$\}$}).
\vfill
\eject %page break
\answer
Answer to the first exercise.
\eject
\answer
Answer to the second exercise.
\eject
\answer
The ``escape'' character '$\backslash$' is of category 0. Hence,
{
\catcode`/=0
\catcode`\\=12
/tt \catcode/catcode`//=12 `/=0
} does the trick.
\vfill
\end
No comments:
Post a Comment