| 1 |
%% $Id: cwebzw.sty,v 1.2 1993/08/10 14:14:33 schrod Exp $ |
| 2 |
%%---------------------------------------------------------------------- |
| 3 |
%% Changed by Joachim Schrod <[email protected]> |
| 4 |
%% Original received by mail: |
| 5 |
%% Date: Thu, 05 Aug 93 12:34:21 MDT |
| 6 |
%% From: Zdenek Wagner <[email protected]> |
| 7 |
|
| 8 |
%% This is file ``cwebzw.sty'' written by Z. Wagner as an extension and |
| 9 |
%% correction of ``cweb.sty'' Revision 1.8 |
| 10 |
|
| 11 |
%% This file is self-documenting. If you process this file through LaTeX, |
| 12 |
%% you will get the documentation. You can use MakeIndex to create an |
| 13 |
%% index of macros used. In your cweb documents you can either use it as |
| 14 |
%% is or you can remove all comment lines by your editor or the docstrip |
| 15 |
%% utility (or a program of your own). |
| 16 |
|
| 17 |
%% See chapter ``Introduction'' for other remarks. |
| 18 |
|
| 19 |
\def\cwebzwrevision{1.8} % Do not remove this line! |
| 20 |
|
| 21 |
% You can remove the next two lines |
| 22 |
\ifcat a\noexpand @\let\next\relax\else\def\next{% |
| 23 |
\documentstyle[doc]{article}\MakePercentIgnore}\fi\next |
| 24 |
|
| 25 |
% \EnableCrossrefs |
| 26 |
% \CodelineIndex |
| 27 |
% \catcode`\_=12 |
| 28 |
% \DoNotIndex{\cweb,\orig,\p} ^^A doc.sty cannot handle underscore |
| 29 |
% \DoNotIndex{\#,\$,\%,\&,\@,\\,\{,\},\^,\_,\~,\ } |
| 30 |
% \DoNotIndex{\@ne,\tw@,\bgroup,\egroup,\endinput,\end,\kern,\hbox,\vbox,\vtop} |
| 31 |
% \DoNotIndex{\aftergroup,\arabic,\begin,\protect,\rm,\reset@font,\setbox} |
| 32 |
% \DoNotIndex{\show,\typeout,\errhelp,\unskip,\unvbox,\wd,\input,\hskip} |
| 33 |
% \DoNotIndex{\ifdim,\ifmmode,\ifnum,\long,\footnotesize,\newbox,\newpage} |
| 34 |
% \DoNotIndex{\@ifnextchar,\@ifundefined,\@namedef} |
| 35 |
% \DoNotIndex{\advance,\begingroup,\catcode,\closein,\closeout} |
| 36 |
% \DoNotIndex{\day,\def,\edef,\else,\empty,\endgroup,\errmessage} |
| 37 |
% \DoNotIndex{\expandafter,\fi,\futurelet,\gdef,\global,\if,\ifeof} |
| 38 |
% \DoNotIndex{\ifx,\immediate,\let,\loop,\m@ne,\message,\month,\newcount} |
| 39 |
% \DoNotIndex{\newif,\newlinechar,\newread,\newtoks,\newwrite} |
| 40 |
% \DoNotIndex{\noexpand,\openin,\openout,\par,\read,\relax,\repeat} |
| 41 |
% \DoNotIndex{\space,\the,\undefined,\write,\xdef,\year,\z@} |
| 42 |
% \advance\textwidth by 40pt |
| 43 |
% \def\pcws{{\tt cweb.sty}} |
| 44 |
% \def\cws{\protect\pcws} |
| 45 |
% \newbox\cwebincr |
| 46 |
% \setbox\cwebincr=\hbox{^^A |
| 47 |
% \kern .5pt |
| 48 |
% \raise .1em\hbox{$\scriptstyle{+}\kern -.1em{+}$}^^A |
| 49 |
% \kern .5pt} |
| 50 |
% \def\Cpp{C\copy\cwebincr} |
| 51 |
% \begin{document} |
| 52 |
% \MakeShortVerb\| |
| 53 |
% \title{Extension and correction of \cws\ revision~\cwebzwrevision} |
| 54 |
% \author{Zden\v{e}k Wagner\\ |
| 55 |
% $\[email protected]$\rangle$ or |
| 56 |
% $\[email protected]$\rangle$}\date{} |
| 57 |
% \maketitle\vspace{3ex} |
| 58 |
|
| 59 |
% \tableofcontents\thispagestyle{empty}\newpage |
| 60 |
|
| 61 |
% \section{Introduction} |
| 62 |
% The purpose of this file is to add new features to \cws\ and |
| 63 |
% correct some bugs. When doing this we intended not to make a faintest |
| 64 |
% change into \cws. Therefore some definitions may look strangely |
| 65 |
% cumbersome. However, this file should be treated as a test of new |
| 66 |
% features and bug fixes which should then be placed in the official |
| 67 |
% distribution of \cws\ and in the ideal state this file will one day |
| 68 |
% vanish at all. |
| 69 |
|
| 70 |
% {\bf Note by Joachim Schrod}:\quad I have incorporated most error |
| 71 |
% repairs and some of the enhancements into \cws{} (Revision~1.12). To |
| 72 |
% avoid problems, I deleted all the respective macros from this |
| 73 |
% option. The rest that you see here will not be incorporated (at |
| 74 |
% least not as-is) and is therefore provided as a contributed style |
| 75 |
% option for those who like it. |
| 76 |
|
| 77 |
|
| 78 |
% \section{Preliminaries} |
| 79 |
% First we make sure that this file is not input twice. |
| 80 |
% \begin{macrocode} |
| 81 |
\@ifundefined{\cweb@egroup}{}{\endinput} |
| 82 |
% \end{macrocode} |
| 83 |
|
| 84 |
% Throughout this file we will use tags defined in \cws. Therefore we |
| 85 |
% begin the file with identifying itself and displaying the revision of |
| 86 |
% \cws\ for which it is written. Afterwards we change catcode of |
| 87 |
% underscore in order to have the same conditions as \cws. |
| 88 |
% \begin{macrocode} |
| 89 |
\typeout{Extension of cweb style, revision \cwebzwrevision} |
| 90 |
\typeout{(if you have an older revision of cweb.sty, please upgrade)} |
| 91 |
\catcode`\_=\CatLetter |
| 92 |
% \end{macrocode} |
| 93 |
|
| 94 |
% \section{Extensions} |
| 95 |
% \begin{macro}{\C++} |
| 96 |
% \begin{macro}{\Cpp} |
| 97 |
% \begin{macro}{\CPLUSPLUS/} |
| 98 |
% The documentation of \cws\ says that |\C++| may now be used for \Cpp\ |
| 99 |
% logo. However, |\C++| is not defined in \cws. The conservative users |
| 100 |
% of {\tt ccwebmac.tex} designed by Hans--Hermann Bode might be |
| 101 |
% accustomed to |\Cpp| while users of {\tt cwebmac.tex} from {\tt CWEB |
| 102 |
% 3.0} might like |\CPLUSPLUS/|. Therefore we supply all three tags and |
| 103 |
% moreover make them robust so that they can safely be used in moving |
| 104 |
% arguments. |
| 105 |
% \begin{macrocode} |
| 106 |
\def\p_cpp{C\CwebIncr} |
| 107 |
\def\C++{\protect\p_cpp} |
| 108 |
\def\Cpp{\protect\p_cpp} |
| 109 |
\def\CPLUSPLUS/{\protect\p_cpp} |
| 110 |
% \end{macrocode} |
| 111 |
% \end{macro} |
| 112 |
% \end{macro} |
| 113 |
% \end{macro} |
| 114 |
|
| 115 |
% \section{Improvements} |
| 116 |
% \begin{macro}{\CwebScope} |
| 117 |
% If your program contains description of member functions as |
| 118 |
% |TListBox::|\-|handleEvent|, the documentation part may easily contain |
| 119 |
% lots of overfull boxes. Therefore we try to allow the line break after |
| 120 |
% the scope operator. We make the change only if it is not typeset in |
| 121 |
% the math mode. The following solution is not perfect. The expression |
| 122 |
% ``|::close|'' may be incorrectly split after the scope resolution |
| 123 |
% operator. To make a robust macro we should probably fiddle with |
| 124 |
% |\lastskip| and |\lastpenalty|. |
| 125 |
% \begin{macrocode} |
| 126 |
\def\CwebScope{\ifmmode \kern.1em::\kern.1em\else |
| 127 |
\kern.1em::\hskip.1em\fi} |
| 128 |
% \end{macrocode} |
| 129 |
% \end{macro} |
| 130 |
|
| 131 |
% \subsection{Index appearance} |
| 132 |
% When typesetting two or more columns it is more pleasant if the |
| 133 |
% columns are balanced. This may easily be achieved with Frank |
| 134 |
% Mittelbach's {\tt multicol.sty}. We try whether the style is |
| 135 |
% available. |
| 136 |
% \begin{macrocode} |
| 137 |
\newif\ifhave@multicol |
| 138 |
\openin\@ne multicol.sty |
| 139 |
\ifeof\@ne \else \have@multicoltrue \fi |
| 140 |
\closein\@ne \relax |
| 141 |
% \end{macrocode} |
| 142 |
|
| 143 |
% If we found {\tt multicol.sty}, we use it. It might me nice to delay |
| 144 |
% this until we know that the index is really requested. |
| 145 |
% \begin{macrocode} |
| 146 |
\ifhave@multicol \input{multicol.sty} \fi |
| 147 |
% \end{macrocode} |
| 148 |
|
| 149 |
% \begin{macro}{\CwebIdIndex} |
| 150 |
% \begin{macro}{\twocolumn} |
| 151 |
% \begin{macro}{\onecolumn} |
| 152 |
% We delay the redefinitions of the twocolumn format into the definition |
| 153 |
% of |\CwebIdIndex|. If we made the changes globally, we could |
| 154 |
% eventually break something in the user's code. |
| 155 |
|
| 156 |
% I dare say that I do not like the page break in between the index and |
| 157 |
% the list of refinements so I do not put it into the redefinition of |
| 158 |
% |\onecolumn|. Notice also that the new version of |\onecolumn| |
| 159 |
% restores everything for the rare case it is needed somewhere later. |
| 160 |
% \begin{macrocode} |
| 161 |
\let\orig_CwebIdIndex=\CwebIdIndex |
| 162 |
\let\orig_twocolumn=\twocolumn |
| 163 |
\let\orig_onecolumn=\onecolumn |
| 164 |
|
| 165 |
\ifhave@multicol |
| 166 |
\def\CwebIdIndex{% |
| 167 |
\def\twocolumn{\newpage |
| 168 |
\@ifnextchar[{\zw@twocol}{\begin{multicols}{2}}} |
| 169 |
\long\def\zw@twocol[##1]{\setbox\cweb_tempbox=\vbox{##1}% |
| 170 |
\begin{multicols}{2}[\unvbox\cweb_tempbox]} |
| 171 |
\def\onecolumn{% |
| 172 |
\let\onecolumn=\orig_onecolumn |
| 173 |
\let\twocolumn=\orig_twocolumn} |
| 174 |
\orig_CwebIdIndex\cweb@restore_end\end{multicols}} |
| 175 |
\fi |
| 176 |
% \end{macrocode} |
| 177 |
% \end{macro} |
| 178 |
% \end{macro} |
| 179 |
% \end{macro} |
| 180 |
|
| 181 |
% \begin{macro}{\cweb@restore_end} |
| 182 |
% The index is processed after the user supplied |\end{document}| where |
| 183 |
% the |\end| tag has unfortunately been redefined. We would always get a |
| 184 |
% \LaTeX\ error informing us about unmatched |\begin| and |\end|. |
| 185 |
% Therefore we prepare a macro which will be used inside a group to |
| 186 |
% restore temporarily the original meaning of |\end|. |
| 187 |
% \begin{macrocode} |
| 188 |
\let\orig_end=\end |
| 189 |
\def\cweb@restore_end{\let\end=\orig_end} |
| 190 |
% \end{macrocode} |
| 191 |
% \end{macro} |
| 192 |
|
| 193 |
% \section{Crazy inventions} |
| 194 |
% As we can see from the documentation of \cws, it can handle two |
| 195 |
% versions of \LaTeX. Older versions of \LaTeX\ are unlikely to be used |
| 196 |
% and \LaTeX3 will handle |\end|'s in a different way so the following |
| 197 |
% invention does not seem useful. I wrote it mainly as an exercise so |
| 198 |
% that I could proudly say with the White Knight from Through the |
| 199 |
% Looking Glass, ``It's my own invention.'' |
| 200 |
|
| 201 |
% \begin{macro}{\cweb@end_tokens} |
| 202 |
% When skipping around the |\end{document}| we have to catch the tokens |
| 203 |
% which are placed after |\endgroup|. For this purpose we establish a |
| 204 |
% new token register. |
| 205 |
% \begin{macrocode} |
| 206 |
\newtoks\cweb@end_tokens |
| 207 |
% \end{macrocode} |
| 208 |
% \end{macro} |
| 209 |
|
| 210 |
% \begin{macro}{\cweb@report_error} |
| 211 |
% Before we start the job of catching tokens we prepare some macros. The |
| 212 |
% first of them will display our error message. Though we hope that the |
| 213 |
% catching algorithm will work with all \LaTeX's currently available, it |
| 214 |
% may according to Murphy's Laws happen that someone's obsolete (or |
| 215 |
% brand new) \LaTeX\ will break it. We do not want to bother the user |
| 216 |
% with strange error messages. We therefore supply ours. The text is |
| 217 |
% taken exactly from \cws. The macro will be issued from inside a group |
| 218 |
% therefore we take no care about restoring the original definitions. |
| 219 |
% \begin{macrocode} |
| 220 |
\def\cweb@report_error{\let\orig_errmsg=\errmessage |
| 221 |
\def\errmessage##1{% |
| 222 |
\errhelp={^^J% |
| 223 |
This style depends on an internal implementation detail of LaTeX.^^J% |
| 224 |
Sad to note, this detail has changed; you cannot use the cweb style.^^J% |
| 225 |
Please type "i\show\end" now. TeX will spit out a few lines of^^J% |
| 226 |
definitions and ask again for input. Type "x" then, this will finish TeX.^^J |
| 227 |
Then send the log file to the style's author, Joachim Schrod^^J% |
| 228 |
(Email: [email protected]). He will adapt cweb.sty^^J% |
| 229 |
to the new LaTeX version.^^J} |
| 230 |
\orig_errmsg{Sorry, you cannot use the cweb style with this LaTeX version}} |
| 231 |
} |
| 232 |
% \end{macrocode} |
| 233 |
% \end{macro} |
| 234 |
|
| 235 |
% \begin{macro}{\cweb@catch_tokens} |
| 236 |
% We also prepare the macro which will catch the tokens. This is an |
| 237 |
% incomplete assignment to the token register. Its function will be |
| 238 |
% explained later. |
| 239 |
% \begin{macrocode} |
| 240 |
\def\cweb@catch_tokens{\cweb@end_tokens=\bgroup} |
| 241 |
% \end{macrocode} |
| 242 |
% \end{macro} |
| 243 |
|
| 244 |
% \begin{macro}{\cweb_3_env} |
| 245 |
% \begin{macro}{\endcweb_3_env} |
| 246 |
% For catching the tokens we will invoke a very special environment with |
| 247 |
% the name |cweb_3_env|. \LaTeX\ would complain if the environment were |
| 248 |
% undefined. Therefore we place to |\cweb_3_env| everything which is |
| 249 |
% needed at the beginning of the catching job and similarly |
| 250 |
% |\endcweb_3_env| will contain the trap for the tokens. Notice that we |
| 251 |
% have to use |\@namedef| to define tags with such strange names. |
| 252 |
% \begin{macrocode} |
| 253 |
\@namedef{cweb_3_env}{\cweb@report_error} |
| 254 |
\@namedef{endcweb_3_env}{\aftergroup\cweb@catch_tokens} |
| 255 |
% \end{macrocode} |
| 256 |
% \end{macro} |
| 257 |
% \end{macro} |
| 258 |
|
| 259 |
% \begin{macro}{\cweb@skip_end} |
| 260 |
% Now we can catch the tokens and define |\cweb@skip_end| accordingly. |
| 261 |
% First we write it and then explain how it works. |
| 262 |
% \begin{macrocode} |
| 263 |
\begin{cweb_3_env} |
| 264 |
{\egroup\end{cweb_3_env}} |
| 265 |
\expandafter\def\expandafter\cweb@skip_end\the\cweb@end_tokens{\cweb@check_fi} |
| 266 |
% \end{macrocode} |
| 267 |
% When we start the environment, \LaTeX\ will invoke our error reporting |
| 268 |
% macro. It is invoked inside a group as we have promised. The ending |
| 269 |
% command will tell \TeX\ that |\cweb@catch_tokens| should be carried |
| 270 |
% out after the end of group. When the group is closed (after some |
| 271 |
% checks), the tokens which stem from the expansion of |\end| are not |
| 272 |
% executed but stored in our token register. So we have to complete the |
| 273 |
% assignment. You might have temptation to just append |\egroup| after |
| 274 |
% the statement ending the environment. But beware! This will store |
| 275 |
% |\egroup| as the next token in |\cweb@end_tokens|. It will also eat up |
| 276 |
% the rest of the file. Fortunately we are redefining \cws\ so that the |
| 277 |
% official tags will do the job. We could start catching tokens with |
| 278 |
% |\bgroup| which is equivalent to \{ but we must put \} and nothing |
| 279 |
% else at the end of the assignment. We solve it by inserting an empty |
| 280 |
% group |{\egroup|. This is syntactically correct. In almost all |
| 281 |
% contexts \} and |\egroup| are interchangeable. So when \TeX\ scans the |
| 282 |
% text, it sees matched braces and when executing the macros it finds |
| 283 |
% balanced groups. The definition of |\cweb@skip_end| is now |
| 284 |
% straightforward. Isn't it a pretty nonsense code? |
| 285 |
% \end{macro} |
| 286 |
|
| 287 |
% \section{Bug corrections} |
| 288 |
% \begin{macro}{\egroup_} |
| 289 |
% A funny (and instructive) bug invaded into the definition of |
| 290 |
% |\CwebNumber|. This tag is defined in \cws\ where underscore is |
| 291 |
% recatcoded to letter. Therefore, what would work in a usual \TeX\ |
| 292 |
% context, does not work here. We correct it by defining |\egroup_| |
| 293 |
% which will do the correct things. However, there is one more thing |
| 294 |
% which should be mentioned. When using NFSS, |\rm| has no effect in the |
| 295 |
% math mode. The easiest safe way for switching to roman alphabet from |
| 296 |
% inside math is to use |\hbox|. Placing |\,| as done in \cws\ seems |
| 297 |
% unpleasant to my eyes therefore I remove it. Please notice that the |
| 298 |
% catcode of underscore is restored to the original value within the |
| 299 |
% following definition. |
| 300 |
|
| 301 |
% {\bf Note from Joachim Schrod:}\quad This will not work any more |
| 302 |
% since the bug with the underscore has been repaired (one shouldn't |
| 303 |
% simply copy plain macros to \LaTeX{} code\,\dots). Nevertheless the |
| 304 |
% problem with NFSS remains. But I'm not (yet?)\ convinced that the |
| 305 |
% work-around presented here is the adequate solution. So the code is |
| 306 |
% here for reference, but it will not be used. |
| 307 |
|
| 308 |
% \begin{macrocode} |
| 309 |
\def\egroup_{\egroup\begingroup |
| 310 |
\catcode`\_=\CatUsCode |
| 311 |
\let\,=\relax |
| 312 |
\def\rm{\reset@font\footnotesize}% |
| 313 |
\cweb@egroup} |
| 314 |
|
| 315 |
\catcode`\_=\CatUsCode |
| 316 |
\def\cweb@egroup#1{_{\hbox{#1}}\endgroup} |
| 317 |
% \end{macrocode} |
| 318 |
% \end{macro} |
| 319 |
|
| 320 |
% \PrintIndex |
| 321 |
% \end{document} |
| 322 |
\endinput |
| 323 |
|