Debian Codegraph @

texmf-dist/doc/latex/cweb-latex/contrib/cweb-hy/cwbasehy.tex

raw
1 % $StyleId: cwebbase.doc,v 1.4 1995/11/07 17:55:19 schrod Exp $
2 %----------------------------------------------------------------------
3 % Written by Joachim Schrod <[email protected]>.
4 % Copyright conditions see below (GPL).
5
6 %
7 % LaTeX macros cwebbase
8 % support for incorporation of CWEAVE markup in LaTeX documents
9 %
10 % [LaTeX in MAKEPROG]
11 % (history at end)
12
13
14
15
16 %%%%
17 %%%%
18 %%%% These TeX macros were documented with the documentation system
19 %%%% MAKEPROG and automatically converted to the current form.
20 %%%% If you have MAKEPROG available you may transform it back to
21 %%%% the original input: Remove every occurence of three percents
22 %%%% and one optional blank from the beginning of a line and remove
23 %%%% every line which starts with four percents. The following lex
24 %%%% program will do this:
25 %%%%
26 %%%% %%
27 %%%%
28 %%%% ^%%%\ ? ;
29 %%%% ^%%%%.*\n ;
30 %%%%
31 %%%% If you just want to print the documentation you may fetch
32 %%%% the archive print-makeprog.tar.Z from ftp.th-darmstadt.de (directory
33 %%%% pub/tex/latex). It contains *all* used styles -- but beware, they
34 %%%% may not be in a documented form...
35 %%%%
36 %%%%
37 %%% \documentclass{progltx}
38
39 %%% \usepackage{cweb-doc} % document-specific markup
40 %%% \usepackage{fullpage}
41
42
43 %%% \RCS $StyleRevision: 1.4 $
44 %%% \RCS $StyleDate: 1995/11/07 17:55:19 $
45
46
47 %%% \begin{document}
48
49
50 %%% \title{Typesetting \cweave{} Output}
51 %%% \author{% % LaTeX does not discard unnecessary glue...
52 %%% Joachim Schrod%
53 %%% \thanks{%
54 %%% \protect\raggedright
55 %%% TU~Darmstadt, Computer Science Department, WG Systems Programming,
56 %%% Alexanderstr.~10, D-64283~Darmstadt, Germany.
57 %%% Email: \texttt{[email protected]}.%
58 %%% }%
59 %%% }
60 %%% \date{%
61 %%% Revision \RCSStyleRevision\\
62 %%% (as of \RCSStyleDate)%
63 %%% }
64
65 %%% \maketitle
66
67
68 %%% % doesn't work with progltx yet
69 %%% %\tableofcontents
70
71
72
73
74 %%% \chap Introduction.
75
76 %%% This code shall interpret and render the tag set output by \cweave{}.
77 %%% That's realized in this module as it's needed in multiple places --
78 %%% when we want to use \LaTeX{} markup in \cweb{}, when we want to
79 %%% incorporate \cweb{} pieces in \LaTeX{} documents (as examples, or in
80 %%% textbooks), and when we want to incorporate whole \cweb{} documents in
81 %%% a \LaTeX{} document. (That's by far the most difficult task.)
82
83 %%% As \cweb{} operates in modes, for obvious reasons our implementation
84 %%% is based on a finite state automaton (FSA). The whole tag set is
85 %%% separated into subsets that are valid in certain states.
86
87 %%% The complete set of tags does not obey any name conventions, some tags
88 %%% are even in conflict with standard \LaTeX{} tags (e.g.\ |\\|). Most
89 %%% tags are used to render code pieces. With the introduction of states
90 %%% we can restrict the visibilities of these tags to those states where
91 %%% we typeset program parts. The needed functionality will be available
92 %%% in cseqs of our namespace, we'll map that to \cweave{}'s names in a
93 %%% group.
94
95 %%% Then we have to implement the rendering of chunks and sections, that's
96 %%% (more or less) a straight-forward task. Actually, we only set up the
97 %%% basic code pieces, the integration of section divisions in the actual
98 %%% \LaTeX{} document is a task of higher-level code; that integration
99 %%% depends heavily on the type of document. That also implies that we
100 %%% won't implement front or back matter material (document markup, table
101 %%% of contents, index, list of refinements, etc.)\ in this module.
102
103
104 %%% \sect Let's identify this module.
105
106 %%% \noindent The code below is explained in the implementation
107 %%% documentation of the \pkg{rcs} package.
108
109 %%% \beginprog
110 \begingroup
111 \def\RCSFile#1#2 $#3: #4 #5\endRCS $#6: #7 #8\endRCS{%
112 \def\date{#4}\def\id{v#7}%
113 \ProvidesFile{#1}[\date\space\id\space #2]%
114 }
115
116 \RCSFile{cwebbase.tex}{CWEAVE tags for LaTeX markup}
117 $StyleDate: 1995/11/07 17:55:19 $: 9999/00/00 \endRCS
118 $StyleRevision: 1.4 $: 0.0 \endRCS
119 \endgroup
120 %%% \endprog
121
122
123 %%% \sect This module is part of the supported \textsl{cweb-sty} bundle.
124 %%% Send bug reports, comments and repairs.
125
126 %%% It assumes that the canonical setup of my modules has happened and can
127 %%% be used herein. (In particular, the underscore is a letter.)
128
129
130 %%% \sect This module reserves the namespace |cwbb|. It assumes that
131 %%% |\cweb_warning| is bound either to |\PackageWarningNoLine| or
132 %%% |\ClassWarningNoLine|, depending on the environment.
133
134 %%% \beginprog
135 \ifx \cwbb@loaded\undefined
136 \def\cwbb@loaded{$StyleRevision: 1.4 $}
137 \else
138 \cweb_warning{cwebbase}%
139 {Some other package already uses namespace `cwbb'}
140 \fi
141 %%% \endprog
142
143
144 %%% \sect This is freely distributable software; you can redistribute it
145 %%% and/or modify it under the terms of the GNU General Public License as
146 %%% published by the Free Software Foundation; either version~2 of the
147 %%% License, or (at your option) any later version.
148
149 %%% This software is distributed in the hope that it will be useful, but
150 %%% \textbf{without any warranty}; without even the implied warranty of
151 %%% \textbf{merchantability} or \textbf{fitness for a particular purpose}.
152 %%% See the GNU General Public License for more details.
153
154 %%% You should have received a copy of the GNU General Public License in
155 %%% the file |License| along with this package; if not, write to the Free
156 %%% Software Foundation, Inc., 675~Mass Ave, Cambridge, MA~02139,~USA.
157
158
159 \ifx\hypertarget\undefined
160 \def\hypertarget#1#2{#2}
161 \def\hyperlink#1#2{#2}
162 \fi
163
164
165 %%% % ------------------------------------------------------------
166 %%% %
167 %%% % subdocument: The interface between CWEAVE and TeX
168 %%% %
169
170 %%% \input{cweave-spec}
171
172 %%% %
173 %%% % ------------------------------------------------------------
174
175
176
177
178 %%% \chap Interface of \pkg{cwebbase} module.
179
180 %%% \pkg{cwebbase} implements most of \cweave{} tags. It sets up tons of
181 %%% redefinable cseqs, all of them start with |Cweb|.
182 %%% %
183 %%% \begin{fixme}
184 %%% How do I document them? We need a configuration document anyhow. Do
185 %%% I present here just a list of those cseqs realized in this module
186 %%% and refer to the config docs? Need to wait until I have it, then
187 %%% we'll see how the stuff here will be added.
188 %%% \end{fixme}
189
190
191 %%% \sect This module supports both hierarchic and flat section
192 %%% structuring. You have to bind |\cweb@structure| to 0 (hierarchic) or 1
193 %%% (flat) before importing it, to show which structure is wanted.
194
195
196 %%% \sect This module supports suppression of different document parts.
197 %%% You have to define flags |@cweb@suppress@|\<foo>|@| with
198 %%% $\mbox{\<foo>} \in \{ |changehints|, |unchanged|, |format| \}$ to
199 %%% denote if suppression shall happen.
200
201
202 %%% \sect The counter |secnumdepth| must be~11 if chunks shall be
203 %%% numbered. That counter doesn't need to be set when this module is
204 %%% imported, it can be set locally during typesetting \cweb{} code.
205
206 %%% The definitions for flat structure assume that |secnumdepth| is~11
207 %%% during typesetting.
208
209
210 %%% \sect |\part|, |\chapter| (if available), and |\section| are used for
211 %%% \cweb{} section divisions (those with the lowest ranks). These
212 %%% commands will change the respective counters globally and will
213 %%% add toc lines and marks. You might want to prevent that by redefining
214 %%% |\addcontentsline| and |\mark|.
215
216 %%% Table of contents macros are not defined for the section divisions
217 %%% introduced by this module. You must either prevent that they are
218 %%% written to the |AUX| file at all; or you must define them.
219 %%% %
220 %%% \begin{fixme}
221 %%% Add explanation of introduced section divisions.
222 %%% \end{fixme}
223
224 %%% For flat structure, all section divisions are of type `|chunk|', like
225 %%% chunks. The section names start with `|\cwbbRank{|\<rank>|}|'. By
226 %%% default, |\cwbbRank| takes one argument and expands to the empty list
227 %%% -- this can be redefined for the table of contents.
228
229
230 %%% \sect The document end, as explained in the \cweave{} interface specs
231 %%% (chunk~\ref{spec:sec:docend}), is not implemented. That must be done
232 %%% by the user of this module -- if the back matter is to be processed at
233 %%% all.
234
235
236
237
238 %%% \chap Processing states.
239
240 %%% We have to typeset five different categories of material:
241 %%% Documentation, program pieces---embedded within the documentation and
242 %%% as large chunks, \TeX{} material within program pieces (i.e., comments
243 %%% and refinement names), and cross reference information. Since we need
244 %%% a complete other environment for the program pieces than for the rest
245 %%% we design ``states'' where we switch to appropriately.
246 %%% %
247 %%% \begin{enumerate}
248
249 %%% \item A chunk starts in the \textsl{documentation state}.
250
251 %%% \item |\B| switches to \textsl{program state}. This can happen in
252 %%% documentation and program state.
253
254 %%% \item While we process the argument of |\PB| we're in \textsl{restricted
255 %%% program state}; |\PB| may appear in documentation and in \TeX{}
256 %%% state. Since \TeX{} state can be switched on within restricted
257 %%% program state, |\PB| can appear within the argument of itself.
258
259 %%% \item In the arguments of |\C|, |\SHC|, and |\X| we switch to
260 %%% \textsl{\TeX{} state}. All these cseqs appear only in (restricted)
261 %%% program state, their official names are actually different. I.e., only
262 %%% in (restricted) program state these cseq are bound to the meaning
263 %%% described here.
264
265 %%% \item Cross reference information are attached to most chunks with
266 %%% refinements. This information is processed in \textsl{CR state}.
267 %%% After CR state material
268 %%% comes always the next chunk or the document end, i.e., material in
269 %%% documentation state.
270
271 %%% \end{enumerate}
272 %%% %
273 %%% This FSA is illustrated by the diagram in figure~\ref{fig:fsa}.
274
275 %%% \begin{figure}
276
277 %%% \begin{center}
278 %%% \chardef\\=`\\
279 %%% \input{cweb-fsa.latex}
280 %%% \end{center}
281
282 %%% \caption{The processing state's FSA. The automaton starts and ends in
283 %%% the ``documentation'' state.}
284 %%% \label{fig:fsa}
285
286 %%% \end{figure}
287
288 %%% |\cwbb@documentation| will switch to documentation state,
289 %%% |\cwbb@program| to program state, |\cwbb@Rprogram| to restricted
290 %%% program state, |\cwbb@tex| to \TeX{} state, and |\cwbb@CR| to CR state.
291 %%% If we're already in a state, the switch to this state shall be a
292 %%% permissible null operation.
293
294
295 %%% \sect The basic difference between these states can be named with
296 %%% two parameters: (1)~The cseq bindings in effect and (2)~the layout
297 %%% parameters used for paragraph makeup.
298
299 %%% In (restricted) program state and in CR state the text is output
300 %%% under the control of \cweave{}, and tagged by \cweave{}. The used
301 %%% tags are from a global namespace and should only be in effect during
302 %%% these states. We call this tag set the \textsl{\cweave{} bindings}. In the
303 %%% other two states the tags are largely defined by the user, the tag
304 %%% set is called the \textsl{user bindings}. The switch to another binding
305 %%% is always done locally, i.e., if we switch from documentation to
306 %%% restricted program state within a group we don't have to bother about
307 %%% the restauration of the user binding; it will be done automatically
308 %%% by \TeX{} at the end of the group. Nevertheless we must be able to
309 %%% switch from the \cweave{} bindings back to the user bindings which
310 %%% were in effect when we activated the \cweave{} bindings. This is
311 %%% needed for the \TeX{} state which is always activated within
312 %%% (restricted) program state.
313
314 %%% The parameters for \textsl{program layout} are really special ones
315 %%% since they need to support the indentation which shows the program
316 %%% structure. These parameters are used in program and in \TeX{} state.
317 %%% The \textsl{document layout} parameters established by the user are
318 %%% used in the other three states.
319
320 %%% The following table shall summarize this. $C$~denotes \cweave{}
321 %%% bindings, $U$~user bindings, $P$~program layout, and $D$~document
322 %%% layout. If an entry is empty, its value is not changed on entry in
323 %%% this state.
324 %%% %
325 %%% \begin{center}
326 %%% \DeleteShortVerb\|
327 %%% \begin{tabular}{r|c|c}
328 %%% \multicolumn1{c|}{\textsc{State}} & \textsc{Binding} & \textsc{Layout} \\[1pt]
329 %%% \hline
330 %%% documentation & $U$ & $D$ \\
331 %%% program & $C$ & $P$ \\
332 %%% restricted program & $C$ & \\
333 %%% \TeX{} & $U$ & \\
334 %%% CR & $C$ & $D$ \\
335 %%% \end{tabular}
336 %%% \MakeShortVerb\|
337 %%% \end{center}
338
339
340 %%% \sect Since the user bindings and the document layout is defined
341 %%% initially, we don't have to do anything if it's requested. Only if we
342 %%% change it, i.e., within |\cwbb@cweave_bindings| and
343 %%% |\cwbb@program_layout|, we redefine |\cwbb@user_bindings| and
344 %%% |\cwbb@doc_layout|. If they are eventually executed, they shall
345 %%% rebind themselves back to |\relax|. This way we can switch to
346 %%% documentation state as often as we want.
347
348 %%% \beginprog
349 \let\cwbb@user_bindings=\relax
350 \let\cwbb@doc_layout=\relax
351
352 \def\cwbb@documentation{%
353 \cwbb@user_bindings
354 \cwbb@doc_layout
355 }
356 \def\cwbb@Rprogram{\cwbb@cweave_bindings}
357
358 \def\cwbb@program{%
359 \cwbb@cweave_bindings
360 \cwbb@program_layout
361 }
362 \def\cwbb@tex{\cwbb@user_bindings}
363
364 \def\cwbb@CR{%
365 \cwbb@cweave_bindings
366 \cwbb@doc_layout
367 }
368 %%% \endprog
369
370
371
372
373 %%% \chap Saving and restoring control sequences.
374
375 %%% We have a lot of cseqs which are defined within the namespace of this
376 %%% module and which will be used with other names. This usage is in a
377 %%% controlled environment, namely neither in documentation nor in \TeX{}
378 %%% state. (I.e., the text processed is tagged by \cweave{}, not by humans;
379 %%% therefore we have a precise specification of the cseqs we have to
380 %%% accept.) We cannot work with groups where a cseq is just redefined
381 %%% and \TeX{} takes care for establishing the old binding again; when we
382 %%% switch from program state to \TeX{} state all the bindings which were
383 %%% in effect before the program state get active, i.e., in the
384 %%% documentation state, must be in effect again. We cannot simply
385 %%% consider the \TeX{} state as something parallel to program state, it
386 %%% must be a hierarchical relationship: In the program state values are
387 %%% set up which must be available after switching back from \TeX{} to
388 %%% program state.
389
390 %%% We save the current binding of a cseq in another cseq, but only if
391 %%% there exists a binding currently. This is done to save valuable
392 %%% \TeX{} main memory. (Why don't all those people who talk about
393 %%% extending \TeX{} not just implement dynamic memory management for the
394 %%% existing \TeX{}? It would still be \TeX{} and would \emph{really} be
395 %%% a worthy activity. But not enough fun, I assume\,\dots) Actually, one
396 %%% can assume that nearly no cseq bindings must be saved at all---the
397 %%% used names are strange enough. The bindings of |\foo|, i.e., of the
398 %%% cseq with the name \fbox{\ttfamily foo}, is saved as the cseq with the
399 %%% name \fbox{\ttfamily cweb\char `\\ foo}, i.e., as
400 %%% |\csname cweb\string\foo \endcsname|.
401
402
403 %%% \sect The save process is not done statically, but by the macro
404 %%% |\cwbb@rebind| which interprets a list of tuples $({\it old\_name},
405 %%% {\it new\_name})$, terminated by the tuple $(|\stop|, |\stop|)$.
406 %%% Eventually it constructs two new lists, |\cwbb@to_restore| with the
407 %%% cseqs which had a binding, and |\cwbb@undefined| with the names which
408 %%% didn't have one.
409
410 %%% The saving is actually done by |\cwbb@save_binding|, |\cwbb@rebind|
411 %%% is responsible for the initialization, |\cwbb@do_rebind| for the
412 %%% effective rebinding and the tail recursion on the list.
413
414 %%% \begin{fixme}
415 %%% We could pull the |\next| assignment in the |\else| branch out of
416 %%% the loop to get a better performance. Should measure if this is of
417 %%% interest.
418 %%% \end{fixme}
419
420 %%% \beginprog
421 \newtoks\cwbb@undefined
422 \newtoks\cwbb@to_restore
423
424 \def\cwbb@rebind{%
425 \cwbb@undefined{}%
426 \cwbb@to_restore{}%
427 \cwbb@do_rebind
428 }
429 \def\cwbb@do_rebind#1#2{%
430 \ifx #1\stop
431 \let\next\relax
432 \else
433 \cwbb@save_binding #2%
434 \let #2=#1%
435 \let\next\cwbb@do_rebind
436 \fi
437 \next
438 }
439 %%% \endprog
440
441
442 %%% \sect If the cseq to be saved is undefined, it may just be added to
443 %%% the ``undefined list.'' Otherwise its binding is saved and it's added
444 %%% to the ``to-be-restored list.''
445
446 %%% \TeX{}nical note: The cseq-name for the saved binding must be created
447 %%% before the |\let| is executed.
448
449 %%% \beginprog
450 \def\cwbb@save_binding#1{%
451 \ifx #1\undefined
452 \cwbb@undefined \expandafter{\the\cwbb@undefined #1}%
453 \else
454 \expandafter\let \csname cweb\string#1\endcsname =#1%
455 \cwbb@to_restore \expandafter{\the\cwbb@to_restore #1}%
456 \fi
457 }
458 %%% \endprog
459
460
461 %%% \sect The restoration of rebound cseqs is a two-tied activity: All
462 %%% previously undefined cseqs must be made undefined again, and all saved
463 %%% cseqs must be restored. Actually, we don't need to reset the two token
464 %%% lists, but we do it to save space.
465
466 %%% Both |\cwbb@undefine| and |\cwbb@restore_binding| iterate over a list
467 %%% of cseqs terminated by |\stop|.
468
469 %%% \begin{fixme}
470 %%% And here the |\next| assignment could be prepended to the loop as
471 %%% well.
472 %%% \end{fixme}
473
474 %%% \beginprog
475 \def\cwbb@restore_bindings{%
476 \expandafter\cwbb@undefine \the\cwbb@undefined \stop
477 \cwbb@undefined{}%
478 \expandafter\cwbb@restore_binding \the\cwbb@to_restore \stop
479 \cwbb@to_restore{}%
480 }
481
482 \def\cwbb@undefine#1{%
483 \ifx #1\stop
484 \let\next\relax
485 \else
486 \let#1\undefined
487 \let\next\cwbb@undefine
488 \fi
489 \next
490 }
491 %%% \endprog
492
493
494 %%% \sect \TeX{}nical note: As in |\cwbb@save_binding|, the cseq-name for
495 %%% the saved binding must be created before the |\let|s are executed.
496
497 %%% \begin{fixme}
498 %%% Another |\next| assignment.
499 %%% \end{fixme}
500
501 %%% \beginprog
502 \def\cwbb@restore_binding#1{%
503 \ifx #1\stop
504 \let\next\relax
505 \else
506 \expandafter\let \expandafter#1\csname cweb\string#1\endcsname
507 \expandafter\let \csname cweb\string#1\endcsname \undefined
508 \let\next\cwbb@restore_binding
509 \fi
510 \next
511 }
512 %%% \endprog
513
514
515
516
517 %%% \chap Chunks.
518
519 %%% All chunks are numbered subsequently. The chunk number is supplied as
520 %%% part of the markup. In addition, the `changed' tag |\*| may be
521 %%% appended to the chunk number.
522
523 %%% By default, chunks have approximately two picas vertical space in
524 %%% front.
525
526 %%% If we use an hierarchic structure, we output the chunk number at the
527 %%% refinement. (It's only needed to identify the refinement for cross
528 %%% references.) But chunks are important structural units and thus should
529 %%% be marked by typographic means that's more visible than the space
530 %%% mentioned above, we add a `chunk start marker'.
531
532 %%% For a flat structure, we output the chunk number as the chunk start
533 %%% marker, that is the traditional \WEB{} layout.
534
535 %%% In any case, the documentation part shall be run in after the chunk
536 %%% start marker.
537
538 %%% \beginprog
539 \newskip\CwebChunkPreSkip
540 \CwebChunkPreSkip=2pc plus 1pc minus 6pt
541 %%% \endprog
542
543
544 %%% \sect In \LaTeX{}, structural divisions are best realized by
545 %%% |\@startsection|, we'll use it also for chunk starts. The chunk start
546 %%% marker is the section heading. For hierarchic structure, we use a
547 %%% traditional paragraph sign, used since medieval times to tag new text
548 %%% units. Our first test showed that the paragraph sign has typically an
549 %%% underlength, that doesn't look good at the start of a chunk. We raise
550 %%% the sign by its depth.
551
552 %%% For flat structure, we don't have text as the section heading,
553 %%% but we have to cope for a deficiency of \LaTeX{}: It always leaves a
554 %%% quad after the section number (by the way, this is not mentioned in
555 %%% the documentation---you have to look in the macros to figure this
556 %%% out). So we use a backskip of $\rm -1\,em$ as the chunk start marker
557 %%% then.
558
559 %%% Changed chunks are marked by a changeflag, by default a star lapping
560 %%% to the right. We need the information if that chunk is changed to
561 %%% decide if we shall output the changeflag. We demand from the chunk
562 %%% macros that they record that info in the flag |@cwbb_changed_chunk@|.
563
564 %%% Each structural division must be categorized, it belongs to a
565 %%% \textsl{type}. This type determines also the name of the counter, the
566 %%% mark handling for this category, and how this section tag is
567 %%% represented in the table of contents. The type of chunks is `|chunk|'
568 %%% (trivial, isn't it?).
569
570 %%% Furthermore, a structural division in \LaTeX{} has an associated
571 %%% \textsl{level}. That level is used to determine if that division get
572 %%% numbered in text or table of contents. For sections, we'll compute the
573 %%% level from the rank, it will not be larger than the rank.%
574 %%% \footnote{Check the next section for a more precise definition of
575 %%% `rank' and `level'.}
576 %%% Since the highest section rank is~10, we may use 11 as chunk level.
577
578 %%% For flat structure, we output the number for all section headings,
579 %%% including chunks. For hierarchic structure we use the default maximum
580 %%% level as supplied by our document class (e.g., 3~for \cls{article},
581 %%% and 2~for \cls{report} or \cls{book}).
582
583 %%% As a last point, we have to care already for sections in flat
584 %%% structure. They will use the |chunk| category as well, we have to
585 %%% distinguish them in the table of contents. For that, we'll record the
586 %%% level in the text, it will get written to the table of contents.
587
588 %%% \beginprog
589 \newif\if@cwbb_changed_chunk@
590 \let\CwebChangeFlag=*
591 \if@cweb@suppress@changehints@
592 \let\cwbb@change_flag=\relax
593 \else
594 \let\cwbb@change_flag=\CwebChangeFlag
595 \fi
596 \def\cwbb@lap_change_flag{\rlap{\cwbb@change_flag}}
597
598 \ifcase \cweb@structure
599 %% hierarchic
600 \let\CwebChunkHeadingStyle\relax
601 \newbox\cweb@chunk_marker
602 \setbox\cweb@chunk_marker=\hbox{\P} % tradition from medivial times
603 \setbox\cweb@chunk_marker=\hbox{%
604 \raise\dp\cweb@chunk_marker \box\cweb@chunk_marker
605 }
606 \def\CwebChunkHeadingMarker{\copy\cweb@chunk_marker}
607 \def\CwebChunkHeading#1{%
608 \CwebChunkHeadingMarker
609 \if@cwbb_changed_chunk@ \cwbb@lap_change_flag \fi
610 }
611 \or
612 %% flat
613 \def\cwbbRank#1{}
614 \def\CwebChunkHeadingStyle{\bfseries}
615 \def\CwebChunkHeading#1{%
616 \protect\cwbbRank{#1}%
617 \kern -1em
618 \if@cwbb_changed_chunk@ \cwbb@lap_change_flag \fi
619 }
620 \fi
621 %%% \endprog
622
623
624 %%% \sect Chunks are tagged with |\M| and get passed the chunk number as
625 %%% argument. Before we evaluate |\@startsection|, we'll start the chunk.
626 %%% That's common code to be used by sections as well, as they also
627 %%% implicitely start a chunk.
628
629 %%% Enrique Mel\'endez (\texttt{[email protected]}) introduced some code to insert
630 %%% hyperlinks.
631
632 %%% \beginprog
633 \def\M#1{%
634 \cwbb@start_chunk{#1}%
635 \@startsection
636 {chunk}% % category, == counter etc.
637 {11}% % level
638 {\z@}% % no indentation for heading
639 {\CwebChunkPreSkip}% % skip above heading
640 {\m@ne em}% % run-in heading, 1em distance to text
641 {\normalfont\CwebChunkHeadingStyle}% % layout
642 {\CwebChunkHeading{11}}% % text, level might go to toc file
643 \hypertarget{_hypersect_#1}{}%
644 }
645 %%% \endprog
646
647
648 %%% \sect But let's first declare how a chunk number is represented. The
649 %%% principle rendering is controlled by |\thechunk|, namely, we get
650 %%% arabic numbers. This rendering is used both for creation of the
651 %%% section header (if in flat mode) and for cross references. I.e.,
652 %%% |\ref| expands into it.
653
654 %%% But for flat structure we need different expansions: In the section
655 %%% header a period shall be appended, a cross reference shall appear
656 %%% without such a period. We use two different macros: |\thechunk|
657 %%% creates the number with the period, |\cwbb@refchunk| only the number.
658 %%% The latter is used for a redefinition of |\@currentlabel|. Of course,
659 %%% for hierarchic structure, both are the same.
660
661 %%% \beginprog
662 \newcounter{chunk}
663
664 \def\cwbb@refchunk{\arabic{chunk}}
665
666 \ifcase \cweb@structure
667 %% hierarchic
668 \let\thechunk=\cwbb@refchunk
669 \or
670 %% flat
671 \def\thechunk{\arabic{chunk}.}
672 \fi
673 %%% \endprog
674
675
676 %%% \sect Each chunk is started by |\cwbb@start_chunk|, which does the
677 %%% common actions. First of all, we switch to documentation state.
678
679 %%% Then we store the chunk number in the |chunk| counter. That implies
680 %%% that the chunk start must not step this counter! We'll take care for
681 %%% that later by redefining |\refstepcounter|. The actual number is
682 %%% passed as the argument, including an optional |\*| used to denote
683 %%% changed chunks. We'll redefine that cseq to update the flag
684 %%% |@cwbb_changed_chunk@|.
685
686 %%% Each chunk must be typeset with an open |\if| since it is finished by
687 %%% |\fi|. If we shall suppress the output of unchanged chunks, we have
688 %%% to use |\iffalse| if not |@cwbb_changed_chunk@|, otherwise |\iftrue|.
689 %%% The flag |@cwbb_print_chunk@| is set up to provide an appropriate
690 %%% test.
691
692 %%% When we typeset a chunk, we evaluate |\cwbb@init_print_chunk|. For
693 %%% hierarchic structure, that cseq will be used to initialize the
694 %%% typesetting of the chunk number at program parts.
695
696 %%% \beginprog
697 \if@cweb@suppress@unchanged@
698 \def\if@cwbb_print_chunk@{\if@cwbb_changed_chunk@}
699 \@gobble\fi % close \if in case it's skipped
700 \else
701 \let\if@cwbb_print_chunk@=\iftrue
702 \@gobble\fi % same here
703 \fi
704
705 \def\cwbb@start_chunk#1{%
706 \cwbb@documentation
707 % \hypertarget{_hypersect_#1}{}%
708 %%\hypertarget{_hyperchunk_#1}{}%
709 \begingroup
710 \def\*{\global\@cwbb_changed_chunk@true}%
711 \global\@cwbb_changed_chunk@false
712 \global \c@chunk #1\relax % might expand \*
713 \endgroup
714 \if@cwbb_print_chunk@
715 \cwbb@init_print_chunk
716 }
717 %%% \endprog
718
719
720 %%% \sect |\@startsection| will step the section counter (i.e., |chunk|).
721 %%% Since we just assigned it in |\cwbb@start_chunk|, that would leave us
722 %%% with a counter that's one too high. And our output in cross references
723 %%% may be wrong, as a period is appended in flat structure.
724
725 %%% That damage all comes from one macro, |\refstepcounter|; let's
726 %%% advice it to do the Right Thing for |chunk| counters.
727
728 %%% \beginprog
729 \let\cwbb@refstepcounter=\refstepcounter
730
731 \def\cwbb@string@chunk{chunk}
732 \def\refstepcounter#1{%
733 \def\@tempa{#1}%
734 \ifx \@tempa\cwbb@string@chunk
735 \protected@edef\@currentlabel{\cwbb@refchunk}%
736 \else
737 \cwbb@refstepcounter{#1}%
738 \fi
739 }
740 %%% \endprog
741
742
743
744
745 %%% \chap Sections.
746
747 %%% Important sections are started on a new page, normal sections have the
748 %%% same space as chunks in front. The very first section does not
749 %%% automatically start on a new page since a title may be in front of it.
750
751 %%% Each section division has a \textsl{rank}, that denotes the section
752 %%% depth as seen by \cweave{}.
753
754 %%% For this depth we compute a \textsl{level}, used to denote the section
755 %%% depth for \LaTeX{}. This section depth is used to decide where
756 %%% numbering shall stop, or if that entry shall be presented in the table
757 %%% of contents, etc.
758
759 %%% These two numbers are not the same, due to the support of document
760 %%% classes with chapters.
761
762 %%% We consider a section as important if it's rank is smaller than~3,
763 %%% i.e., then we'll start a new page. This limit is controlled by the
764 %%% number |\CwebRankNoEject|. The rank is used as the section level
765 %%% and is therefore available to configure depth of typeset numbering and
766 %%% appearance in table of contents.
767
768 %%% \beginprog
769 \def\CwebRankNoEject{3}
770 %%% \endprog
771
772
773 %%% \sect Sections are started with the macro |\N|. It's first parameter
774 %%% is the section's rank. The second parameter is the chunk number, the
775 %%% third the title of the section. This last parameter must be terminated
776 %%% by a dot.
777
778 %%% Each section implicitly starts a chunk. As explained above, major
779 %%% sections may eject the page, and we add our actual section heading
780 %%% with |\CwebSection|.
781
782 %%% We also tell the user that we have reached the next section by telling
783 %%% him about the current chunk number. The message is output after the
784 %%% section header is set, it shall be on the correct page. Since the
785 %%% token list to be output is expanded at shipout time, we must take care
786 %%% for the immediate expansion ourselves.
787
788 %%% Enrique Mel\'endez (\texttt{[email protected]}) introduced some code to insert
789 %%% hyperlinks.
790 %%% \beginprog
791 \def\N#1#2#3.{%
792 \cwbb@start_chunk{#2}%
793 \CwebEjectSection{#1}%
794 \hypertarget{_hypersect_#2}{}%
795 \CwebSection{#1}{#3}%
796 \begingroup
797 \def\*{}%
798 \edef\tmp{*#2}%
799 \message \expandafter{\tmp}%
800 \endgroup
801 }
802 %%% \endprog
803
804
805 %%% \sect At the start of a section we usually eject the page if our rank
806 %%% is not too low. But if the user had a title above the first section,
807 %%% he won't want this page break. So we try to guess it. If we guess
808 %%% wrong, the user may either add |\newpage| himself or he may redefine
809 %%% |\CwebEjectSection| in a package.
810
811 %%% \beginprog
812 \def\CwebEjectSection#1{% % #1 == rank
813 \gdef\CwebEjectSection##1{%
814 \relax
815 \ifnum ##1<\CwebRankNoEject\relax
816 \newpage
817 \fi
818 }%
819 }
820
821 \if@titlepage
822 \CwebEjectSection{}
823 \fi
824 %%% \endprog
825
826
827 %%% \sect Now comes a heary piece. We have 11~section ranks, and need 11
828 %%% different section categories, section counters, etc. For flat
829 %%% structure, they shall all do the same; for hierarchic structure, they
830 %%% shall be really different.
831
832 %%% \noindent Let's have a look at the hierarchic structure first, it's
833 %%% more complex.
834 %%% %
835 %%% \begin{itemize}
836
837 %%% \item We associate section rank~0 (that's `|@**|') with document
838 %%% parts, i.e., map it to |\part|. Many smaller programs won't use it.
839
840 %%% \item If we are used in a class that has a bound cseq |\chapter|, we
841 %%% associate rank~1 (`|@*0|') with it and rank~2 (`|@*1|') with
842 %%% |\section|. Otherwise we associate rank~1 with |\section|. These
843 %%% tags (|\chapter| and/or |\section|) must be defined because many
844 %%% macros that want to create section divisions will use them.
845
846 %%% \item All other section ranks are placed below |\section|.
847 %%% |\subsection| and other \LaTeX{} style markup is not supported.
848
849 %%% For hierarchic structure, we identify these sections with category
850 %%% names `|section|$l$', where $l$ is the respective level, computed
851 %%% from the rank. Those section names do not exist yet, we have to
852 %%% create them.
853
854 %%% \end{itemize}
855
856 %%% Now we come to the point why we can't use the rank as the section
857 %%% level passed to \LaTeX{}: When we assume the level usage of \LaTeX{}'s
858 %%% standard classes, |\section| is \emph{always} on level~1, independent
859 %%% of the existence of |\chapter|. The latter is placed on level~0, its
860 %%% existence only influences the section level of |\part|, which is
861 %%% either $-1$ or~0.
862
863 %%% This implies that |\subsection| in a standard class is always on
864 %%% level~2, but our equivalent section division is either `|@*0|'
865 %%% (rank~1) or `|@*1|' (rank~2). I.e., when we have chapters, we use a
866 %%% level that's one lower than the rank, otherwise we use the rank.
867
868 %%% For flat structure, we use type |chunk|. This way we'll use the chunk
869 %%% numbers, they are already set up.
870
871 %%% For flat structure, we will map all ranks to the same section markup.
872 %%% This markup will also be accessible by |\section| or |\chapter|. They
873 %%% will be declared to be on a level that is the same as the rank.
874
875
876 %%% \sect The printed representation of a section divison number is simply
877 %%% the presentation from the next upper level, a full stop, and an arabic
878 %%% section number. When we compute the name of the previous level we must
879 %%% pay attention to our first section division created this way. This
880 %%% division must be placed below |section|, without any following number.
881
882 %%% Since registers are a valuable resource in \TeX{}, we have to take
883 %%% care not to allocate a superfluous one.
884
885 %%% \beginprog
886 \def\toclevel@chunk{12}
887 \def\theHchunk{chunk.\arabic{chunk}}
888 \ifcase \cweb@structure
889 %% hierarchic
890 \newcounter{section2}[section]
891 \@namedef{thesection2}{\@nameuse{thesection}.\arabic{section2}}
892 \newcounter{section3}[section2]
893 \@namedef{thesection3}{\@nameuse{thesection2}.\arabic{section3}}
894 \newcounter{section4}[section3]
895 \@namedef{thesection4}{\@nameuse{thesection3}.\arabic{section4}}
896 \newcounter{section5}[section4]
897 \@namedef{thesection5}{\@nameuse{thesection4}.\arabic{section5}}
898 \newcounter{section6}[section5]
899 \@namedef{thesection6}{\@nameuse{thesection5}.\arabic{section6}}
900 \newcounter{section7}[section6]
901 \@namedef{thesection7}{\@nameuse{thesection6}.\arabic{section7}}
902 \newcounter{section8}[section7]
903 \@namedef{thesection8}{\@nameuse{thesection7}.\arabic{section8}}
904 \newcounter{section9}[section8]
905 \@namedef{thesection9}{\@nameuse{thesection8}.\arabic{section9}}
906 %
907 \@namedef{theHsection2}{\@nameuse{thesection}.\arabic{section2}}
908 \@namedef{theHsection3}{\@nameuse{thesection2}.\arabic{section3}}
909 \@namedef{theHsection4}{\@nameuse{thesection3}.\arabic{section4}}
910 \@namedef{theHsection5}{\@nameuse{thesection4}.\arabic{section5}}
911 \@namedef{theHsection6}{\@nameuse{thesection5}.\arabic{section6}}
912 \@namedef{theHsection7}{\@nameuse{thesection6}.\arabic{section7}}
913 \@namedef{theHsection8}{\@nameuse{thesection7}.\arabic{section8}}
914 \@namedef{theHsection9}{\@nameuse{thesection8}.\arabic{section9}}
915 \@namedef{toclevel@section2}{2}
916 \@namedef{toclevel@section3}{3}
917 \@namedef{toclevel@section4}{4}
918 \@namedef{toclevel@section5}{5}
919 \@namedef{toclevel@section6}{6}
920 \@namedef{toclevel@section7}{7}
921 \@namedef{toclevel@section8}{8}
922 \@namedef{toclevel@section9}{9}
923 \ifx \chapter\undefined
924 \newcounter{section10}[section9]
925 \@namedef{thesection10}{\@nameuse{thesection9}.\arabic{section10}}
926 \@namedef{theHsection10}{\@nameuse{theHsection9}.\arabic{section10}}
927 \@namedef{toclevel@section10}{10}
928 \else
929 \fi
930 \fi
931 %%% \endprog
932
933
934 %%% \sect Sections are typeset by |\CwebSection|; rank and title are the
935 %%% arguments.
936
937 %%% For hierarchic structure, we select the proper cseq according to rank:
938 %%% |\part|, |\chapter| if this is a structure with chapters, |\section|,
939 %%% and |\cwbb@section{|\<rank>|}| for other ranks. For the last cseq we
940 %%% also have to supply the section category, it's `|section|$l$' where
941 %%% $l$ is the rank~$r$ if we don't have chapters, $r-1$ otherwise.
942
943 %%% That category cannot be computed by |\cwbb@section| itself since we
944 %%% want to use that macro also for flat structure. But there all sections
945 %%% are basically chunks, we have to use the |chunk| category there. Since
946 %%% we want to differentiate them in the table of contents nevertheless,
947 %%% we record the current rank in the title.
948
949 %%% \beginprog
950 \ifcase \cweb@structure
951 %% hierarchic
952 \ifcase\cweb@cls
953 \ifx \chapter\undefined
954 \def\CwebSection#1#2{%
955 \ifcase #1
956 %% 0
957 \let\next\part
958 \or %% 1
959 \let\next\section
960 \else %% level = rank
961 \def\cwbb@sect_name{section#1}%
962 \def\next{\cwbb@section{#1}}%
963 \fi
964 \next{#2}%
965 }
966 \else
967 \def\CwebSection#1#2{%
968 \ifcase #1
969 %% 0
970 \let\next\part
971 \or %% 1
972 \let\next\chapter
973 \or %% 2
974 \let\next\section
975 \else %% level = rank - 1
976 \count@=#1 \advance \count@\m@ne
977 \edef\cwbb@sect_name{section\number\count@}%
978 \edef\next{\noexpand\cwbb@section{\number\count@}}%
979 \fi
980 \next{#2}%
981 }
982 \fi
983 \or %% In case we are included from other classes
984 %%
985 \ifx \chapter\undefined
986 \def\CwebSection#1#2{%
987 \count@=#1 \advance \count@\@ne\advance \count@\@ne
988 \edef\cwbb@sect_name{section\number\count@}%
989 \edef\next{\noexpand\cwbb@section{\number\count@}}%
990 \next{#2}%
991 }
992 \else
993 \def\CwebSection#1#2{%
994 \ifcase #1
995 %% 0
996 \let\next\chapter
997 \or %% 1
998 \let\next\section
999 \else %% level = rank
1000 \def\cwbb@sect_name{section#1}%
1001 \def\next{\cwbb@section{#1}}%
1002 \fi
1003 \next{#2}%
1004 }
1005 \fi
1006 \fi
1007 \or
1008 %% flat
1009 \def\CwebSection#1#2{%
1010 \def\cwbb@sect_name{chunk}%
1011 \cwbb@section{#1}{\protect\cwbbRank{#1}#2}%
1012 }
1013 \def\section{%
1014 \def\cwbb@sect_name{chunk}%
1015 \cwbb@section{1}%
1016 }
1017 \fi
1018 %%% \endprog
1019
1020
1021 %%% \sect We use the same layout for all minor sections. That layout can
1022 %%% be changed by ammended by defining |\CwebSect|$r$|Hook| to redefine
1023 %%% |\CwebSectPreSkip| and/or |\CwebSectLayout| locally. (Of couse, it may
1024 %%% be redefined once globally, too.) These are the values to be used for
1025 %%% arguments 4 and~5 of |\@startsection|, pay attention to the skip sign,
1026 %%% telling about indentation of the first paragraph. And don't forget
1027 %%% that the skip is only used for sections on ranks below
1028 %%% |\CwebRankNoEject|, the others start on a new page anyhow.
1029
1030 %%% The default definition sets the section title in bold and leaves the
1031 %%% same space as before chunks. The first paragraph of the following
1032 %%% documentation has no indentation.
1033
1034 %%% Other layout changes (indentation for heading, etc.)\ must be made by
1035 %%% redefining |\cwbb@section|. Or---email me, if you want to do it. Then
1036 %%% I might be enclined to introduce further possibilities.
1037
1038 %%% \beginprog
1039 \newskip\CwebSectPreSkip
1040 \CwebSectPreSkip = -\CwebChunkPreSkip
1041 \def\CwebSectLayout{\normalfont\bfseries}
1042
1043 \def\cwbb@section#1{% % #2 (next token) is title
1044 \csname CwebSect#1Hook\endcsname % \relax if undefined
1045 \expandafter\@startsection
1046 \expandafter{\cwbb@sect_name}% % category; for counter, etc.
1047 {#1}% % level is rank
1048 \z@ % no indentation for heading
1049 \CwebSectPreSkip % skip above, maybe no next par indent
1050 \medskipamount % skip below heading
1051 \CwebSectLayout
1052 }
1053 %%% \endprog
1054
1055
1056
1057
1058 %%% \chap Marks.
1059
1060 %%% \begin{fixme}
1061 %%% Since I don't know yet how to handle marks I ignore most of them for
1062 %%% the time being.
1063
1064 %%% Have to change this later.
1065 %%% \end{fixme}
1066
1067 %%% \beginprog
1068 \let\chunkmark\@gobble
1069
1070 \count@=2
1071 \@whilenum \count@<11 \do {
1072 \expandafter\let \csname section\number\count@ mark\endcsname \@gobble
1073 \advance \count@ by 1
1074 }
1075 %%% \endprog
1076
1077
1078
1079
1080 %%% \chap Typesetting programs.
1081
1082 %%% Program pieces come in two flavours: as argument of |\PB|, or as
1083 %%% material after |\B|. In the former case we can use a group for the
1084 %%% switch to the restricted program state, the group end will restore the
1085 %%% previous state again. In the latter case we use |\B| for the switch to
1086 %%% program state, the cross reference list or the next chunk will go to
1087 %%% another state. Since we have to do more for the material after |\B|,
1088 %%% we define this cseq later.
1089
1090 %%% \beginprog
1091 \def\PB#1{%
1092 \begingroup
1093 \cwbb@Rprogram
1094 \leavevmode
1095 #1%
1096 \endgroup
1097 }
1098 %%% \endprog
1099
1100
1101 %%% \sect Note, that |\Y| cannot just be |\smallskip|, as in Plain
1102 %%% \cweb{}. We must assert that the current paragraph is ended before the
1103 %%% vertical glue is inserted, and that's not done by the \LaTeX{}
1104 %%% definition of |\smallskip|. In addition we add some negative penalty,
1105 %%% here is a good place for a page break. As the penalty value we use
1106 %%% half the chunk break penalty---of course a chunk start is an even
1107 %%% better place for a page break\,\dots
1108
1109 %%% It might be that |\Y| is the very first token in a chunk. Then the
1110 %%% chunk start marker isn't set already since it is regarded as a run-in
1111 %%% section heading. In that case we don't set the vertical skip but
1112 %%% simply start the chunk with the program part.
1113
1114 %%% \TeX{}nical note: The flag |@noskipsec| may be used to test if we're
1115 %%% immediately after a run-in section heading.
1116
1117 %%% \beginprog
1118 \newcount\CwebProgPenalty
1119 \CwebProgPenalty=\@secpenalty
1120 \divide\CwebProgPenalty by 2
1121 \def\Y{%
1122 \if@noskipsec
1123 \else
1124 \par
1125 \penalty\CwebProgPenalty
1126 \smallskip
1127 \fi
1128 }
1129 %%% \endprog
1130
1131
1132 %%% \sect Yep, let's unfold the ``official'' names of the cseqs used in
1133 %%% program state.
1134
1135 %%% If we turn on the \cweave{} bindings, they might be in effect already,
1136 %%% we don't need to establish them again. We can test
1137 %%% |\cwbb@user_bindings| for this case, it will be redefined then.
1138
1139 %%% \beginprog
1140 \def\cwbb@cweave_bindings{%
1141 \ifx \cwbb@user_bindings\relax
1142 \cwbb@rebind
1143 % indentation and paragraph layout
1144 \cwbb@incr_indent \1%
1145 \cwbb@decr_indent \2%
1146 \cwbb@expr_break \3%
1147 \cwbb@backup \4%
1148 \cwbb@opt_break \5%
1149 \cwbb@break \6%
1150 \cwbb@big_break \7%
1151 \cwbb@noindent \8%
1152 % C/C++ tokens
1153 \CwebRel \?%
1154 \CwebAddress \AND
1155 \CwebComplement \CM
1156 \CwebScope \DC
1157 \CwebEquiv \E
1158 \CwebGe \G
1159 \CwebRightShift \GG
1160 \CwebNe \I
1161 \CwebAssign \K
1162 \CwebLeftShift \LL
1163 \CwebMod \MOD
1164 \CwebNull \NULL
1165 \CwebNot \R
1166 \CwebBinOr \OR
1167 \CwebMemberRef \PA
1168 \CwebThis \this
1169 \CwebOr \V
1170 \CwebAnd \W
1171 \CwebXor \XOR
1172 \CwebLe \Z
1173 \CwebPointer \MG
1174 \CwebPointerMemberRef \MGA
1175 \CwebDecr \MM
1176 \CwebIncr \PP
1177 % more tokens
1178 \CwebId \\%
1179 \CwebIdLetter \|%
1180 \CwebRes \&%
1181 \CwebString \.% %% ( ...Emacs...
1182 \CwebStringBreak \)%
1183 \CwebNumber \T
1184 \CwebCombinedOp \MRL
1185 % goes to TeX state
1186 \CwebComment \C
1187 \CwebCxxComment \SHC
1188 \CwebRefName \X
1189 % CWEB tokens
1190 \CwebMacrosHere \ATH
1191 \CwebDefine \D
1192 \cwbb@format \F
1193 \CwebIdCat \J
1194 \CwebVerbString \vb
1195 % cross reference tags
1196 \cwbb@change_flag \*%
1197 \CwebCRAlso \A
1198 \CwebCRsAlso \As
1199 \CwebCRCite \Q
1200 \CwebCRsCite \Qs
1201 \CwebCRUse \U
1202 \CwebCRsUse \Us
1203 \CwebCREt \ET
1204 \CwebCRsEt \ETs
1205 % finish the list
1206 \stop\stop
1207 \def\cwbb@user_bindings{%
1208 \cwbb@restore_bindings
1209 \let\cwbb@user_bindings\relax
1210 }%
1211 \fi
1212 }
1213 %%% \endprog
1214
1215
1216 %%% \sect Since most of the \cweave{} bindings are simple and tedious
1217 %%% coding, we'll have a look at the program layout next. Between two
1218 %%% paragraphs there must not be any skip, the skip used in document
1219 %%% layout is saved in |\cwbb@save@parskip|. A few other layout
1220 %%% parameters from the document layout must be saved as well.
1221
1222 %%% \beginprog
1223 \newskip\cwbb@save@parskip
1224 \newskip\cwbb@save@rightskip
1225 \newcount\cwbb@save@sem_sfcode
1226 \newcount\cwbb@save@pretolerance
1227 \newcount\cwbb@save@hyphenpenalty
1228 \newcount\cwbb@save@exhyphenpenalty
1229
1230 \def\cwbb@save_doc_layout{%
1231 \cwbb@save@parskip\parskip
1232 \cwbb@save@rightskip\rightskip
1233 \cwbb@save@sem_sfcode\sfcode`\;
1234 \cwbb@save@pretolerance\pretolerance
1235 \cwbb@save@hyphenpenalty\hyphenpenalty
1236 \cwbb@save@exhyphenpenalty\exhyphenpenalty
1237 }
1238 \def\cwbb@restore_doc_layout{%
1239 \parskip\cwbb@save@parskip
1240 \rightskip\cwbb@save@rightskip
1241 \sfcode`\;=\cwbb@save@sem_sfcode
1242 \pretolerance\cwbb@save@pretolerance
1243 \hyphenpenalty\cwbb@save@hyphenpenalty
1244 \exhyphenpenalty\cwbb@save@exhyphenpenalty
1245 }
1246 %%% \endprog
1247
1248
1249 %%% \sect When |\cwbb@program_layout| is called for the very first time
1250 %%% we have to set up some variables. This cannot be done in advance
1251 %%% since they depend on values which might be changed by the user in the
1252 %%% preamble. This setup is done in |\cwbb@layout_init|.
1253
1254 %%% If the program layout is already active, we must not switch it on
1255 %%% another time. This can be tested by the current binding of
1256 %%% |\cwbb@doc_layout|.
1257
1258 %%% \beginprog
1259 \def\cwbb@program_layout{%
1260 \ifx \cwbb@doc_layout\relax
1261 \cwbb@layout_init
1262 \cwbb@save_doc_layout
1263 \def\cwbb@doc_layout{%
1264 \cwbb@restore_doc_layout
1265 \let\cwbb@doc_layout\relax
1266 }%
1267 % set new values
1268 \parskip\z@skip
1269 \rightskip\z@ plus 100\p@ minus 10\p@
1270 \sfcode`\;=3000
1271 \pretolerance\@M
1272 \hyphenpenalty 1000 % strings can be broken this way
1273 \exhyphenpenalty\@M
1274 \fi
1275 }
1276 %%% \endprog
1277
1278
1279 %%% \sect The unit of the basic indentation is stored in
1280 %%% |\CwebIndentUnit|. Continuation lines are indented two units further,
1281 %%% i.e., the initial hanging indentation is 3~units. The current hanging
1282 %%% indentation is kept in |\cwbb@indent|.
1283
1284 %%% We need undiscardable items which can be used as backspaces, of one
1285 %%% and two units, respectively. This is done best by boxes. The
1286 %%% initialization of the boxes must be postponed until the user had the
1287 %%% chance to change |\CwebIndentUnit|, it's done in the program state
1288 %%% initialization.
1289
1290 %%% \beginprog
1291 \newdimen\CwebIndentUnit
1292 \CwebIndentUnit=1em
1293 \newdimen\cwbb@indent
1294
1295 \newbox\cwbb@bak % backspace one unit
1296 \newbox\cwbb@bakk % backspace two units
1297
1298 \def\cwbb@layout_init{%
1299 \global\setbox\cwbb@bak \hbox to -1\CwebIndentUnit{}%
1300 \global\setbox\cwbb@bakk \hbox to -2\CwebIndentUnit{}%
1301 \global\let\cwbb@layout_init\relax
1302 }
1303 %%% \endprog
1304
1305
1306 %%% \sect Now we can formulate how to start typesetting program pieces: We
1307 %%% switch to program state, set the initial indentation, and add the
1308 %%% basic indentation of the first code line. Then we might add a marker
1309 %%% to this program part; for hierarchic structure we want to typeset the
1310 %%% chunk number in the margin of the chunk's program part. That's not
1311 %%% really possible, 'though: definitions and format requests are also
1312 %%% introduced with |\B|, so the chunk number will happen to be at the
1313 %%% start of the definition part if one exists.
1314
1315 %%% If the code line is the very first text to be typeset in this chunk,
1316 %%% we don't add the basic indentation---we're already indented from the
1317 %%% run-in chunk start marker. But we must not start our chunk with
1318 %%% |\noindent|, the marker would be typeset in the left margin then. (I
1319 %%% consider this as a \LaTeX{} error.) So we just emulate an empty
1320 %%% documentation part, the marker is now set correctly. |\B| can test for
1321 %%% this case: |@noskipsec| is still true then.
1322
1323 %%% \beginprog
1324 \def\B{%
1325 \cwbb@program
1326 \cwbb@indent 3\CwebIndentUnit \hangindent\cwbb@indent
1327 \ifvmode
1328 \if@noskipsec
1329 \indent % add an empty documentation part
1330 \else
1331 \noindent \kern\CwebIndentUnit
1332 \fi
1333 \fi
1334 \CwebNumberProgramPart
1335 }
1336 %%% \endprog
1337
1338
1339 %%% \sect The chunk number shall be added at the first program part. We
1340 %%% have a hook in the chunk start where we can set up
1341 %%% |\CwebNumberProgramPart|. It will redefine itself at first call, to
1342 %%% disable further output on more |\B| occurences in a chunk.
1343
1344 %%% The chunk number should always be in the left margin. If it's in the
1345 %%% right margin, there would be too much horizontal space between the
1346 %%% code start and the actual number. (The first code line is typically
1347 %%% not very long.) \LaTeX{} does not allow to select the margin for
1348 %%% marginpars, therefore we have to typeset the marginal note `by hand'.
1349 %%% As we know that we're in horizontal mode when we're called, |\vadjust|
1350 %%% is used to create the note. The standard \LaTeX{} dimen register for
1351 %%% the distance between marginal notes and text matter is used, of
1352 %%% course.
1353
1354 %%% Note that marginal notes may overwrite the chunk number. As it's very
1355 %%% unlikely that somebody issues marginal notes in program mode (that's
1356 %%% quite difficult and involves ingenious usage of the implementation of
1357 %%% this macros), I won't care for that case.
1358
1359 %%% \begin{fixme}
1360 %%% The baseline of the marginal note shall be aligned to the baseline
1361 %%% of the preceding line. That does not happen by default. Currently, I
1362 %%% assume that the preceding line has a depth of appropriately the
1363 %%% depth of a~`g'. Experiments showed that this gives good results for
1364 %%% most \cweb{} documents. But nevertheless one should determine the
1365 %%% exact depth of the preceding line, to know how much |box0| should be
1366 %%% raised. If anybody knows how this can be done, please tell me. (I
1367 %%% know about the route over the output routine, implementing an own
1368 %%% marginal note category, but this seems too much effort.)
1369 %%% \end{fixme}
1370
1371 %%% For flat structure, we don't add any program part marker and we
1372 %%% don't need to initialize it.
1373
1374 %%% Enrique Mel\'endez (\texttt{[email protected]}) introduced some code to insert
1375 %%% hyperlinks.
1376 %%% \beginprog
1377 \ifcase \cweb@structure
1378 %% hierarchic
1379 \def\cwbb@marginal_chunkno{%
1380 \vadjust{%
1381 \setbox\z@ \hbox to \z@{%
1382 \hss \vphantom{g}%
1383 \hypertarget{_hyperchunk_\thechunk}{%
1384 \small \thechunk
1385 }%
1386 \hskip \marginparsep
1387 }%
1388 \vbox to \z@{%
1389 \hsize\z@
1390 \vss
1391 \noindent \raise \dp\z@ \box\z@
1392 }%
1393 }%
1394 }
1395 \def\cwbb@init_print_chunk{%
1396 \def\CwebNumberProgramPart{%
1397 %\hypertarget{_hyperchunk_\thechunk}{%
1398 \cwbb@marginal_chunkno%}
1399 \let\CwebNumberProgramPart\relax
1400 }%
1401 }
1402 \or
1403 %% flat
1404 \let\cwbb@init_print_chunk\relax
1405 \let\CwebNumberProgramPart\relax
1406 \fi
1407 %%% \endprog
1408
1409
1410 %%% \sect If a statement is finished, a new paragraph with the basic
1411 %%% indentation has to be started.
1412
1413 %%% An optional statement break is implemented by a low penalty which
1414 %%% will be selected if the line has to be broken. We assume that the
1415 %%% hanging indentation of the new line is already set correctly, and
1416 %%% have to backup two units to get the basic indentation. It might be
1417 %%% that the line break is not chosen by \TeX{}, we compensate the
1418 %%% backspace for this case. This compensation is discarded at the start
1419 %%% of a new line.
1420
1421 %%% \beginprog
1422 \def\cwbb@break{% % forced break, between statements
1423 \ifmmode\else
1424 \endgraf % in LaTeX it isn't sure what \par is really...
1425 \noindent
1426 \hangindent\cwbb@indent \kern\cwbb@indent
1427 \copy\cwbb@bakk % go back to basic indentation
1428 \ignorespaces
1429 \fi
1430 }
1431 \def\cwbb@opt_break{% % optional break between statements
1432 \hfil \penalty\m@ne
1433 \hfilneg \kern .5em \kern 2\CwebIndentUnit % discarded on line break
1434 \copy\cwbb@bakk
1435 \ignorespaces
1436 }
1437 \def\cwbb@big_break{% % forced break and a little extra space
1438 \Y
1439 \cwbb@break
1440 }
1441 \def\cwbb@expr_break#1{% % break with penalty #1 * 10
1442 \hfil \penalty#10
1443 \hfilneg % discarded on line break
1444 }
1445 %%% \endprog
1446
1447
1448 %%% \sect When we increment the indentation, we must not forget to set
1449 %%% the hanging indentation immediately since |\cwbb@opt_break| relies on
1450 %%% the new value. If a continuation line is needed it will also be
1451 %%% indented one unit more, which is ok since it should be distinguishable
1452 %%% from the next line.
1453 %%% %
1454 %%% \begin{fixme}
1455 %%% Shouldn't the hanging indentation be set anew at the end of
1456 %%% |\cwbb@decr_indent| as well?
1457 %%% \end{fixme}
1458
1459 %%% \beginprog
1460 \def\cwbb@incr_indent{%
1461 \global\advance\cwbb@indent\CwebIndentUnit
1462 \hangindent\cwbb@indent
1463 }
1464 \def\cwbb@decr_indent{\global\advance\cwbb@indent -\CwebIndentUnit}
1465 \def\cwbb@backup{\copy\cwbb@bak}
1466 \def\cwbb@noindent{% % no indentation
1467 \hskip -\cwbb@indent \hskip 2\CwebIndentUnit
1468 }
1469 %%% \endprog
1470
1471
1472
1473
1474 %%% \chap Program (C or \C++) tokens.
1475
1476 %%% Since the user might want to change the (somewhat unusual) way some
1477 %%% of the operators are typeset, we supply names for them.
1478
1479 %%% \beginprog
1480 \let\CwebAnd=\land % logical and, &&
1481 \let\CwebEquiv=\equiv % equiv sign, for ==
1482 \let\CwebGe=\ge % greater or equal
1483 \let\CwebLe=\le % less or equal
1484 \let\CwebNe=\ne % unequal, !=
1485 \let\CwebNull=\Lambda % NULL pointer
1486 \let\CwebNot=\lnot % logical not, !
1487 \let\CwebOr=\lor % logical or, ||
1488 \let\CwebXor=\oplus % bitwise exclusive or, ^
1489 %%% \endprog
1490
1491
1492 %%% \sect Some symbols have to be shifted around, to save computation time
1493 %%% we put them in boxes.
1494
1495 %%% \begin{fixme}
1496 %%% It's not sure if the following symbols still look good in other font
1497 %%% families than Computer Modern. The movements might need to get
1498 %%% adapted when more experience is available. They were chosen from
1499 %%% Plain \cweb{}, where these were explicit movements measured in
1500 %%% points. I changed the dimension to quads, to achieve at least the
1501 %%% support for different sizes in the Computer Modern family.
1502 %%% \end{fixme}
1503
1504 %%% \TeX{}nical note: The pointer symbol must not be declared as a math
1505 %%% symbol (e.g., with |\DeclareMathSymbol|). Then \TeX{} would insert an
1506 %%% italic correction behind it, according to rule~17 from appendix~G.
1507 %%% (Please send email if you know of an easy way to prevent that
1508 %%% addition.) So I use the symbol as an accent, but then I have to supply
1509 %%% a nucleus for this math list. That nucleus also determines the total
1510 %%% width of this construct. As the vector accent has a width of
1511 %%% approximately 5\,pt in |cmmi10|, I'm going to use 0.5\,em. (That
1512 %%% heuristic is as good as any other I can think of.)
1513
1514 %%% \beginprog
1515 %% pointer to struct component (`->'), use symbol of \vec accent
1516 \newbox\cwbb@pointer
1517 \setbox\cwbb@pointer=\hbox{%
1518 \kern -.2em
1519 \lower .3em \hbox{$\vec{\kern .5em}$}%
1520 \kern .1em
1521 }
1522
1523 \newbox\cwbb@decr % decrement, --
1524 \setbox\cwbb@decr=\hbox{%
1525 \kern .05em
1526 \raise .1em \hbox{$\scriptstyle {-}\kern -.1em{-}$}%
1527 \kern .05em
1528 }
1529 \newbox\cwbb@incr % increment, ++
1530 \setbox\cwbb@incr=\hbox{%
1531 \kern .05em
1532 \raise .1em \hbox{$\scriptstyle {+}\kern -.1em{+}$}%
1533 \kern .05em
1534 }
1535 %%% \endprog
1536
1537
1538 %%% \sect Although the following symbols are typeset like an ``ordinary
1539 %%% \C++ programmer'' would expect them, we provide own module names
1540 %%% nevertheless. They can now be changed as well, i.e., orthogonality is
1541 %%% enhanced. (And we can use |\cwbb@rebind| for assigning them to their
1542 %%% names while we switch to program state\,\dots).
1543
1544 %%% Note: The comment at |\CwebMod| says ``modulo/remainder'', as this is
1545 %%% not defined by the C standard, i.e., implementation-dependent.
1546
1547 %%% \beginprog
1548 \mathchardef\CwebAddress="2026 % `&', as binary op
1549 \let\CwebAssign== % assignment
1550 \let\CwebBinOr=\mid % binary or
1551 \def\CwebComplement{{\sim}} % `~', as ordinary symbol
1552 \def\CwebDecr{\copy\cwbb@decr} % decrement
1553 \def\CwebIncr{\copy\cwbb@incr} % increment
1554 \let\CwebLeftShift=\ll % left shift, <<
1555 \def\CwebMod{\mathbin{\hbox{\footnotesize\rm\%}}} % modulo/remainder, %
1556 \def\CwebMemberRef{\mathbin{.*}} % ptr to member (on object)
1557 \def\CwebPointer{\copy\cwbb@pointer}
1558 \def\CwebPointerMemberRef{\mathbin{\CwebPointer*}} % ptr to member (on ptr)
1559 \def\CwebRel{\mathrel?} % relation operator
1560 \let\CwebRightShift=\gg % right shift, >>
1561 \def\CwebScope{\kern.1em{::}\kern.1em} % scope resolution
1562
1563 \def\CwebThis{\CwebRes{this}} % reserved identifier `this'
1564 %%% \endprog
1565
1566
1567 %%% \sect The special identifier |\TeX| remains. In math mode it shall be
1568 %%% the identifier, in other modes the usual logo. We use the definition
1569 %%% supplied by DEK (or \textsc{Silvio Levy}?)\ from Plain \cweb{}.
1570
1571 %%% \beginprog
1572 \def\TeX{%
1573 {%
1574 \ifmmode\it\fi
1575 \mbox{T\kern-.1667em\lower.424ex\hbox{E}\hskip-.125emX}%
1576 }}
1577 %%% \endprog
1578
1579
1580 %%% \sect Some tokens don't have constant names, the name is supplied as
1581 %%% the argument.
1582
1583 %%% Identifiers are typeset in italics, reserved words and type names in
1584 %%% boldface, and strings in typewriter. For an underscore in the bold
1585 %%% words we use a line that's 50\,\% thicker as the usual line thickness.
1586 %%% -- But what is the usual line thickness. As Knuth uses 0.4\,pt for a
1587 %%% 10\,pt Computer Modern font, we'll use 0.06\,em for a CM font in an
1588 %%% arbitrary size. If that line thickness is still OK for other fonts is
1589 %%% doubtful, as it should fit to the stem width. (CM is a rather light
1590 %%% font, after all.) But since there is no font dimension that gives a
1591 %%% hint to an appropriate line thickness, it's our best try.
1592
1593 %%% \beginprog
1594 \def\CwebCombinedOp#1{\mathrel{\let\K==#1}} % e.g., += operator
1595 \def\CwebId#1{\hbox{\it#1\/\kern.05em}} % identifier, more than one char
1596 \def\CwebIdLetter#1{\hbox{$#1$}} % identifier, one letter
1597 \def\CwebRes#1{% % reserverd words and type names
1598 \hbox{\bf
1599 \def\_{\kern.04em\vbox{\hrule width.3em height.06em}\kern.08em}%
1600 #1\/\kern .05em
1601 }%
1602 }
1603 %%% \endprog
1604
1605
1606 %%% \sect In Plain \cweb{} strings are typeset in the font |cmtex10|,
1607 %%% which is a typewriter font with extended ASCII characters. This font
1608 %%% does not have the usual accents and can therefore not used for
1609 %%% typesetting national characters. (Very often they are input in some
1610 %%% 8-bit encoding, the respective character code is made active and is
1611 %%% substituted by a cseq which expands to the correct glyph. Of course,
1612 %%% there are better ways, but that's the reality we have to cope with.)
1613 %%% Instead of this special font we use the standard typewriter font.
1614 %%% This has the further advantage that |cmtex10| may not be introduced
1615 %%% to NFSS\@.
1616
1617 %%% \beginprog
1618 \def\CwebString{%
1619 \hbox \bgroup
1620 \tt
1621 \cwbb@string_setup
1622 \cwbb@string
1623 }
1624 \def\cwbb@string#1{%
1625 #1\kern .05em
1626 \egroup
1627 }
1628 %%% \endprog
1629
1630
1631 %%% \sect Within strings certain cseqs have a special meaning; this is
1632 %%% introduced by |\cwbb@string_setup|. The cseqs within strings are
1633 %%% mostly special \TeX{} characters that are to be typeset by cseqs with
1634 %%% the same name.
1635
1636 %%% But a problem remains: active characters. They will still expand, and
1637 %%% will mess up the string visualization. This is a particular problem
1638 %%% with |german.sty| where the double quote is active. (Of course, that's
1639 %%% a problem -- I'm German. :--) When one typesets strings, a double
1640 %%% quote shall be typeset as double quotes, and must not expand to the
1641 %%% special meaning. Remember that double quotes happen to appear quite
1642 %%% often in strings. As the string argument is already tokenized, one has
1643 %%% to redefine the binding of $(\textit{\textup{symbol}}\ \textbf{.}\
1644 %%% |#\"|)$.
1645
1646 %%% \begin{fixme}
1647 %%% Perhaps one might use a loop over all characters except the braces,
1648 %%% and set their catcode to other. That would give us enough security.
1649
1650 %%% For now, we handle only the double quote.
1651 %%% \end{fixme}
1652
1653 %%% Every once in a while we have discretionary breaks in a string,
1654 %%% denoted by |\CwebStringBreak|. This break is shown with the C
1655 %%% convention of escaped newlines.
1656
1657 %%% \beginprog
1658 \def\cwbb@string_setup{%
1659 \chardef\ =`\ % % <-- two spaces !
1660 \chardef\&=`\&
1661 \chardef\\=`\\
1662 \chardef\^=`\^
1663 \chardef\_=`\_
1664 \chardef\{=`\{
1665 \chardef\}=`\}
1666 \chardef\~=`\~
1667 \catcode`\"=\CatOther
1668 }
1669
1670 \def\CwebStringBreak{\discretionary{\hbox{\tt\char`\\}}{}{}}
1671 %%% \endprog
1672
1673
1674 %%% \sect Numbers are typeset in different ways. We use the definition of
1675 %%% Plain \cweb{}.
1676 %%% %
1677 %%% \begin{fixme}
1678 %%% Should add a specification of the possible input and an explanation
1679 %%% of the macros below. In particular, that the closing brace after
1680 %%% |\aftergroup| is used much later is probably not grokked by most
1681 %%% \TeX{} programmers.
1682 %%% \end{fixme}
1683
1684 %%% \beginprog
1685 \def\cwbb@oct{\hbox{$^\circ$\kern-.1em\it\aftergroup\?\aftergroup}}
1686 \def\cwbb@hex{\hbox{$^{\scriptscriptstyle\#}$\tt\aftergroup}}
1687
1688 \def\CwebNumber#1{% % octal, hex, or decimal constant
1689 \hbox{%
1690 $%
1691 \def\?{\kern.2em}%
1692 \def\$##1{\egroup\sb{\,\rm##1}\bgroup}% suffix to constant
1693 \def\_{\cdot 10^{\aftergroup}}% power of ten (via dirty trick)
1694 \let\~\cwbb@oct \let\^\cwbb@hex
1695 {#1}%
1696 $}%
1697 }
1698 %%% \endprog
1699
1700
1701 %%% \sect Comments are typeset in \TeX{} state. We add a hook, the user
1702 %%% shall be able to change the layout (e.g., he might want another font).
1703 %%% %
1704 %%% \begin{fixme}
1705 %%% Currently \C++ comments are typeset like C comments. This is
1706 %%% horrible in usual circumstances, i.e., when complete blocks of text
1707 %%% are prefixed with |//|. We should simply catenate all these text and
1708 %%% typeset it as one paragraph, each line prefixed by |//|. But then we
1709 %%% have to implement an |\everyline| first, and since that's not so
1710 %%% easy we postpone it\,\dots
1711 %%% \end{fixme}
1712 %%% %
1713 %%% In front of a C comment there is an optional stmt break, with 2\,quad
1714 %%% in front if the line is not broken and 1.5\,quad if the line is broken.
1715
1716 %%% \beginprog
1717 \def\CwebComment#1{%
1718 \5% % 0.5em will be discarded on line break
1719 \hskip 1.5em
1720 $/\ast\,$%
1721 {\cwbb@tex
1722 \CwebCommentHook
1723 #1%
1724 }%
1725 $\,\ast/$%
1726 }
1727 \let\CwebCommentHook\relax
1728 \let\CwebCxxComment\CwebComment
1729 %%% \endprog
1730
1731
1732
1733
1734
1735 %%% \chap \cweb{} tokens.
1736
1737 %%% We distinguish three categories of \cweb{} tokens: (1) Those which
1738 %%% output constant text, (2) those which have attributes to be displayed
1739 %%% in a special way, and (3) those which start a new structure element,
1740 %%% namely |@d| and~|@f|. Let's consider them in this order.
1741
1742
1743 %%% \sect \cweb{} tokens which expand in a constant string are the
1744 %%% identifier catenation operator~(`|@&|') and the macro placement
1745 %%% directive~(`|@h|').
1746
1747 %%% \beginprog
1748 \def\CwebIdCat{\CwebString{@\&}}
1749 \def\CwebMacrosHere{%
1750 \begingroup
1751 \def\CwebRefNumber##1{}%
1752 \CwebRefName :Preprocessor definitions\X
1753 \endgroup
1754 }
1755 %%% \endprog
1756
1757
1758 %%% \sect Verbatim program strings, i.e., strings passed verbatim by
1759 %%% \ctangle{}~(`|@=|') are typeset like normal strings, but within a box.
1760 %%% We use 2\,pt as the separating distance, this is set locally.
1761
1762 %%% \beginprog
1763 \def\CwebVerbString#1{{\fboxsep\tw@\p@ \fbox{\CwebString{#1}}}}
1764 %%% \endprog
1765
1766
1767 %%% \sect The refinement names are typeset in angles, this has a long
1768 %%% tradition. We burry the typesetting of the chunk number (which is
1769 %%% the first parameter) in a macro call; the user may change this to
1770 %%% achieve special effects.
1771 %%% %
1772 %%% \begin{fixme}
1773 %%% One could think about handling special values of the chunk numbers
1774 %%% differently. E.g., an empty argument is not typeset at all, a~0
1775 %%% triggers a marginal note about a missing definition, etc.
1776 %%% \end{fixme}
1777
1778 %%% A refinement name may be typeset both in math and horizontal mode.
1779 %%% The name itself is typeset in horizontal mode, of course; for the
1780 %%% angles we need math mode. Therefore we assert at the start of the
1781 %%% macro that we're not in math mode any more. At the end we switch back
1782 %%% to math mode if we've started in it. This conditional switch from and
1783 %%% back to math mode is done by |\cwbb@toggle_text|.
1784
1785 %%% \TeX{}nical note: If we're in math mode |\cwbb@toggle_text| must be
1786 %%% defined globally, as it will turn off math mode and the definition
1787 %%% would be un-made then. The second invocation of |\cwbb@toggle_text|
1788 %%% would be undefined then.
1789
1790 %%% A refinement may also consist of the file name the expansion of this
1791 %%% refinement shall be written to.
1792 %%% %
1793 %%% \label{sec:refname-dot}
1794 %%% %
1795 %%% This file name is tagged with |\.|, it shall be typeset like a string.
1796 %%% But the user shall be able to use the dot accent in the refinement
1797 %%% name as well. We check if the text consists solely of the tag and its
1798 %%% argument; in this case we substitute |\.| with |\CwebString|.
1799 %%% Otherwise we leave it as it is. Then a refinement name may not
1800 %%% consist of a single dot-accented expression---well, that's highly
1801 %%% unlikely. (Nevertheless I'll document it in the user's manual\,\dots)
1802
1803 %%% \begin{fixme}
1804 %%% One should be able to use |\EnsureMath| here. But the refinement
1805 %%% name must not be set in math mode and must not be set in an hbox;
1806 %%% the latter would prevent line breaks.
1807 %%% \end{fixme}
1808 %%% Enrique Mel\'endez (\texttt{[email protected]}) added the macro |\cweb@num@lnk|
1809 %%% include hyperlinks into the cross references.
1810
1811 %%% \beginprog
1812 \def\CwebRefName#1:#2\X{%
1813 \ifmmode \gdef\cwbb@toggle_text{\null$\null}%
1814 \else \let\cwbb@toggle_text\relax
1815 \fi
1816 \cwbb@toggle_text
1817 $\langle\,${\cwbb@tex \cwbb@check_dot{#2}\CwebRefNumber{#1}}$\,\rangle$%
1818 %}
1819 \cwbb@toggle_text
1820 }
1821 \def\CwebRefNumber#1{%
1822 {\reset@font \footnotesize \kern .5em\cweb@num@lnk#1, |}%
1823 }
1824 %%% \endprog
1825
1826 %%% \sect This is the implementation of |\cweb@num@lnk|. It essentially
1827 %%% processes the incoming list, takink care of whether one element of the
1828 %%% list is processed with the macro |\[|. It borrows the phylosophy from
1829 %%% |\check_dot| below in that we inhibit the behaviour of |\[| for a while,
1830 %%% so that we can test its presence. Then we proeceed differently when it is
1831 %%% present. I (\texttt{[email protected]}) have not a lot of experience in list
1832 %%% processing in \LaTeX. I have done my best, using only two macros, the
1833 %%% already named |\def\cweb@num@lnk| and a wrapper for it,
1834 %%% |\def\cweb@@num@lnk|. I need the strange termination code (\texttt{|}).
1835
1836 %%% \beginprog
1837 \newif\if@lbracket@
1838 \def\hyper@i\[#1]{\hyperlink{_hyperchunk_#1}{\[#1]}}
1839 \def\cweb@num@lnk #1, #2|{%
1840 \begingroup
1841 \def\[##1]{}%
1842 \expandafter\def\expandafter\next\expandafter{#1}%
1843 \ifx\next\empty
1844 \global\@lbracket@true
1845 \else
1846 \global\@lbracket@false
1847 \fi
1848 \endgroup
1849 \if@lbracket@%
1850 \hyper@i#1%
1851 \else
1852 \hyperlink{_hyperchunk_#1}{#1}%
1853 \fi
1854 \@lbracket@false
1855 \edef\next{#2}%
1856 \ifx\next\empty
1857 \else
1858 { } % Yep, a space by itself.
1859 \cweb@@num@lnk #2|%
1860 \fi
1861 }
1862 \def\cweb@@num@lnk #1, |{\cweb@num@lnk#1, |}
1863 %%% \endprog
1864
1865
1866 %%% \sect The next macro, |\cwbb@check_dot| is a hassle to implement. We
1867 %%% must check if it's argument consists solely of a `|\.|'~tag, together
1868 %%% with the argument to this tag. Then the `|\.|'-argument shall be
1869 %%% typeset like a string, |\.| itself must be ignored.
1870
1871 %%% The check for |\.| must not evaluate the parameter. Especially |\PB|
1872 %%% must not be evaluated within, it would lead to havoc with the
1873 %%% redefinition of all bindings, etc. (At least that's the empirical
1874 %%% result---it happened; although I don't know where the problems are.
1875 %%% Anyhow, it wasn't in the specs of the rebinding process.) All other
1876 %%% cseqs which shouldn't be used in moving arguments may cause problems
1877 %%% here, too. Note that |\protect| is no solution here, the user often is
1878 %%% not aware of the presence of \cweave{}-generated tags. As an example,
1879 %%% consider the refinement \verb"@< local variables of |foo| @>|" which
1880 %%% will lead to a call with the argument `|local variables of \PB{\\{foo}}|'.
1881 %%% |\\| must not be evaluated here.
1882
1883 %%% I use an approach where I hope that it will work---but to be honest,
1884 %%% I'm not sure. I want to define a macro |\next| which shall have an
1885 %%% empty expansion iff |#1| was a `|\.|'~tag with its argument. Empty
1886 %%% refinement names are not allowed so we can assume that |#1| consists
1887 %%% of at least one token. I evaluate the first token of |#1| before the
1888 %%% |\def| is done. With an appropriate binding a |\.| will disappear,
1889 %%% perhaps leaving an empty token list. I also take care that |\PB| is
1890 %%% not evaluated then, by temporary rebinding it to |\relax|. Thereby I
1891 %%% have taken care for all cseqs \cweave{} might have introduced at the
1892 %%% very front of |#1|. Other cseqs are user-tags. If they cause
1893 %%% problems, the user might circumstance them by adding |\protect|.
1894
1895 %%% \beginprog
1896 \def\cwbb@check_dot#1{%
1897 \begingroup
1898 \let\.\@gobble
1899 \let\PB\relax
1900 \expandafter\def \expandafter\next \expandafter{#1}%
1901 \ifx \next\empty
1902 \gdef\next##1{\CwebString}%
1903 \else
1904 \global\let\next\relax
1905 \fi
1906 \endgroup
1907 \next #1%
1908 }
1909 %%% \endprog
1910
1911
1912 %%% \sect \cweb{} macro definitions (done by~|@d|) and format directives are
1913 %%% basically program text. When they are started we are already in
1914 %%% program state, i.e., |\B| has appeared in front of it. But since we have
1915 %%% an introductionary identifier (either |#define| or |format|) to set at
1916 %%% the very front we increase the indentation by three units.
1917
1918 %%% The output of format directives may be suppressed. Then we have to
1919 %%% gather both identifiers that will appear after |\F|. Both of them
1920 %%% consist of one group-token (a cseq and the identifier name), after
1921 %%% each identifier one other token separates them. I.e., we have to
1922 %%% gobble six group-tokens. As the very last token is |\par| if a format
1923 %%% directive follows directly on another one, the definition must be
1924 %%% long.
1925
1926 %%% \TeX{}nical note: |\cwbb@format| must expand to |\CwebFormat|, not to
1927 %%% its expansion. Otherwise a redefinition of |\CwebFormat| in a package
1928 %%% would not be used.
1929
1930 %%% \beginprog
1931 \def\CwebDefine{\cwbb@macro{\#define}}
1932 \def\CwebFormat{\cwbb@macro{format}}
1933 \if@cweb@suppress@format@
1934 \long\def\cwbb@format#1#2#3#4#5#6{}
1935 \else
1936 \def\cwbb@format{\CwebFormat}
1937 \fi
1938
1939 \def\cwbb@macro#1{%
1940 \global\advance\cwbb@indent \tw@\CwebIndentUnit
1941 \cwbb@incr_indent
1942 \CwebRes{#1 }% % <-- blank!
1943 }
1944 %%% \endprog
1945
1946
1947
1948
1949 %%% \chap Refinement cross references and changes.
1950
1951 %%% At the end of chunks with refinements, \cweave{} may output cross
1952 %%% reference information: In which chunks additional definitions for
1953 %%% this refinement are found, where this refinement is used, and where it
1954 %%% is cited. This cross reference information is always introduced by a
1955 %%% tag followed by a non-empty list of chunk numbers. Different tags
1956 %%% are used for lists with only one element and for lists with more than
1957 %%% one element, this way the introductionary text may be adapted.
1958
1959 %%% Within a list of $n$~chunk numbers the first $n-1$~numbers are
1960 %%% separated by commas with one following blank. The last two numbers
1961 %%% are separated by |\ET| if~$n=2$, and by |\ETs| if~$n>2$. If a chunk
1962 %%% is changed by the changefile, a changeflag~(`|\*|') is appended to
1963 %%% its number. The list is eventually terminated by a full stop.
1964
1965
1966 %%% \sect We separate the cross reference information by a smallskip from
1967 %%% the refinement or from a previous cross reference information. The
1968 %%% information itself is typeset in a smaller font, as it is auxilliary,
1969 %%% inserted stuff. The number list has a hanging indentation of
1970 %%% |\CwebNumberListHangindent|. But beware: This isn't a dimension
1971 %%% register, it's a macro. This way one can use ems as dimensions.
1972
1973 %%% The actual size change is represented by a macro. We will redefine it
1974 %%% when we need an other size, e.g., in the lists at the end of the
1975 %%% document.
1976
1977 %%% We must assert that we're in CR state while we set a cross reference.
1978
1979 %%% The first parameter of a cross reference information unit is the
1980 %%% introductionary text, the second is the number list. The parameters
1981 %%% must be evaluated in a group---local parameter changes therein must
1982 %%% not influence the environment.
1983
1984 %%% Enrique Mel\'endez (\texttt{[email protected]}) included some code to handle
1985 %%% putting in hyperlinks. In the case of only one item, a single
1986 %%% |\hyperlink| has been included. The processing of several
1987 %%% cross-references is somewhat more difficult. This amounts to inhibiting
1988 %%% the effect of |\ET| and |\ETs| so that the list can be processed
1989 %%% properly, and calling the macro |\cweb@cr@lnk| to process it. The
1990 %%% appropriate end-list conjunction will be added there.
1991
1992 %%% \beginprog
1993 \def\CwebNumberListHangindent{2em}
1994 \let\CwebCRSize\footnotesize
1995 \def\CwebCrossRef#1#2.{%
1996 \par\smallskip
1997 \cwbb@CR
1998 \begingroup
1999 \reset@font \CwebCRSize
2000 \noindent \hangindent\CwebNumberListHangindent\relax
2001 #1~\hyperlink{_hypersect_#2}{#2}.\par
2002 %#1~\hyperlink{_hyperchunk_#2}{#2}.\par
2003 \endgroup
2004 }
2005 \def\CwebCrossRefs#1#2.{%
2006 \par\smallskip
2007 \cwbb@CR
2008 \begingroup
2009 \reset@font \CwebCRSize
2010 \noindent \hangindent\CwebNumberListHangindent\relax
2011 \let\save@et\ET%
2012 \let\save@ets\ETs
2013 \def\ET{, }%
2014 \let\ETs\ET%
2015 \edef\@cr@lst{#2}%
2016 \let\LastList@Conjunction\save@et
2017 #1~\expandafter\cweb@cr@lnk\@cr@lst, ]\par
2018 \endgroup
2019 }
2020 %%% \endprog
2021
2022 %%% \sect The cross references are added here for the case of a list of them.
2023 %%% We test whether we are at the last point of the list, and then add the
2024 %%% adequate conjunction, which is updated in the macro |\cweb@@cr@lnk|, which
2025 %%% takes care of the case of there being more than two elements. The
2026 %%% processing of the list goes along the same lines as |\cweb@num@lnk|.
2027
2028 %%% \beginprog
2029 \def\cweb@cr@lnk #1, #2, #3]{%
2030 \hyperlink{_hyperchunk_#1}{#1}%
2031 \edef\next{#3}%
2032 \ifx\next\empty
2033 \LastList@Conjunction\hyperlink{_hyperchunk_#2}{#2}%
2034 \else
2035 , \hyperlink{_hyperchunk_#2}{#2}%
2036 \cweb@@cr@lnk#3]%
2037 \fi
2038 }
2039 \def\cweb@@cr@lnk #1, #2]{%
2040 \let\LastList@Conjunction\save@ets
2041 \edef\next{#2}%
2042 \ifx\next\empty
2043 \LastList@Conjunction\hyperlink{_hyperchunk_#1}{#1}%
2044 \else
2045 , \cweb@cr@lnk#1, #2]%
2046 \fi
2047 }
2048 %%% \endprog
2049
2050
2051 %%% \sect Well, let's define all introducing tags, which in fact start the
2052 %%% cross reference information unit. The number list is gathered by
2053 %%% |\CwebCrossRef|.
2054
2055 %%% \beginprog
2056 \def\CwebCRAlso{\CwebCrossRef{See also chunk}}
2057 \def\CwebCRsAlso{\CwebCrossRefs{See also chunks}}
2058
2059 \def\CwebCRCite{\CwebCrossRef{This code is cited in chunk}}
2060 \def\CwebCRsCite{\CwebCrossRefs{This code is cited in chunks}}
2061
2062 \def\CwebCRUse{\CwebCrossRef{This code is used in chunk}}
2063 \def\CwebCRsUse{\CwebCrossRefs{This code is used in chunks}}
2064
2065 \def\CwebCREt{ and~}
2066 \def\CwebCRsEt{, and~}
2067 %%% \endprog
2068
2069
2070
2071
2072 %%% \chap Bells and whistles.
2073
2074 %%% \begin{fixme}
2075 %%% Just copied from Plain \cweb{}. It doesn't work
2076 %%% anyhow---|\char"|\<xy> usually doesn't typeset the correct
2077 %%% character. That's because this character is most probably an active
2078 %%% character; at least that's typical for the way \TeX{} systems are
2079 %%% used in Europe. I have to think about the implementation.
2080 %%% \end{fixme}
2081
2082 %%% \beginprog
2083 \def\ATL{\par\noindent\bgroup\catcode`\_=12 \postATL} % print @l in limbo
2084 \def\postATL#1 #2 {\bf letter \\{\uppercase{\char"#1}}
2085 tangles as \tentex "#2"\egroup\par}
2086 \def\noATL#1 #2 {}
2087 \def\noatl{\let\ATL=\noATL} % suppress output from @l
2088 %%% \endprog
2089
2090
2091
2092 %%% \chap The end.
2093
2094 %%% Well, after all we're finished with this module
2095
2096 %%% \beginprog
2097 \endinput
2098 %%% \endprog
2099
2100
2101 %%%
2102 %%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2103
2104 %%% \vskip \PltxPreSectSkip
2105
2106 %%% \rcsLogIntro{After the actual revision log of this module, we give an
2107 %%% extract of log messages of the \cls{cweb} class. This module was
2108 %%% extracted from revision~2.8 of that class, we present to you the
2109 %%% log entries that concern the code of the new module.}
2110
2111 %%% \begin{rcslog}
2112 %%% $StyleLog: cwebbase.doc,v $
2113 %%% \Revision 1.4 1995/11/07 17:55:19 schrod
2114 %%% \LaTeX{} \cweb{} should work at least with the last two \LaTeX{}
2115 %%% versions; make it work with the previous-to-last one, version
2116 %%% \mbox{$\langle$1994/12/01$\rangle$}. For that, one has to install the
2117 %%% \mbox{$\langle$1995/06/01$\rangle$} (non-outer) definition of
2118 %%% |\newif|, and |\hb@xt@| must not be used.\\
2119 %%% Problem reported by Laurent Desnogues
2120 %%% \path|<[email protected]>| and somebody else (XXX
2121 %%% -- add name).
2122
2123 %%% \Revision 1.3 1995/11/07 14:13:12 schrod
2124 %%% Reset section numbers when higher-level section begins.\\
2125 %%% Error reported by Bronne Louis \path|<[email protected]>|.
2126
2127 %%% \Revision 1.2 1995/11/06 10:58:47 schrod
2128 %%% Support active double quotes in strings. That happens when
2129 %%% |german.sty| is used. Problems with other active characters may still
2130 %%% appear.
2131
2132 %%% \Revision 1.1 1995/09/12 23:02:22 schrod
2133 %%% Moved all code that does the actual typesetting of \cweave{} tags and
2134 %%% is therefore also needed for a |cweb| environment. It's now an own
2135 %%% module named \pkg{cwebbase}.
2136
2137 %%% Chunk markers and chunk marginal numbers don't hang below the
2138 %%% baseline any more.
2139
2140
2141 %%% \item[] \noindent\hrulefill\break
2142 %%% \textbf{Extract of the revision log for |cweb.doc|:}
2143
2144 %%% \vskip 2ex
2145
2146 %%% \Revision 2.5 1995/08/29 02:07:26 schrod
2147 %%% Discard dependencies on 10\,pt fonts.
2148
2149 %%% Support suppression of format directives.
2150
2151 %%% \Revision 2.4 1995/08/27 19:31:43 schrod
2152 %%% Make configuration of change flag easier.
2153
2154 %%% Put section title of changed chunks list in marks, and tell the user
2155 %%% that it got typeset.
2156
2157 %%% \Revision 2.3 1995/08/27 17:24:46 schrod
2158 %%% Make usage of baseclass with chapters work.
2159
2160 %%% \Revision 2.2 1995/08/27 13:26:22 schrod
2161 %%% Add possibility to suppress change hints.
2162
2163 %%% \Revision 2.1 1995/08/25 19:11:18 schrod
2164 %%% Hierarchic structures are supported now, in addition to the flat
2165 %%% structure of the beta-test version. One can choose with an option. For
2166 %%% that step, the terminology was cleaned up, too: Chunks are not named
2167 %%% sections any more. (That change involved reimplementation of almost
2168 %%% all the structure and toc stuff.)
2169
2170 %%% The chunk number supplied by \cweave{} is used now, not some computed
2171 %%% number. Change flags are printed, too.
2172
2173 %%% One can suppress output of unchanged sections.
2174
2175 %%% \Revision 1.12 1993/08/10 14:15:43 schrod
2176 %%% New page on main section only if group level $<$ |\cwebSecNoEject|.
2177 %%% Default for the latter is 3.
2178
2179 %%% \Revision 1.11 1993/08/10 11:21:07 schrod
2180 %%% Reference to section number does not render a period after the
2181 %%% number any more.
2182
2183 %%% \Revision 1.10 1993/08/09 20:08:20 schrod
2184 %%% |\cweb@cweave_bindings| is now a no-op if \cweave{} bindings are in
2185 %%% effect already.\\
2186 %%% (Problem reported by Michael M\"uller \path|<[email protected]>|.)
2187
2188 %%% \Revision 1.9 1993/08/09 18:05:28 schrod
2189 %%% Left shift operator wasn't defined correctly.\\
2190 %%% (Problem reported by Michael M\"uller \path|<[email protected]>|.)
2191
2192 %%% \Revision 1.6 1993/06/15 08:49:23 schrod
2193 %%% |\cweb@check_dot| must not evaluate its argument in an |\edef|, this
2194 %%% causes problems if a |\PB| is within. Now I try hard not to evaluate any
2195 %%% tokens outside of my control.
2196
2197 %%% Can use |\@defpar| for an empty line in |\cweb@has_entries|, don't
2198 %%% need an own macro.
2199
2200 %%% \Revision 1.4 1993/06/14 15:54:18 schrod
2201 %%% Add FSA diagram about processing states. CR state is also switched
2202 %%% to from \TeX{} state (that happens with |\ch| at the document end).
2203
2204 %%% \Revision 1.3 1993/05/13 17:51:21 schrod
2205 %%% Refinements may also be filenames (`|@(|'). Then the complete name
2206 %%% consists of a |\.| macro call, which is handled now.\\
2207 %%% (Problem reported by Michael M\"uller \path|<[email protected]>|.)
2208
2209 %%% Made the detection of `|@.|' index entries more robust.
2210
2211 %%% \Revision 1.2 1993/05/12 18:28:59 schrod
2212 %%% Adapted to recent changes of \cweave{} (of April 93):
2213
2214 %%% Main sections have a group level, represented in the table of
2215 %%% contents. This changed the complete implementation of section tags.
2216
2217 %%% New C token cseqs: |\Z| and |\MRL|, implemented as |\CwebLe| and
2218 %%% |\CwebCombinedOp|.
2219
2220 %%% \Revision 1.1 1993/04/09 15:00:37 schrod
2221 %%% Initial revision
2222
2223 %%% \end{rcslog}
2224
2225
2226
2227 %%% \end{document}
2228
2229
2230 %%%
2231 %%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2232 %%% Local Variables:
2233 %%% mode: LaTeX
2234 %%% TeX-brace-indent-level: 4
2235 %%% indent-tabs-mode: t
2236 %%% TeX-auto-untabify: nil
2237 %%% TeX-auto-regexp-list: LaTeX-auto-regexp-list
2238 %%% compile-command: "make cwebbase.tex"
2239 %%% End: