| 1 |
% (This file is public domain.) |
| 2 |
% Demonstrate how Eplain can be used to include a TeX source file |
| 3 |
% verbatim, typesetting comments in colored italic typewriter type. |
| 4 |
|
| 5 |
% Load Eplain and LaTeX's color.sty package. |
| 6 |
\input eplain |
| 7 |
\beginpackages \usepackage{color} \endpackages |
| 8 |
\nopagenumbers % Disable page numbers. |
| 9 |
\font\commentfont = cmitt10 % Font for the comments (italic \tt). |
| 10 |
% We'll define some `protected' macros with `@' in their names. |
| 11 |
\makeatletter |
| 12 |
% Define an equivalent of Eplain's \letreturn, to be able to assign |
| 13 |
% various actions to the (active) percent character. |
| 14 |
\begingroup \makeactive\% |
| 15 |
\gdef\letpercent{\let%} |
| 16 |
\endgroup |
| 17 |
% The listing hook to be called in \setuplistinghook, see below. It |
| 18 |
% makes `%' active and assigns it a `start comment' action. |
| 19 |
\def\hlightcommentslisting{\makeactive\% \letpercent\start@comment}% |
| 20 |
% This is what `%' is aliased to before a comment is started. |
| 21 |
\def\start@comment{% |
| 22 |
\leavevmode % Needed in the very first line of the input to process |
| 23 |
% the new par (possibly inserting line number) before we |
| 24 |
% kick in with the color and stuff. |
| 25 |
\begingroup % Isolate color and font changes and the redefinitions. |
| 26 |
\commentfont |
| 27 |
\color[cmyk]{0.28,1,1,0.35}% |
| 28 |
\percentchar % Produce the actual `%' and |
| 29 |
\letpercent\percentchar % make all following `%'s do the same. |
| 30 |
\letreturn\end@comment % Call \end@comment at end-of-line. |
| 31 |
} |
| 32 |
% \end@comment (alias for ^^M inside a comment) will end the comment |
| 33 |
% started by \start@comment. We make ^^M active temporarily so that |
| 34 |
% the active version of ^^M gets "frozen" into \end@comment. |
| 35 |
\begingroup \makeactive\^^M % Avoid ^^M's from here on. |
| 36 |
\gdef\end@comment{\endgroup ^^M}% |
| 37 |
\endgroup |
| 38 |
\resetatcatcode % Make `@' again inaccessible for use in macro names. |
| 39 |
|
| 40 |
% Define \setuplistinghook to setup comments highlighting, line |
| 41 |
% numbering and omitting the last (empty) line of input. |
| 42 |
\def\setuplistinghook{\hlightcommentslisting \linenumberedlisting |
| 43 |
\nolastlinelisting} |
| 44 |
% Isn't this fun? This file typesets itself, with the extra bonus of |
| 45 |
% the pretty-printed comments and numbered source lines! |
| 46 |
\listing{lscommnt} |
| 47 |
\bye |