Debian Codegraph @

texmf-dist/doc/latex/cweb-latex/src/cwebx.sty

raw
1 % $Id: cwebx.sty,v 3.1 1995/11/21 00:42:49 schrod Exp $
2 %----------------------------------------------------------------------
3
4 %
5 % LaTeX2e package cwebx
6 % extra stuff for cweb bundle, to be added there sometimes
7 %
8 % [LaTeX2e]
9 % (history at end)
10
11
12 % Identification. The code below is explained in the implementation
13 % documentation of the rcs package.
14
15 \begingroup
16 \def\RCSPackage#1#2 $#3: #4 #5\endRCS $#6: #7 #8\endRCS{%
17 \def\date{#4}\def\id{v#7}%
18 \ProvidesPackage{#1}[\date\space\id\space #2]%
19 }
20
21 \RCSPackage{cwebx}{extra stuff for cweb bundle}
22 $Date: 1995/11/21 00:42:49 $: 9999/00/00 \endRCS
23 $Revision: 3.1 $: 0.0 \endRCS
24 \endgroup
25
26
27 %
28 % What's this package for?
29 %
30 % Additional macros for cweb.cls or cwebpart.sty, to be added there
31 % sometimes.
32 %
33
34
35 % requires that cweb base is loaded
36 \ifx \cwbb@loaded\undefined
37 \PackageError{cwebx}{cweb base is not loaded}
38 {This package requires the usage of either cweb.cls or
39 cwebparts.sty.}
40 \fi
41
42
43 % This style is supported. Send bug reports, comments and repairs.
44 %
45 % The reference version may be retrieved via anonymous ftp from
46 % |ftp.th-darmstadt.de| [130.83.47.112], directory |pub/tex/latex|. It's
47 % placed there as a gzipped tar file. (The information on the
48 % IP~number is dated 27 Sep 95. It might have changed, also
49 % this is very unlikely. Use your friendly nameserver.)
50
51
52
53 \catcode`\_=\CatLetter
54
55
56
57 %%% ======================================================================
58
59
60 %%
61 %% Errors in cwebbase.doc
62 %%
63
64
65 % As \4 follows \B always, the \kern\CwebIndentUnit to neutralize that
66 % backspace must be made after run-in section, too. Between the chunk
67 % marker and the program code start is 1em then (inserted by LaTeX
68 % section start).
69
70 % FIXME: \4 does _not_ follow \B all the time. Check when it is
71 % issued. The code below was introduced to repair a problem that gets
72 % visible if one uses \cwebNoChunk with an indentation unit of 2em,
73 % obviously I have to look for a better repair possibility.
74
75 \CheckCommand*\B{%
76 \cwbb@program
77 \cwbb@indent 3\CwebIndentUnit \hangindent\cwbb@indent
78 \ifvmode
79 \if@noskipsec
80 \indent % add an empty documentation part
81 \else
82 \noindent \kern\CwebIndentUnit
83 \fi
84 \fi
85 \CwebNumberProgramPart
86 }
87
88 \renewcommand\B{%
89 \cwbb@program
90 \cwbb@indent 3\CwebIndentUnit \hangindent\cwbb@indent
91 \ifvmode
92 \if@noskipsec
93 \indent % add an empty documentation part
94 \else
95 \noindent
96 \fi
97 \fi
98 \kern\CwebIndentUnit
99 \CwebNumberProgramPart
100 }
101
102
103 %%% ------------------------------------------------------------
104
105
106 %%
107 %% Macros from cwebparts.doc, to be moved to cwebbase.doc.
108 %%
109
110 % They are partly repaired and improved, where noted with `CHANGE'.
111
112
113 % \sect Now we can typeset pieces of \cweave{} output -- in principle.
114 % If these pieces have sections in them, they'll write entries to the
115 % |TOC| file. These entries will either mess up the structure of the
116 % document's table of contents or lead to \TeX{} error messages. That's
117 % because either toc entries for section types |part|, |chapter|, or
118 % |section| are written (causing the conflict); or toc entries for
119 % section types |chunk| and `|section|$i$' are written (being
120 % undefined).
121
122 % The best way seems to stop the included source to add anything to the
123 % table of contents or to do any mark processing. For that, we provide a
124 % macro |\CwebNoLists| that will locally redefine the \LaTeX{} cseqs
125 % that cause such actions to happen. That macro will be used at the
126 % start of the environment.
127
128 % CHANGE: Discard try code that redefines |\markboth| and |\markright|.
129
130 % \beginprog
131 \def\CwebNoLists{%
132 \let\addtocontents\@gobbletwo
133 \let\mark\@gobble
134 }
135 % \endprog
136
137
138 % \sect Furthermore, section divisions should not start a new page.
139 % %
140 % \begin{fixme}
141 % Currently, sections in the included parts are typeset exactly the
142 % same way as they're typeset in the main document. That should be
143 % different -- but how do I change it in a general way?
144 % \end{fixme}
145 %
146 % CHANGE: Moved to Cweb environment.
147
148
149 % CHANGE: Improved question.
150 %
151 % \sect OK, what gets destroyed by the environment? We need to save
152 % and restore counters that are changed globally by section commands.
153
154 % \beginprog
155 \ifx \chapter\undefined
156 \let\cweb@save_c@chapter\@gobble
157 \let\c@chapter\@gobble
158 \else
159 \newcount\cweb@save_c@chapter
160 \fi
161 \newcount\cweb@save_c@part
162 \newcount\cweb@save_c@section
163 \newcount\cweb@save_c@chunk
164
165 \def\cweb@save_for_env{%
166 %% save values changed globally by cwebbase macros
167 \cweb@save_c@chapter\c@chapter
168 \cweb@save_c@part\c@part
169 \cweb@save_c@section\c@section
170 \cweb@save_c@chunk\c@chunk
171 \let\cweb@save_thechapter\thechapter
172 \let\cweb@save_thesection\thesection
173 %% set up typesetting of CWEB source
174 \@nobreaktrue % don't add space from first chunk
175 }
176 \def\cweb@restore_env{%
177 \global\c@chapter\cweb@save_c@chapter
178 \global\c@part\cweb@save_c@part
179 \global\c@section\cweb@save_c@section
180 \global\c@chunk\cweb@save_c@chunk
181 \global\let\thechapter\cweb@save_thechapter
182 \global\let\thesection\cweb@save_thesection
183 }
184 % \endprog
185
186
187 % \sect For the moment, we use list spacing around a |cweb| environment.
188 % \LaTeX{} supplies the |trivlist| environment for such purposes.
189
190 % But the environment content itself must not be typeset in a list
191 % context. Two problems exist: There must be at least one |\item|, it
192 % will actually add the vertical space and must therefore not be
193 % discarded. And list environments redefine |\par|, but the
194 % \pkg{cwebbase} macros need a more `normal' definition.
195
196 % An item label is stored by |\item| in the |\everypar| register. The
197 % label is only typeset if |@inlabel| is true. The flag |@newlist| tells
198 % most other \LaTeX{} macros, that there was no item yet; typically
199 % they'll add an empty paragraph if necessary. As the content will
200 % start with a \LaTeX{} section division, or even with document markup,
201 % we don't want that empty paragraph and should skip the empty item
202 % label. (Often enough, due to the initialisation of |\everypar| in
203 % |\@startsection|, it will be thrown away anyhow). So we establish its
204 % postconditions, the next macro won't notice that the item hasn't been
205 % set actually.
206
207 % CHANGE: Added \CwebNoLists, as I consider it part of the env layout.
208
209 % CHANGE: Added paragraph below.
210 %
211 % Furthermore, section divisions should not start a new page.
212 % %
213 % \begin{fixme}
214 % Currently, sections in the included parts are typeset exactly the
215 % same way as they're typeset in the main document. That should be
216 % different -- but how do I change it in a general way?
217 % \end{fixme}
218
219 % \begin{fixme}
220 % Experimentally, we reduce the skip in front of a chunk to 1\,pc,
221 % otherwise the distance between two chunks is far too wide compared
222 % to other vertical distances in the text around the included stuff.
223 % \end{fixme}
224
225 % \beginprog
226 \def\CwebBeginEnvLayout{%
227 %% use spacing of list, but switch off list handling afterwards
228 \trivlist
229 \@inlabelfalse % don't go in horizontal mode
230 \item\relax
231 \global\@newlistfalse
232 \global\@inlabelfalse\the\everypar
233 \@setpar{\@@par}%
234 %% now change cweb base layout, meant for classes
235 \CwebNoLists
236 \let\CwebEjectSection\@gobble
237 \CwebChunkPreSkip 1pc plus 6pt minus 3pt
238 }
239 \let\CwebEndEnvLayout=\endtrivlist
240 % \endprog
241
242
243 % \sect The environment gets trivial now. We supply a hook for a whole
244 % document and also environment-specific ones (as an optional
245 % environment argument).
246
247 % CHANGE: Renamed to `Cweb'. Lusers should actually not call that env
248 % directly, it's too dangerous.
249
250 % CHANGE: Added forgotten evaluation of \cweb@restore_env.
251
252 % \beginprog
253 \newenvironment{Cweb}[1][]%
254 {%
255 \CwebBeginEnvLayout
256 \cweb@save_for_env
257 \csname CwebEnvHook\endcsname
258 #1
259 }{%
260 \cweb@restore_env
261 \CwebEndEnvLayout
262 }
263 % \endprog
264
265
266 % CHANGE: Have to improve the introduction of |cwebInput|. Now it has
267 % an additional optional parameter, where instance specific cseqs may
268 % be passed (like the cweb env).
269
270 % \sect An a convenience tag to include a complete \cweave{} file. Since
271 % we want to test the typesetting of our included \cweb{} program alone,
272 % we allow but ignore most kinds of document markup. Many of them have
273 % two arguments, one is optional.
274
275 % In the preambel, only |\documentclass| and |\usepackage| may appear.
276 % Titlepage material is handled, table of contents is discarded. The
277 % document environment does nothing, i.e., unlike the \cls{cweb} class,
278 % material behind |\end{document}| is not ignored.
279
280 % An |\end| tag is inserted by \cweave{} and must be redefined, we don't
281 % end an environment there. We'll open a group and will use that tag to
282 % close it again, as we know that we'll have reached the end of our
283 % \cweb{} file. Of course, |\end| must not be redefined during
284 % processing the actual program source -- environments are valid there.
285 % The redefinition is best be triggered by material inserted from
286 % \cweave{} at the very end, e.g., from |\inx|. But |\inx| may not be
287 % there (when \cweave{} is called with the `|-x|' option), we'll use
288 % |\enddocument| to add a |\inx| tag for safety reason. If the user
289 % didn't add an |\end{document}| to his file and used `|-x|', we're
290 % going to loose.
291
292 % CHANGE: Added handling of empty chunk. (@noskipsec was set after the
293 % environment, what messed up later invocations of program code if
294 % used with \cwebCodeExample.)
295
296 % \TeX{}nical note: |\document| must not have the same binding as
297 % |\relax|, as this would be interpreted as a non-existing environment
298 % by \LaTeX{}. (That's due to the |\csname| lossage.)
299
300 % \TeX{}nical note: Evaluating |\inx| in |\enddocument| will not have
301 % any effect, we're inside a group. That evaluation must be postponed
302 % after the group has been closed.
303
304 % \beginprog
305 \providecommand\cweb@doc_markup_gobble[2][]{}
306 \let\cwebInput\undefined
307 \newcommand*\cwebInput[2][]{%
308 \begin{Cweb}
309 [%
310 \begingroup
311 \let\documentclass\cweb@doc_markup_gobble
312 \let\usepackage\cweb@doc_markup_gobble
313 \let\title\@gobble
314 \let\author\@gobble
315 \let\date\@gobble
316 \let\maketitle\relax
317 \let\tableofcontents\relax
318 \let\document\empty
319 \def\inx{\let\end\endgroup}%
320 \let\fin\relax
321 \let\con\relax
322 \def\enddocument{%
323 \if@noskipsec % empty chunk
324 \global\@noskipsecfalse
325 \global\everypar{}%
326 \fi
327 \aftergroup\inx
328 }%
329 #1%
330 ]%
331 \input{#2}%
332 \end{Cweb}%
333 }
334 % \endprog
335
336
337 %%% ------------------------------------------------------------
338
339
340 %%
341 %% New macros for cwebbase.doc.
342 %%
343
344
345 % For production of code examples in CWEB documents. It's expected
346 % that the document consists of only \emph{one} chunk that has no
347 % documentation. Just the code is of interest. Neither chunk markers,
348 % nor chunk numbers, nor refinement numbers are typeset.
349 %
350 % But one may change that with the optional parameter.
351
352 \providecommand*\cwebCodeExample[2][]{%
353 \cwebInput[%
354 \def\CwebChunkHeading##1{\kern -1em}%
355 \let\cwbb@marginal_chunkno\relax
356 \let\CwebRefNumber\@gobble
357 \CwebChunkPreSkip\z@skip
358 #1%
359 ]{#2}%
360 }
361
362
363 % Often one has an explanation for more than one refinement. (E.g.,
364 % when there's needed a definition and a declaration.) Then the
365 % documentation of the follow-up refinements shall consist solely of
366 % |\cwebNoChunk|. Then no chunk marker is set, and the refinement
367 % is typeset nearer to the previous refinement. Optically, we create
368 % one chunk with many refinements this way.
369
370 % \TeX{}nical note: No chunk marker is created by redefining macro
371 % |\@svsechd| that creates header for run-in \LaTeX{} section. Every
372 % header is followed by 1\,em space, we have to annulate that skip.
373 % (The refinement shall start at the beginning of the line.) One must
374 % not use |\hskip| to backup, an |\unskip| comes after the header and
375 % would discard that skip.
376
377 \providecommand\cwebNoChunk{%
378 \vskip -\lastskip \bigskip % discard LaTeX's inter-section skip
379 \def\@svsechd{\kern -1em}%
380 }
381
382
383
384
385 \catcode`\_=\CatUsCode
386 \endinput
387
388
389 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
390 %
391 % $Log: cwebx.sty,v $
392 % Revision 3.1 1995/11/21 00:42:49 schrod
393 % version 1.1
394 %
395
396
397
398 %%%------------------------------------------------------------
399
400 % Local Variables:
401 % mode: LaTeX
402 % TeX-brace-indent-level: 4
403 % indent-tabs-mode: t
404 % TeX-auto-untabify: nil
405 % page-delimiter: "^%%%"
406 % End: