1%****************************************************************** 2% $Id: htcweb.sty,v 1.2 1999/04/09 19:25:34 JCL Exp $ 3%****************************************************************** 4% 5% Copyright 1998-1999 by Jens Lippmann (lippmann@rbg.informatik.tu-darmstadt.de) 6% 7% Permission to use, copy, modify, and distribute this software for any 8% purpose and without fee is hereby granted, provided that the above 9% copyright notice appears in all copies. This software is provided "as is" 10% and without any express or implied warranties. 11% 12%****************************************************************** 13% htcweb.tex, htcweb.sty 14% Macros for alternative CWEB listings to use with LaTeX2HTML 15% extends original file: hywebmac.tex or cwebmac.tex, depending 16% on \HTCwebmode value which is preset at the beginning of the document. 17% See also htcweb.perl, the perl translation of this file's and 18% hywebmac.tex's resp. cwebmac.tex's macros. 19% See also ProcessCwebTex, the Perl script to convert weaved documents 20% into parsable shape for LaTeX2HTML. 21%****************************************************************** 22 23%% Prevent multi-input 24\ifx\HTCwebstyloaded\relax\endinput\else\let\HTCwebstyloaded\relax\fi 25 26\def\HTCwebmodecweb{cweb} 27\def\HTCwebmodehyweb{hyweb} 28\expandafter\ifx\csname HTCwebmode\endcsname\relax 29 \expandafter\ifx\csname HyTeXSetUp\endcsname\relax 30 \def\HTCwebmode{cweb}\else 31 \def\HTCwebmode{hyweb}\fi\fi 32\ifx\HTCwebmode\HTCwebmodecweb 33% We are able to work with Schrod's cweb-sty only. 34% CWEB's cwebmac does exactly nothing with LaTeX, but let's input it. 35% Schrod defines CWEB's bindings elsewhere (in cweb.sty resp. 36% cweb.cls), and doesn't set CWEB's special chars. We do it here. 37\input cwebmac 38\chardef\AM=`\& % ampersand character in a string 39\chardef\BS=`\\ % backslash in a string 40\chardef\LB=`\{ % left brace in a string 41\chardef\RB=`\} % right brace in a string 42\def\SP{{\tt\char`\ }} % (visible) space in a string 43\chardef\TL=`\~ % tilde in a string 44\chardef\UL=`\_ % underline character in a string 45\chardef\CF=`\^ % circumflex character in a string 46\def\oct{\hbox{$^\circ$\kern-.1em\it\aftergroup\?\aftergroup}}% CWEB style 47\def\hex{\hbox{$^{\scriptscriptstyle\#}$\tt\aftergroup}} % CWEB style 48\fi 49\ifx\HTCwebmode\HTCwebmodehyweb 50% Get the original LaTeX macros, then introduce simpler macro names. 51% The \sbox stuff is a workaround to get LaTeX 2e run with hywebmac.tex 52\let\HTCwebsavesbox\sbox 53\input hywebmac 54\let\HTCwebsaveoldsbox\sbox 55\let\sbox\HTCwebsavesbox 56\fi 57\makeatletter 58 59 60% Name: @HTCwebnoderef @HTCwebpretty 61% Interface: internal 62% Synopsis: 63% @HTCwebnoderef <label> <no> 64% @HTCwebpretty <name> 65% Description: 66% Depending on Cweb or Hyweb mode, leave <no> or \noderef <label> <no>. 67% In Hyweb mode, use @HTCwebpretty to nice up the refinement <name> a bit. 68% 69\ifx\HTCwebmode\HTCwebmodecweb 70 \def\@HTCwebnoderef#1#2{#2}% 71 \def\@HTCwebpretty#1{#1}% 72\fi 73\ifx\HTCwebmode\HTCwebmodehyweb 74 \def\@HTCwebnoderef#1#2{\noderef{#1}{#2}}% 75 \def\@HTCwebpretty#1{\underline{\HTCwebidbo{#1}}}% 76\fi 77 78 79\let\@HTCweblabelson=0 80 81\def\@HTCwebverb{\def\do##1{\catcode`##1=12}% 82\do\#\do\_\do\{\do\}\do\$\do\^\do\&\do\%\do\\\relax} 83 84\def\@HTCwebspch{\catcode`_=13\relax} 85 86\def\@HTCwebnextfile#1,#2\\{\edef\@HTCwebfilename{#1}\def\@HTCwebfilelist{#2}} 87\newif\if@HTCwebfileok 88\newread\@HTCwebfilein 89\def\@HTCwebreadfile{\openin\@HTCwebfilein=\@HTCwebfilename.lbl %<- space 90 \ifeof\@HTCwebfilein\typeout{No labels from \@HTCwebfilename.lbl, ignored}\else 91 \typeout{Reading label file \@HTCwebfilename.lbl}% 92 {\@HTCwebfileoktrue\loop 93 {\@HTCwebverb\global\read\@HTCwebfilein to \@HTCwebfilelinea} 94 \ifeof\@HTCwebfilein\@HTCwebfileokfalse\else 95 \expandafter\@HTCwebauxa\@HTCwebfilelinea::: :\\% 96 {\@HTCwebspch\global\read\@HTCwebfilein to \@HTCwebfilelineb} 97 \ifeof\@HTCwebfilein\@HTCwebfileokfalse 98 \errmessage{Corrupted label file \@HTCwebfilename.lbl}\else 99 \expandafter\@HTCwebauxb\@HTCwebfilelineb::: :\\% 100 \fi\fi\if@HTCwebfileok\repeat}% 101 \closein\@HTCwebfilein\fi} 102 103% A fake \HTCweblabels is defined in htcweb.tex which expands to this macro 104\def\HTCweblabelsEnv#1#2{\if1\@HTCweblabelson\else 105 \global\let\@HTCweblabelson=1\@HTCwebmakelabels\fi 106 \def\@HTCwebfilelist{#1,}{\loop 107 \expandafter\@HTCwebnextfile\@HTCwebfilelist\\% 108 \def\nope{}\ifx\@HTCwebfilename\nope\else 109 \ifx\@HTCwebfilename\jobname\else\@HTCwebreadfile\fi\fi 110 \ifx\@HTCwebfilelist\nope\else\repeat}} 111 112\def\endHTCweblabelsEnv{} 113 114\def\@HTCwebauxa#1:#2:#3:#4 :#5\\{\gdef\HTCwebaux{#4}% must not use xdef 115\expandafter\gdef\csname HTCweblabelfile\HTCwebaux\endcsname{#1}% 116\expandafter\gdef\csname HTCweblabelname\HTCwebaux\endcsname{#2}% 117\expandafter\gdef\csname HTCweblabelno\HTCwebaux\endcsname{#3}} 118 119{\catcode`+=8 \catcode`_=13 120\gdef\@HTCwebauxb#1:#2:#3:#4 :#5\\{% 121% Do not use \xdef, cause \_ somehow goes haywire if flattened. 122% Let active _ be local in any case 123\expandafter\gdef\csname HTCweblabelftext\HTCwebaux\endcsname{{% 124\catcode`_=13 \def_{\ifmmode+\else\_\fi}\relax #1.w}}% 125\expandafter\gdef\csname HTCweblabelntext\HTCwebaux\endcsname{{% 126\catcode`_=13 \def_{\ifmmode+\else\_\fi}\relax #2}}% 127% We must care here for _'s in math at least. 128\expandafter\gdef\csname HTCweblabeltext\HTCwebaux\endcsname{{% 129\catcode`_=13 \def_{\ifmmode+\else\_\fi}\relax #4}}% 130\global\expandafter\let\csname HTCweblabelon\HTCwebaux\endcsname=1}} 131 132\def\@HTCwebmakelabels{\if@filesw \newwrite\@HTCweblabelfile 133 \immediate\openout\@HTCweblabelfile=\jobname.lbl 134 \typeout{Writing label file \jobname.lbl} 135% Provide a way to cite a complete cweb file 136 \expandafter\@HTCwebauxa\jobname:section_1:1:\jobname.w :\\% 137 {\@HTCwebspch\relax% this doesn't flip catcodes in \jobname XXX. 138 \expandafter\@HTCwebauxb\jobname:section_1:1:\jobname.w :\\} 139 \write\@HTCweblabelfile{\jobname:section_1:1:\jobname.w}% 140 \write\@HTCweblabelfile{\jobname:section_1:1:\jobname.w}% 141\fi} 142 143\def\@HTCwebwrlabel#1#2#3{\relax 144 \write\@HTCweblabelfile{\jobname:#1:#2:#3}\relax 145 \write\@HTCweblabelfile{\jobname:#1:#2:#3}\relax} 146 147 148% Description of extern ref feature \HTCwebX..\HTCwebX, which replaces 149% the original \X0..\X of CWEB. 150% We have to be careful with math mode, since the outer math chars of 151% \X0..\X have been removed during conversion to HTCweb macros. 152% 153% a) if HTCweblabelson: 154% HTCwebX goes verbatim and makes ~ the escape char. 155% It defines \\ (~\ in input line) locally, such that 156% \HTCwebX~\HTCwebNodeRefExt{bubble name}~\HTCwebX -> 157% \\HTCwebNodeRefExt{#1 }\\HTCwebX 158% and #1 holds the bubble name in verbatim chars. 159% This macro first terminates the verbatim group. 160% Then, with #1 as bubble name 161% a1) if HTCweblabelon<bubble name> is 1: 162% The textual bubble name, the external file name and section no 163% are displayed using the original \X..\X macro. 164% a2) else 165% The *verbatim* bubble name is displayed together with \X0..\X. 166% This is a slight deficiency against CWEB, but we have no workaround 167% here cause we must scan bubble name at least verbatim. 168% Note: We have to go completely into verbatim mode. This affects the 169% open/close group brace, too. Thus, we can't use {,} as macro arg 170% delimiter in \\. Left hand of #1, we have the (verbatim) 171% delimiter 'HTCwebNodeRefExt{ ', right hand we have '}\\HTCwebX'. 172% We will take care of this at the place we define HTCwebX. 173% b) else 174% b1) if doc part 175% HTCwebX does nothing. 176% The ~ has its normal meaning. It will add extra space before 177% and after the bubble brackets, this is neglected. 178% HTCwebNodeRefExt gives #1, the textual bubble name, to \X0..\X. 179% We have no math mode. \X will handle this. 180% b2) if code part 181% Behaviour like b1), but the two ~'s act like math signs, 182% this means \X0..\X is called within math mode. 183% 184{\catcode`]=2 \catcode`\}=12 \catcode`[=1 \catcode`\{=12 185\gdef\HTCwebX[\if1\@HTCweblabelson\begingroup 186 \def\\HTCwebNodeRefExt{##1}\\HTCwebX[\endgroup 187 \expandafter\if1\csname HTCweblabelon##1\endcsname 188 \PB[$\X\csname HTCweblabelftext##1\endcsname\ \csname HTCweblabelno##1\endcsname:% 189 \@HTCwebpretty[\csname HTCweblabeltext##1\endcsname]\X$]\typeout[+ @<##1@>]% 190 \else\PB[$\X0:\@HTCwebpretty[\ ##1]\X$]\typeout[- @<##1@>]\fi]% 191 \catcode`\~=0\@HTCwebverb\fi]] 192 193 194% Name: HTCwebNodeRef 195% Interface: machine 196% Synopsis: 197% HTCwebNodeRef <labellist> <name> 198% labellist ::= {<label>}{<no>}(, {<label>}{<no>})* 199% Equal to Cweb: 200% \X<labelnolist>:<name>\X 201% labelnolist ::= <no>(, <no>)* 202% Equal to Hyweb: 203% \X<nodelabellist>:<name>\X 204% nodelabellist ::= \noderef{<label>}{<no>}(, \noderef{<label>}{<no>})* 205% Description: 206% Typeset <name> as refinement reference using \X. 207% <no> is the number of the first refinement, <label> its label. 208% If a refinement consists one multiple parts (+=), <labellist> is a comma 209% separated list of <label><no> pairs. 210% The data \jobname, <label>, <no>, and <name> is written once to the 211% label file. 212% Leaves the \X...\X sequence to render the output. 213% Preconditions: 214% <labellist> must contains at least one <label><no> pair. 215% 216\def\@HTCwebgetnext#1, #2\\{\def\@HTCweblist{#2}\def\@HTCwebnext{#1}} 217\def\HTCwebNodeRef#1#2{% 218 %%% 219 %%% Get first <label><no> pair. 220 %%% 221 \@HTCwebgetnext #1, \\%<-- space 222 % define help macro to split <label><no> into <label> and <no> 223 \def\@HTCwebtmpa##1##2{\def\@HTCwebtmpb{{##1}}\def\@HTCwebtmpc{{##2}}% 224 \def\@HTCwebtmpd{@HTCwebsection##2}}% 225 \expandafter\@HTCwebtmpa\@HTCwebnext 226 %%% 227 %%% If external labels are wanted, write data to label file. 228 %%% 229 \if1\@HTCweblabelson 230 % did label for refinement numbered <no> been written? 231 \expandafter\if1\csname\@HTCwebtmpd\endcsname 232 \else 233 % no, write <label>, <no>, <name> and remember this 234 \expandafter\@HTCwebwrlabel\@HTCwebnext{#2}% 235 \global\expandafter\let\csname\@HTCwebtmpd\endcsname=1% 236 \fi 237 \fi 238 %%% 239 %%% Parse the comma separated <labellist> and compute a list 240 %%% \@HTCwebnoderef{<label>}{<no>}(, \@HTCwebnoderef{<label>}{<no>})* 241 %%% which is named \@HTCwebtmpoutlist. It will appear after the first \X. 242 %%% \@HTCwebnoderef cares for its arguments in respect of the mode (see above). 243 %%% 244 % initialize out list. must be global because the loop defines it in 245 % some deeper group nesting level. 246 % the \expandafters assure that the contents of \@HTCwebnext is 247 % taken, not \@HTCwebnext itself 248 \expandafter\gdef 249 \expandafter\@HTCwebtmpoutlist 250 \expandafter{% 251 \expandafter\@HTCwebnoderef\@HTCwebnext}% 252 % parse rest of list and append it to out list 253 \def\@HTCwebtmpe##1##2{\expandafter\gdef\expandafter\@HTCwebtmpoutlist 254 \expandafter{\@HTCwebtmpoutlist, \@HTCwebnoderef{##1}{##2}}}% 255 {\loop\def\nope{}% 256 \ifx\@HTCweblist\nope\else 257 \expandafter\@HTCwebgetnext\@HTCweblist\\% 258 \expandafter\@HTCwebtmpe\@HTCwebnext 259 \repeat}% 260 % pass \X's, out list and refinement name to TeX 261 % let out list expand first 262 \expandafter\PB 263 \expandafter{% 264 \expandafter\X\@HTCwebtmpoutlist:\@HTCwebpretty{#2}\X 265 }% 266} 267 268 269% \HTCwebNodeRefExt is defined in htcweb.tex 270% We introduced a fake \HTCwebNodeRefExt in such a way that its argument 271% appears in an environment. 272% In l2h, this enables us to slurp the arg before it gets expanded, to 273% wield the original (almost raw) expression of the bubble name. 274\def\HTCwebNodeRefExtEnv#1{\PB{\X0:\@HTCwebpretty{#1}\X}} 275\def\endHTCwebNodeRefExtEnv{} 276 277 278% The .idx (list of identifiers) and .scn (list of refinements) are processed 279% after \end{document}. 280% To let l2h go beyond this, we hide the \end{document} away. 281% Also we have to reset the fake \HTCwebNodeRefExt to its original, because 282% LaTeX environments are not allowed anymore after the document ended. 283\def\HTCwebdocumentend{\gdef\HTCwebNodeRefExt{\HTCwebNodeRefExtEnv}\end{document}} 284 285\def\HTCwebpar{\egroup\par} %JL 14.2. see \B 286 287\def\HTCwebidit{\\}% italic type for identifiers 288\def\HTCwebidma{\|}% one-letter identifiers 289\def\HTCwebidbo{\&}% boldface type for reserved words 290\def\HTCwebidtt{\.}% typewriter type for strings 291\def\HTCwebdiscr{\)}% discretionary 292 293\def\HTCweboneright{\1}% indent one more notch 294\def\HTCweboneleft{\2}% indent one less notch 295\def\HTCweboptbreak{\3}% optional break within a statement 296\def\HTCwebthisleft{\4}% backspace one notch 297\def\HTCwebbigoptbreak{\5}% optional break 298\def\HTCwebbreak{\6}% forced break 299\def\HTCwebbigbreak{\7}% forced break and a little extra space 300\def\HTCwebclearleft{\8}% no indentation 301\def\HTCwebempty{\9}% do nothing (eats its arg) 302 303\def\HTCwebmathque{\?}% relation sign 304 305%\let\@HTCweboldB=\B 306\def\HTCwebB{\B\bgroup\catcode`~=3\relax}% uses new math mode 307 308\def\HTCwebsmllspc{\,} 309 310\makeatother 311\endinput 312 313%****************************************************************** 314# 315# $Log: htcweb.sty,v $ 316# Revision 1.2 1999/04/09 19:25:34 JCL 317# changed my e-Mail address 318# 319# Revision 1.1 1998/02/24 02:29:51 latex2html 320# for 98.1 321# 322# Revision 1.1 1998/02/24 02:15:58 latex2html 323# ready for 98.1 324# 325# Revision 1.10 1997/11/10 09:24:33 zohar 326# th-darmstadt -> tu... 327# 328# Revision 1.9 1997/09/13 01:09:31 lippmann 329# minor change 330# 331# Revision 1.8 1997/06/01 11:56:09 lippmann 332# o changed name from htmlmac to htcweb 333# o htcweb.perl takes different actions depending on $HTCwebmode 334# (\U, \Us, \Q, \Qs string translation currently) 335# 336# Revision 1.7 1997/06/01 08:18:24 lippmann 337# Introduced the name space HTCweb, which will be used both in TeX and Perl 338# packages and for mapping to some CWEB internals hidden from LaTeX2HTML. 339# 340# HTmode, HTpretty, HTnoderef -> HTCweb... 341# HTweb -> HTCweb 342# \ciao -> \HTCwebdocumentend 343# 1 -> HTCweboneright 344# 2 -> HTCweboneleft 345# 3 -> HTCweboptbreak 346# 4 -> HTCwebthisleft 347# 5 -> HTCwebbigoptbreak 348# 6 -> HTCwebbreak 349# 7 -> HTCwebbigbreak 350# 8 -> HTCwebclearleft 351# 9 -> HTCwebempty 352# idit -> HTCwebidit 353# idma -> HTCwebidma 354# idbo -> HTCwebidbo 355# idtt -> HTCwebidtt 356# discr -> HTCwebdiscr 357# mathque -> HTCwebmathque 358# smllspc -> HTCwebsmllspc 359# 360# Revision 1.6 1997/05/31 01:56:38 lippmann 361# o new face for \HTwebNodeRef to parse a list of <label><no> pairs occurring 362# in multi-part refinement citations in the list of refinements 363# o more documentation 364# o small enhancements 365# 366# Revision 1.5 1997/02/11 01:52:56 lippmann 367# \HTlabels... macros may now occur multiply 368# 369# Revision 1.4 1997/02/04 20:08:22 lippmann 370# changed local newread, newif to be global 371# 372# Revision 1.3 1996/12/11 11:00:43 lippmann 373# introduced macros to handle Schrod's LaTeX CWEB 374# 375# Revision 1.2 1996/11/04 14:39:33 lippmann 376# provides now linkage to complete web file: 377# 378# use |@<foo.w@>| to link to file foo.w (exactly: to section 1 of it) 379# 380# Revision 1.1.1.1 1996/07/08 15:46:25 liefke 381# initial version for Darmstadt 382# 383# Revision 1.1.1.1 1996/07/08 15:35:41 liefke 384# initial version for Darmstadt 385# 386# Revision 1.9 1996/06/25 20:54:51 lippmann 387# percent was missing after numerical constant, which affected alignment 388# of bubble names in DVI 389# 390# Revision 1.8 1996/06/20 02:28:35 lippmann 391# added \relax in \B 392# 393# Revision 1.7 1996/06/20 02:17:50 lippmann 394# first intensive tested revision with external bubble referencing 395# - HTweblabels{<dvi label files list>}{<html dir list>} to switch it on 396# (list comma separated) 397# - writes its \jobname.lbl file when TeX'ed 398# - reads external dvi label files 399# - external bubble references are solved into <bubble_name file section_no> 400# if possible, else <bubble_name 0>, the old behaviour 401# - supports LaTeX2HTML (together with htmlmac.tex) 402# - narrative comment explanations 403# - bubble names may be complex TeX and filenames may contain underscores 404# 405# Caveat: 406# The contents is pure death to someone who isn't fertile in plain TeX. 407# 408# Revision 1.6 1996/05/27 22:06:23 lippmann 409# moved nasty cvs logging after \endinput 410# 411# Revision 1.5 1996/05/23 00:45:02 lippmann 412# supports now LaTeX 2e 413# 414%****************************************************************** 415