| 1 |
% $StyleId: cwebparts.doc,v 1.1 1995/09/16 17:01:59 schrod Exp $ |
| 2 |
%---------------------------------------------------------------------- |
| 3 |
% Written by Joachim Schrod <[email protected]>. |
| 4 |
% Copyright conditions see below. |
| 5 |
|
| 6 |
% |
| 7 |
% LaTeX package cwebparts |
| 8 |
% include parts of CWEB programs in LaTeX documents |
| 9 |
% |
| 10 |
% [LaTeX in MAKEPROG] |
| 11 |
% (history at end) |
| 12 |
|
| 13 |
%% FIXME: The user manual is not in cwebparts-user.tex. Most probably |
| 14 |
%% I'll make one user manual for the whole bundle; due to the usage of |
| 15 |
%% cwebbase class and package have lots in common. |
| 16 |
%% |
| 17 |
%% % If you have received this style file without the user manual (in the |
| 18 |
%% % file cwebparts-user.tex or the respective DVI file), it's incomplete and |
| 19 |
%% % near to useless. If it was given to you as something that you shall |
| 20 |
%% % use as an author -- complain bitterly to your provider. You need the |
| 21 |
%% % documentation and you have a right on it! (Below you can find info |
| 22 |
%% % where to get the reference version.) |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
\documentclass{progltx} |
| 28 |
|
| 29 |
\usepackage{cweb-doc} % document-specific markup |
| 30 |
\usepackage{fullpage} |
| 31 |
|
| 32 |
|
| 33 |
\RCS $StyleRevision: 1.1 $ |
| 34 |
\RCS $StyleDate: 1995/09/16 17:01:59 $ |
| 35 |
|
| 36 |
|
| 37 |
\begin{document} |
| 38 |
|
| 39 |
|
| 40 |
\title{The \texttt{cwebparts} Package\\ |
| 41 |
{\large (Implementation)}% |
| 42 |
} |
| 43 |
\author{% % LaTeX does not discard unnecessary glue... |
| 44 |
Joachim Schrod% |
| 45 |
\thanks{% |
| 46 |
\protect\raggedright |
| 47 |
TU~Darmstadt, Computer Science Department, WG Systems Programming, |
| 48 |
Alexanderstr.~10, D-64283~Darmstadt, Germany. |
| 49 |
Email: \texttt{[email protected]}.% |
| 50 |
}% |
| 51 |
} |
| 52 |
\date{% |
| 53 |
Revision \RCSStyleRevision\\ |
| 54 |
(as of \RCSStyleDate)% |
| 55 |
} |
| 56 |
|
| 57 |
\maketitle |
| 58 |
|
| 59 |
|
| 60 |
% doesn't work with progltx yet |
| 61 |
%\tableofcontents |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
\chap What's this style for?. |
| 66 |
|
| 67 |
This style supports inclusion of \cweb{} program parts in \LaTeX{} |
| 68 |
documents. For that it provides the environment |cweb| where \cweave{} |
| 69 |
output may be stuffed in. |
| 70 |
|
| 71 |
A more versatile explanation is available in the user manual of the |
| 72 |
\cweb{} bundle; this package is part of that bundle. |
| 73 |
% |
| 74 |
\begin{fixme} |
| 75 |
Read: ``should be available'' -- there is no bundle user manual |
| 76 |
(yet). |cweb-user.tex| will be enhanced after first testing of this |
| 77 |
code. |
| 78 |
\end{fixme} |
| 79 |
|
| 80 |
|
| 81 |
\sect The internal interface is also not described in this source, |
| 82 |
refer to the configuration documentation for this bundle. |
| 83 |
% |
| 84 |
\begin{fixme} |
| 85 |
Even worse: I don't even have written the internal specs for the |
| 86 |
\cls{cweb} class, not to speak of this package. |
| 87 |
\end{fixme} |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
\chap Implementation. |
| 93 |
|
| 94 |
Most of the implementation is made available by the module |
| 95 |
\pkg{cwebbase}. We have to supply macros it demands from a user, and |
| 96 |
have to deliver the |cweb| environment. |
| 97 |
|
| 98 |
|
| 99 |
\sect This module reserves the namespace |cweb|. (This implies that it |
| 100 |
cannot be used with the \cls{cweb} class. But you don't want to do |
| 101 |
that anyhow. :--) |
| 102 |
|
| 103 |
\beginprog |
| 104 |
\ifx \cweb@loaded\undefined |
| 105 |
\def\cweb@loaded{$StyleRevision: 1.1 $} |
| 106 |
\else |
| 107 |
\PackageWarningNoLine{cwebparts}% |
| 108 |
{Some other package already uses namespace `cweb'} |
| 109 |
\fi |
| 110 |
\endprog |
| 111 |
|
| 112 |
|
| 113 |
\sect Let's identify this package. |
| 114 |
|
| 115 |
\noindent The code below is explained in the implementation |
| 116 |
documentation of the |rcs| package. |
| 117 |
|
| 118 |
\beginprog |
| 119 |
\begingroup |
| 120 |
\def\RCSPackage#1#2 $#3: #4 #5\endRCS $#6: #7 #8\endRCS{% |
| 121 |
\def\date{#4}\def\id{v#7}% |
| 122 |
\ProvidesPackage{#1}[\date\space\id\space #2]% |
| 123 |
} |
| 124 |
|
| 125 |
\RCSPackage{cwebparts}{include CWEB program parts in LaTeX documents} |
| 126 |
$StyleDate: 1995/09/16 17:01:59 $: 9999/00/00 \endRCS |
| 127 |
$StyleRevision: 1.1 $: 0.0 \endRCS |
| 128 |
\endgroup |
| 129 |
\endprog |
| 130 |
|
| 131 |
|
| 132 |
\sect This module is supported. Send bug reports, comments and |
| 133 |
repairs. |
| 134 |
|
| 135 |
The reference version may be retrieved via anonymous ftp from |
| 136 |
|ftp.th-darmstadt.de| [130.83.47.112], directory |pub/tex/latex|. It's |
| 137 |
placed there as a gzipped tar file. (The information on the IP~number |
| 138 |
is dated September~13,~1995. |
| 139 |
It might have changed, although this is very unlikely. Use your |
| 140 |
friendly nameserver.) |
| 141 |
|
| 142 |
|
| 143 |
\sect This is freely distributable software; you can redistribute it |
| 144 |
and/or modify it under the terms of the GNU General Public License as |
| 145 |
published by the Free Software Foundation; either version~2 of the |
| 146 |
License, or (at your option) any later version. |
| 147 |
|
| 148 |
This software is distributed in the hope that it will be useful, but |
| 149 |
\textbf{without any warranty}; without even the implied warranty of |
| 150 |
\textbf{merchantability} or \textbf{fitness for a particular purpose}. |
| 151 |
See the GNU General Public License for more details. |
| 152 |
|
| 153 |
You should have received a copy of the GNU General Public License in |
| 154 |
the file |License| along with this package; if not, write to the Free |
| 155 |
Software Foundation, Inc., 675~Mass Ave, Cambridge, MA~02139,~USA. |
| 156 |
|
| 157 |
|
| 158 |
\sect Before we start we declare some shorthands for category codes. |
| 159 |
By declaring the underscore~`(|_|)' as letter we can use it in our |
| 160 |
macros. (I agree with \textsc{D.~Knuth} that |
| 161 |
|\identifier_several_words_long| is more readable than |
| 162 |
|\IdentifierSeveralWordsLong| and in every case better than |\p@@@s|.) |
| 163 |
|
| 164 |
As this is a \LaTeX{} style file the at sign is a letter anyhow; so |
| 165 |
we can use the ``private'' \LaTeX{} macros; and with the underscore we |
| 166 |
can make our own macros more readable. But as we have to restore this |
| 167 |
category code at the end of this macro file we store its former value |
| 168 |
in the control sequence |\CatUsCode|. This method is better than to |
| 169 |
use a group because not all macros have to be defined global this way. |
| 170 |
|
| 171 |
Since somebody might use more styles from me, this cseqs might be |
| 172 |
defined already. |
| 173 |
|
| 174 |
\beginprog |
| 175 |
\ifx \CatEscape\undefined |
| 176 |
\chardef\CatEscape=0 |
| 177 |
\chardef\CatOpen=1 |
| 178 |
\chardef\CatClose=2 |
| 179 |
\chardef\CatIgnore=9 |
| 180 |
\chardef\CatLetter=11 |
| 181 |
\chardef\CatOther=12 |
| 182 |
\chardef\CatActive=13 % is defined in Plain already |
| 183 |
|
| 184 |
\chardef\CatUsCode=\catcode`\_ |
| 185 |
\fi |
| 186 |
|
| 187 |
\catcode`\_=\CatLetter % top level macro file |
| 188 |
\endprog |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
\chap Typesetting \cweave{} output. |
| 194 |
|
| 195 |
The module \pkg{cwebbase} handles that. It demands some cseqs to be |
| 196 |
defined before it may be imported. |
| 197 |
% |
| 198 |
\begin{fixme} |
| 199 |
These cseqs should actually be implemented as package options. Have |
| 200 |
to extract the \pkg{keyvalx} code from the \cls{cweb} class first. |
| 201 |
Now I fix the usage I need for our Literate Programming book. |
| 202 |
\end{fixme} |
| 203 |
|
| 204 |
\begin{fixme} |
| 205 |
The options should not only be available as package options, but |
| 206 |
also on a per environment base. We might to typeset one part with |
| 207 |
flat and another one with hierarchic structure. Or we might to |
| 208 |
suppress format directives only in some parts, while other parts |
| 209 |
feature them. But this needs a change in \pkg{cwebbase}, there code |
| 210 |
is \emph{defined} depending on the cseqs below. It must be evaluated |
| 211 |
differently to support the stuff below. OTOH, this will cost |
| 212 |
performance -- is it worth it? |
| 213 |
\end{fixme} |
| 214 |
|
| 215 |
\beginprog |
| 216 |
\def\cweb@structure{0 } % hierarchic structure |
| 217 |
\let\if@cweb@suppress@changehints@=\iffalse % no suppression whatsoever |
| 218 |
\let\if@cweb@suppress@unchanged@=\iffalse |
| 219 |
\let\if@cweb@suppress@format@=\iffalse |
| 220 |
|
| 221 |
\input{cwebbase} |
| 222 |
\endprog |
| 223 |
|
| 224 |
|
| 225 |
\sect Now we can typeset pieces of \cweave{} output -- in principle. |
| 226 |
If these pieces have sections in them, they'll write entries to the |
| 227 |
|TOC| file. These entries will either mess up the structure of the |
| 228 |
document's table of contents or lead to \TeX{} error messages. That's |
| 229 |
because either toc entries for section types |part|, |chapter|, or |
| 230 |
|section| are written (causing the conflict); or toc entries for |
| 231 |
section types |chunk| and `|section|$i$' are written (being |
| 232 |
undefined). |
| 233 |
|
| 234 |
The best way seems to stop the included source to add anything to the |
| 235 |
table of contents or to do any mark processing. For that, we provide a |
| 236 |
macro |\CwebNoLists| that will locally redefine the \LaTeX{} cseqs |
| 237 |
that cause such actions to happen. That macro will be used at the |
| 238 |
start of the environment. |
| 239 |
|
| 240 |
\beginprog |
| 241 |
\def\CwebNoLists{% |
| 242 |
\let\addtocontents\@gobbletwo |
| 243 |
\let\mark\@gobble |
| 244 |
%% \let\markboth\@gobbletwo |
| 245 |
%% \let\markright\@gobble |
| 246 |
} |
| 247 |
\endprog |
| 248 |
|
| 249 |
|
| 250 |
\sect Furthermore, section divisions should not start a new page. |
| 251 |
% |
| 252 |
\begin{fixme} |
| 253 |
Currently, sections in the included parts are typeset exactly the |
| 254 |
same way as they're typeset in the main document. That should be |
| 255 |
different -- but how do I change it in a general way? |
| 256 |
\end{fixme} |
| 257 |
|
| 258 |
\beginprog |
| 259 |
\let\CwebEjectSection\@gobble |
| 260 |
\endprog |
| 261 |
|
| 262 |
|
| 263 |
\sect OK, what needs to be done for the environment? We need to save |
| 264 |
and restore counters that are changed globally by section commands. |
| 265 |
|
| 266 |
\beginprog |
| 267 |
\ifx \chapter\undefined |
| 268 |
\let\cweb@save_c@chapter\@gobble |
| 269 |
\let\c@chapter\@gobble |
| 270 |
\else |
| 271 |
\newcount\cweb@save_c@chapter |
| 272 |
\fi |
| 273 |
\newcount\cweb@save_c@part |
| 274 |
\newcount\cweb@save_c@section |
| 275 |
|
| 276 |
\def\cweb@save_for_env{% |
| 277 |
%% save values changed globally by cwebbase macros |
| 278 |
\cweb@save_c@chapter\c@chapter |
| 279 |
\cweb@save_c@part\c@part |
| 280 |
\cweb@save_c@section\c@section |
| 281 |
\let\cweb@save_thechapter\thechapter |
| 282 |
\let\cweb@save_thesection\thesection |
| 283 |
%% set up typesetting of CWEB source |
| 284 |
\@nobreaktrue % don't add space from first chunk |
| 285 |
} |
| 286 |
\def\cweb@restore_env{% |
| 287 |
\global\c@chapter\cweb@save_c@chapter |
| 288 |
\global\c@part\cweb@save_c@part |
| 289 |
\global\c@section\cweb@save_c@section |
| 290 |
\global\let\thechapter\cweb@save_thechapter |
| 291 |
\global\let\thesection\cweb@save_thesection |
| 292 |
} |
| 293 |
\endprog |
| 294 |
|
| 295 |
|
| 296 |
\sect For the moment, we use list spacing around a |cweb| environment. |
| 297 |
\LaTeX{} supplies the |trivlist| environment for such purposes. |
| 298 |
|
| 299 |
But the environment content itself must not be typeset in a list |
| 300 |
context. Two problems exist: There must be at least one |\item|, it |
| 301 |
will actually add the vertical space and must therefore not be |
| 302 |
discarded. And list environments redefine |\par|, but the |
| 303 |
\pkg{cwebbase} macros need a more `normal' definition. |
| 304 |
|
| 305 |
An item label is stored by |\item| in the |\everypar| register. The |
| 306 |
label is only typeset if |@inlabel| is true. The flag |@newlist| tells |
| 307 |
most other \LaTeX{} macros, that there was no item yet; typically |
| 308 |
they'll add an empty paragraph if necessary. As the content will |
| 309 |
start with a \LaTeX{} section division, or even with document markup, |
| 310 |
we don't want that empty paragraph and should skip the empty item |
| 311 |
label. (Often enough, due to the initialisation of |\everypar| in |
| 312 |
|\@startsection|, it will be thrown away anyhow). So we establish its |
| 313 |
postconditions, the next macro won't notice that the item hasn't been |
| 314 |
set actually. |
| 315 |
|
| 316 |
\begin{fixme} |
| 317 |
Experimentally, we reduce the skip in front of a chunk to 1\,pc, |
| 318 |
otherwise the distance between two chunks is far too wide compared |
| 319 |
to other vertical distances in the text around the included stuff. |
| 320 |
\end{fixme} |
| 321 |
|
| 322 |
\beginprog |
| 323 |
\def\CwebBeginEnvLayout{% |
| 324 |
%% use spacing of list, but switch off list handling afterwards |
| 325 |
\trivlist |
| 326 |
\@inlabelfalse % don't go in horizontal mode |
| 327 |
\item\relax |
| 328 |
\global\@newlistfalse |
| 329 |
\global\@inlabelfalse\the\everypar |
| 330 |
\@setpar{\@@par}% |
| 331 |
\CwebChunkPreSkip 1pc plus 6pt minus 3pt |
| 332 |
} |
| 333 |
\let\CwebEndEnvLayout=\endtrivlist |
| 334 |
\endprog |
| 335 |
|
| 336 |
|
| 337 |
\sect The environment gets trivial now. We supply a hook for a whole |
| 338 |
document and also environment-specific ones (as an optional |
| 339 |
environment argument). |
| 340 |
|
| 341 |
\beginprog |
| 342 |
\newenvironment{cweb}[1][]% |
| 343 |
{% |
| 344 |
\CwebBeginEnvLayout |
| 345 |
\cweb@save_for_env |
| 346 |
\CwebNoLists |
| 347 |
\csname CwebEnvHook\endcsname |
| 348 |
#1 |
| 349 |
}{% |
| 350 |
\CwebEndEnvLayout |
| 351 |
} |
| 352 |
\endprog |
| 353 |
|
| 354 |
|
| 355 |
\sect An a convenience tag to include a complete \cweave{} file. Since |
| 356 |
we want to test the typesetting of our included \cweb{} program alone, |
| 357 |
we allow but ignore most kinds of document markup. Many of them have |
| 358 |
two arguments, one is optional. |
| 359 |
|
| 360 |
In the preambel, only |\documentclass| and |\usepackage| may appear. |
| 361 |
Titlepage material is handled, table of contents is discarded. The |
| 362 |
document environment does nothing, i.e., unlike the \cls{cweb} class, |
| 363 |
material behind |\end{document}| is not ignored. |
| 364 |
|
| 365 |
An |\end| tag is inserted by \cweave{} and must be redefined, we don't |
| 366 |
end an environment there. We'll open a group and will use that tag to |
| 367 |
close it again, as we know that we'll have reached the end of our |
| 368 |
\cweb{} file. Of course, |\end| must not be redefined during |
| 369 |
processing the actual program source -- environments are valid there. |
| 370 |
The redefinition is best be triggered by material inserted from |
| 371 |
\cweave{} at the very end, e.g., from |\inx|. But |\inx| may not be |
| 372 |
there (when \cweave{} is called with the `|-x|' option), we'll use |
| 373 |
|\enddocument| to add a |\inx| tag for safety reason. If the user |
| 374 |
didn't add an |\end{document}| to his file and used `|-x|', we're |
| 375 |
going to loose. |
| 376 |
|
| 377 |
\TeX{}nical note: |\document| must not have the same binding as |
| 378 |
|\relax|, as this would be interpreted as a non-existing environment |
| 379 |
by \LaTeX{}. (That's due to the |\csname| lossage.) |
| 380 |
|
| 381 |
\TeX{}nical note: Evaluating |\inx| in |\enddocument| will not have |
| 382 |
any effect, we're inside a group. That evaluation must be postponed |
| 383 |
after the group has been closed. |
| 384 |
|
| 385 |
\beginprog |
| 386 |
\newcommand\cweb@doc_markup_gobble[2][]{} |
| 387 |
\newcommand*\cwebInput[1]{% |
| 388 |
\begin{cweb} |
| 389 |
[% |
| 390 |
\begingroup |
| 391 |
\let\documentclass\cweb@doc_markup_gobble |
| 392 |
\let\usepackage\cweb@doc_markup_gobble |
| 393 |
\let\title\@gobble |
| 394 |
\let\author\@gobble |
| 395 |
\let\date\@gobble |
| 396 |
\let\maketitle\relax |
| 397 |
\let\tableofcontents\relax |
| 398 |
\let\document\empty |
| 399 |
\def\inx{\let\end\endgroup}% |
| 400 |
\let\fin\relax |
| 401 |
\let\con\relax |
| 402 |
\def\enddocument{\aftergroup\inx}% |
| 403 |
]% |
| 404 |
\input{#1}% |
| 405 |
\end{cweb}% |
| 406 |
} |
| 407 |
\endprog |
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
\chap The end. |
| 413 |
|
| 414 |
Well, after all we're finished with this style. We must not forget to |
| 415 |
restore the underscore catcode. |
| 416 |
|
| 417 |
\beginprog |
| 418 |
\catcode`\_=\CatUsCode |
| 419 |
|
| 420 |
\endinput |
| 421 |
\endprog |
| 422 |
|
| 423 |
|
| 424 |
%\sect I would like to thank those who helped me to improve this style. |
| 425 |
% In particular, XXX provided XXXsubstantial parts of the code. |
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 430 |
|
| 431 |
\begin{rcslog} |
| 432 |
$StyleLog: cwebparts.doc,v $ |
| 433 |
\Revision 1.1 1995/09/16 17:01:59 schrod |
| 434 |
Add support for inclusion of \cweb{} files in \LaTeX{} documents. |
| 435 |
|
| 436 |
\end{rcslog} |
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
\end{document} |
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 445 |
Local Variables: |
| 446 |
mode: LaTeX |
| 447 |
TeX-brace-indent-level: 4 |
| 448 |
indent-tabs-mode: t |
| 449 |
TeX-auto-untabify: nil |
| 450 |
TeX-auto-regexp-list: LaTeX-auto-regexp-list |
| 451 |
compile-command: "make cwebparts.sty" |
| 452 |
End: |