summaryrefslogtreecommitdiff
path: root/macros/plain/contrib/misc/lwebmac.tex
blob: 23cf864ff87e978387b915769de27059b74e9c37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
% macros for the LWEB system by DCB -*- Mode: TeX; Syntax: Common-lisp; Package: LWEB -*-

% setup
\catcode`\@=11

% fonts
\def\LWnormalfont {\rm}
\def\LWcommentfont {\it}
\def\LWpuncfont {\tt}
\def\LWcodefont {\rm}
\def\LWcodepuncfont {\tt}
\def\slantedcode {%
  \font\sltt=amsltt10
  \def\LWcodefont{\sl}%
  \def\LWcodepuncfont{\sltt}}
\def\boldcode {%
  \def\LWcodefont{\bf}%
  \def\LWcodepuncfont{\tt}}

% delimiters
\newdimen\LWparenkern   \LWparenkern=.1pt
\newdimen\LWcommentkern \LWcommentkern=1pt
\newdimen\LWspacewidth  \LWspacewidth=.45em
\def\LWop/{{\rm(\kern\LWparenkern}}
\def\LWcp/{\/{\rm\kern\LWparenkern)}}
\def\LWobrace/{{$\{$\kern\LWparenkern}}
\def\LWcbrace/{\/{\kern\LWparenkern$\}$}}
\def\LWquot/{\raise.3ex\hbox{\LWpuncfont\char`\"}}
\def\LWstar/{\lower.05ex\hbox{\LWpuncfont\char`\*}}
\def\LWchr {\LWpuncfont\char}
\def\LWsetpwidth {\setbox\z@=\hbox{\LWop/}\LWpwidth=\wd\z@}
\newdimen\LWpwidth      \LWsetpwidth

% indentations
\def\LWpi/{\kern\LWpwidth}              % increment for plus1
\def\LWpii/{\kern 2\LWspacewidth}       % increment for plus2
\def\LWpiv/{\kern 4\LWspacewidth}       % increment for plus4
\def\LWks #1{\kern #1\LWspacewidth}     % kern a number of space widths


% boxes
\newbox\LWbox
\newdimen\LWboxw
\def\LWsb {\setbox\LWbox=\hbox}         % start a box
\def\LWdb/{\box\LWbox}                  % dump out a box
\def\LWbb {\LWboxw=\wd\LWbox            % output a box and backspace over it
           \box\LWbox
           \kern-\LWboxw}

% markers
\def\LWsm #1{\xdef#1{\the\wd\LWbox}%    % set a mark register
             \box\LWbox}
\def\LWkr #1{\kern #1\relax}            % kern a register
\def\LWkm {\LWbb\LWkr}                  % kern to a marked position

% modules

% keep track of position in file: top, after module, before module
\newif\iffirstmodule \firstmoduletrue
\newif\ifmodule

% incrementally number modules
\newcount\modulecount

% normal modules
\def\LWbeginmodule/{%
  \iffirstmodule \firstmodulefalse
  \else          \LWfilbreak \bigskip \fi
  \advance\modulecount\@ne
  \LWmarkmodule
  \begingroup \LWmoduledefs
  \noindent {\bf \number\modulecount.}\enspace \ignorespaces}

\def\LWendmodule/{%
  \endgraf
  \endgroup
  \moduletrue}

\def\LWmarkmodule {}

\def\LWmoduledefs {\def\par{\endgraf\nobreak}\LWsetpwidth}

% star modules
\def\LWbeginstarmodule #1{%
  \iffirstmodule \firstmodulefalse
  \else          \vfil \eject \fi
  \advance\modulecount\@ne
  \LWmarkstarmodule{#1}%
  \begingroup \LWmoduledefs
  \noindent {\bf \number\modulecount. \ignorespaces #1\par}
  \nobreak \smallskip \noindent \ignorespaces}

\def\LWmarkstarmodule {\message{*\number\modulecount}\mark}

% spacing and layout
\def\LWfilbreak {\vfil\penalty-200\vfilneg}
\def\LWfilnobreak {\vfil\penalty9999\vfilneg}
\parindent=2em
\interlinepenalty=10000                         % forbid page breaks in modules

% code in module text
\def\LWbcode/{\begingroup \LWcodefont \LWcodedefs \let\LWpuncfont=\LWcodepuncfont}
\def\LWecode/{\/\endgroup}

% code
\def\LWbeginlisp/{%
  \iffirstmodule \beginmodule \endmodule \fi
  \ifmodule \modulefalse \LWfilnobreak \bigskip
  \else     \LWfilnobreak \medskip \fi
  \vbox\bgroup \LWnormalfont \LWcodedefs}

\def\LWendlisp/{%
  \egroup}

\def\LWcodedefs {%
  \spaceskip=\LWspacewidth
  \xspaceskip=\LWspacewidth
  \LWsetpwidth}

% module text in code
\def\LWcommentdefs {\spaceskip=\z@ \xspaceskip=\z@ \LWcommentfont \LWsetpwidth}
\def\LWbcom/{\begingroup \LWcommentdefs {\rm;\kern\LWcommentkern}}
\def\LWecom/{\endgroup}

% miscellany
\ifx\lisp\undefined
  \def\lisp {Lisp}
  \let\LISP=\lisp
  \let\Lisp=\lisp
\fi
\def\lweb {LWEB}
\let\LWEB=\lweb

% cleanup
\catcode`\@=12