blob: 2e11a50aa320f2f0231f1977935db3d2846aacf8 [file] [log] [blame]
Fred Drakebc7101d1998-03-06 21:18:55 +00001#LaTeX2HTML Version 96.1 : dot.latex2html-init -*- perl -*-
2#
Fred Drake13210ed1998-03-17 06:28:05 +00003# Significantly revised by Fred L. Drake, Jr. <fdrake@acm.org> for use
4# with the Python documentation.
5#
6# New name to avoid distributing "dot" files with the Python documentation.
7#
Fred Drakebc7101d1998-03-06 21:18:55 +00008
Fred Drake41814bc1998-05-11 18:23:35 +00009package Override;
10
11use Cwd qw(getcwd);
12
13
14package main;
15
Fred Drakebc7101d1998-03-06 21:18:55 +000016$INFO = 1; # 0 = do not make a "About this document..." section
17$MAX_LINK_DEPTH = 3;
Fred Draked7571651998-04-23 20:06:24 +000018$ADDRESS = '';
Fred Drakebc7101d1998-03-06 21:18:55 +000019
Fred Drakee194beb1998-05-19 19:38:49 +000020$NO_FOOTNODE = 1;
Fred Drakebc7101d1998-03-06 21:18:55 +000021$NUMBERED_FOOTNOTES = 1;
22
23# Python documentation uses section numbers to support references to match
24# in the printed and online versions.
25#
26$SHOW_SECTION_NUMBERS = 1;
27
28$ICONSERVER = '../icons';
29
Fred Drake0cb76201998-08-07 16:43:29 +000030$BODYTEXT = 'bgcolor="#ffffff"';
Fred Drakebc7101d1998-03-06 21:18:55 +000031$CHILDLINE = "\n<p><hr>\n";
32$VERBOSITY = 0;
Fred Drakebc7101d1998-03-06 21:18:55 +000033
Fred Drakec9f2c141998-03-11 12:08:21 +000034
Fred Drakedb34a1e1998-03-10 23:02:57 +000035# A little painful, but lets us clean up the top level directory a little,
36# and not be tied to the current directory (as far as I can tell).
37#
Fred Drakec9f2c141998-03-11 12:08:21 +000038use Cwd;
39use File::Basename;
40($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
41chop $mydir; # remove trailing '/'
42$mydir = getcwd() . "$dd$mydir"
43 unless $mydir =~ s|^/|/|;
Fred Drakedb34a1e1998-03-10 23:02:57 +000044$LATEX2HTMLSTYLES = "$mydir$envkey$LATEX2HTMLSTYLES";
Fred Drakeb3a3ed81998-07-24 22:17:34 +000045push (@INC, $mydir);
Fred Drakebc7101d1998-03-06 21:18:55 +000046
Fred Drake235e6b11998-03-27 05:19:43 +000047($myrootname, $myrootdir, $myext) = fileparse($mydir, '\..*');
48chop $myrootdir;
49
Fred Drakebc7101d1998-03-06 21:18:55 +000050
Fred Drakea4565b01998-05-15 17:14:17 +000051# Hackish way to get the appropriate paper-*/ directory into $TEXINPUTS;
52# pass in the paper size (a4 or letter) as the environment variable PAPER
53# to add the right directory. If not given, the current directory is
54# added instead for use with HOWTO processing.
55#
56if (defined $ENV{'PAPER'}) {
57 $mytexinputs = "$myrootdir${dd}paper-$ENV{'PAPER'}$envkey";
58}
59else {
60 $mytexinputs = getcwd() . $envkey;
61}
62$mytexinputs .= "$myrootdir${dd}texinputs";
63
64
65sub custom_driver_hook{
66 #
67 # This adds the directory of the main input file to $TEXINPUTS; it
68 # seems to be sufficiently general that it should be fine for HOWTO
69 # processing.
70 #
71 my $file = @_[0];
72 my($jobname,$dir,$ext) = fileparse($file, '\..*');
73 $dir = make_directory_absolute($dir);
74 $dir =~ s/$dd$//;
75 $TEXINPUTS = "$dir$envkey$mytexinputs";
76 print "\nadding $dir to \$TEXINPUTS\n";
77}
78
79
Fred Drake13210ed1998-03-17 06:28:05 +000080sub make_nav_panel{
Fred Drake64bdc241998-04-17 02:14:12 +000081 ($NEXT_TITLE ? $NEXT : '')
82 . ($UP_TITLE ? $UP : '')
83 . ($PREVIOUS_TITLE ? $PREVIOUS : '')
84 . $CONTENTS
85 . $INDEX
Fred Drake13210ed1998-03-17 06:28:05 +000086# . " $CUSTOM_BUTTONS"
Fred Drake64bdc241998-04-17 02:14:12 +000087 . "\n<br>\n"
88 . ($NEXT_TITLE ? "<b>Next:</b> $NEXT_TITLE\n" : '')
Fred Drake13210ed1998-03-17 06:28:05 +000089 . ($UP_TITLE ? "<b>Up:</b> $UP_TITLE\n" : '')
90 . ($PREVIOUS_TITLE ? "<b>Previous:</b> $PREVIOUS_TITLE\n" : '');
91}
92
Fred Drakebc7101d1998-03-06 21:18:55 +000093sub top_navigation_panel {
Fred Drake13210ed1998-03-17 06:28:05 +000094 "<div class=navigation>\n"
Fred Drake64bdc241998-04-17 02:14:12 +000095 . make_nav_panel()
96 . '<br><hr><p></div>';
Fred Drakebc7101d1998-03-06 21:18:55 +000097}
98
99sub bot_navigation_panel {
Fred Drake9d4b6c51998-04-11 05:21:14 +0000100 "<p>\n<div class=navigation><hr>"
Fred Drake64bdc241998-04-17 02:14:12 +0000101 . make_nav_panel()
102 . '</div>';
103}
104
105sub add_link {
106 # Returns a pair (iconic link, textual link)
107 my($icon, $current_file, @link) = @_;
108 my($dummy, $file, $title) = split($delim,
109 $toc_section_info{join(' ',@link)});
110 if ($title && ($file ne $current_file)) {
111 $title = purify($title);
112 $title = get_first_words($title, $WORDS_IN_NAVIGATION_PANEL_TITLES);
113 return (make_href($file, $icon), make_href($file, "$title"))
114 }
115 elsif ($icon eq $up_visible_mark && $EXTERNAL_UP_LINK) {
116 return (make_href($EXTERNAL_UP_LINK, $icon),
117 make_href($EXTERNAL_UP_LINK, "$EXTERNAL_UP_TITLE"))
118 }
119 elsif (($icon eq $previous_visible_mark
120 || $icon eq $previous_page_visible_mark)
121 && $EXTERNAL_PREV_LINK && $EXTERNAL_PREV_TITLE) {
122 return (make_href($EXTERNAL_PREV_LINK, $icon),
123 make_href($EXTERNAL_PREV_LINK, "$EXTERNAL_PREV_TITLE"))
124 }
125 elsif (($icon eq $next_visible_mark
126 || $icon eq $next_page_visible_mark)
127 && $EXTERNAL_DOWN_LINK && $EXTERNAL_DOWN_TITLE) {
128 return (make_href($EXTERNAL_DOWN_LINK, $icon),
129 make_href($EXTERNAL_DOWN_LINK, "$EXTERNAL_DOWN_TITLE"))
130 }
131 (&inactive_img($icon), "");
132}
133
134sub add_special_link {
135 my($icon, $file, $current_file) = @_;
136 (($file && ($file ne $current_file)) ? make_href($file, $icon) : undef)
137}
138
139sub img_tag {
140 local($icon) = @_;
141 my $alt;
142 my $align = " align=bottom ";
143
144 $alt = join('|', 'up', 'next_group', 'previous_group'
145 , 'next', 'previous', 'change_begin_right', 'change_begin'
146 , 'change_end_right', 'change_end', 'change_delete_right'
147 , 'change_delete', 'contents', 'index');
148
149 if ($icon =~ /(gif|png)$/) {
150 $used_icons{$icon} = 1;
151 if ($icon =~ /change_(begin|end|delete)_right/) { $align = ' ' };
152 my $nav_border = "$NAV_BORDER";
153 if ($icon =~ /($alt)/) {
154 $alt = $1;
155 }
156 else {
157 $nav_border = '1';
158 $alt = '[*]';
159 };
160 if ($LOCAL_ICONS) {
161 return join('', '<img ', $iconsizes{$1}, $align
162 ,'border=', $nav_border, ' alt="', $alt
163 ,'" src="', $icon, '">' );
164 }
165 return join('', '<img ', $iconsizes{$1}, $align
166 ,'border=', $nav_border, ' alt="', $alt, '"\n'
167 ,' src="', $ICONSERVER, "/$icon", '">' );
168 }
169 else {
170 return $icon;
171 }
Fred Drakebc7101d1998-03-06 21:18:55 +0000172}
173
174
Fred Drakebc7101d1998-03-06 21:18:55 +0000175sub gen_index_id {
176 # this is used to ensure common index key generation and a stable sort
Fred Drake235e6b11998-03-27 05:19:43 +0000177 my($str,$extra) = @_;
Fred Drake64bdc241998-04-17 02:14:12 +0000178 sprintf('%s###%s%010d', $str, $extra, ++$global{'max_id'});
Fred Drakebc7101d1998-03-06 21:18:55 +0000179}
180
Fred Drake13210ed1998-03-17 06:28:05 +0000181sub make_index_entry {
Fred Drake11916921998-04-02 22:30:57 +0000182 my($br_id,$str) = @_;
Fred Drake13210ed1998-03-17 06:28:05 +0000183 # If TITLE is not yet available (i.e the \index command is in the title of the
184 # current section), use $ref_before.
185 $TITLE = $ref_before unless $TITLE;
186 # Save the reference
187 $str = gen_index_id($str, '');
Fred Drake64bdc241998-04-17 02:14:12 +0000188 $index{$str} .= make_half_href("$CURRENT_FILE#$br_id");
Fred Drake13210ed1998-03-17 06:28:05 +0000189 "<a name=\"$br_id\">$anchor_invisible_mark<\/a>";
190}
Fred Drakebc7101d1998-03-06 21:18:55 +0000191
Fred Drake64bdc241998-04-17 02:14:12 +0000192
193sub insert_index{
194 my($mark,$datafile) = @_;
195 my $index = `$myrootdir/tools/buildindex.py $datafile`;
196 s/$mark/$index/;
197}
198
Fred Drake235e6b11998-03-27 05:19:43 +0000199sub add_idx{
Fred Drake5a525191998-04-02 22:39:05 +0000200 print "\nDoing the index ...";
Fred Drake235e6b11998-03-27 05:19:43 +0000201 close(IDXFILE);
Fred Drake64bdc241998-04-17 02:14:12 +0000202 insert_index($idx_mark, 'index.dat');
Fred Drake13210ed1998-03-17 06:28:05 +0000203}
Fred Drakebc7101d1998-03-06 21:18:55 +0000204
205
206$idx_module_mark = '<tex2html_idx_module_mark>';
207$idx_module_title = 'Module Index';
208
Fred Drake13210ed1998-03-17 06:28:05 +0000209sub add_module_idx{
Fred Drakebc7101d1998-03-06 21:18:55 +0000210 print "\nDoing the module index ...";
Fred Drake235e6b11998-03-27 05:19:43 +0000211 my $key;
Fred Drake64bdc241998-04-17 02:14:12 +0000212 open(MODIDXFILE, '>modindex.dat') || die "\n$!\n";
Fred Drake235e6b11998-03-27 05:19:43 +0000213 foreach $key (keys %Modules) {
214 # dump the line in the data file; just use a dummy seqno field
Fred Drake9d4b6c51998-04-11 05:21:14 +0000215 print MODIDXFILE "$Modules{$key}" . $IDXFILE_FIELD_SEP . "$key###\n";
Fred Drakebc7101d1998-03-06 21:18:55 +0000216 }
Fred Drake235e6b11998-03-27 05:19:43 +0000217 close(MODIDXFILE);
Fred Drake64bdc241998-04-17 02:14:12 +0000218 insert_index($idx_module_mark, 'modindex.dat');
Fred Drakebc7101d1998-03-06 21:18:55 +0000219}
220
Fred Drake235e6b11998-03-27 05:19:43 +0000221# replace both indexes as needed:
222sub add_idx_hook{
Fred Drakeb3a3ed81998-07-24 22:17:34 +0000223 add_idx() if (/$idx_mark/);
224 add_module_idx() if (/$idx_module_mark/);
225 process_all_localmoduletables();
Fred Drake235e6b11998-03-27 05:19:43 +0000226}
Fred Drakebc7101d1998-03-06 21:18:55 +0000227
Fred Drakebc7101d1998-03-06 21:18:55 +0000228
229# In addition to the standard stuff, add label to allow named node files.
230sub do_cmd_tableofcontents {
231 local($_) = @_;
232 $TITLE = $toc_title;
233 $tocfile = $CURRENT_FILE;
Fred Drake64bdc241998-04-17 02:14:12 +0000234 my($closures,$reopens) = preserve_open_tags();
235 anchor_label('contents', $CURRENT_FILE, $_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000236 join('', "<BR>\n", $closures
Fred Drake64bdc241998-04-17 02:14:12 +0000237 , make_section_heading($toc_title, 'H2'), $toc_mark
Fred Drakebc7101d1998-03-06 21:18:55 +0000238 , $reopens, $_);
239}
240# In addition to the standard stuff, add label to allow named node files.
241sub do_cmd_listoffigures {
242 local($_) = @_;
243 $TITLE = $lof_title;
244 $loffile = $CURRENT_FILE;
Fred Drake64bdc241998-04-17 02:14:12 +0000245 my($closures,$reopens) = preserve_open_tags();
246 anchor_label('lof', $CURRENT_FILE, $_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000247 join('', "<BR>\n", $closures
Fred Drake64bdc241998-04-17 02:14:12 +0000248 , make_section_heading($lof_title, 'H2'), $lof_mark
Fred Drakebc7101d1998-03-06 21:18:55 +0000249 , $reopens, $_);
250}
251# In addition to the standard stuff, add label to allow named node files.
252sub do_cmd_listoftables {
253 local($_) = @_;
254 $TITLE = $lot_title;
255 $lotfile = $CURRENT_FILE;
Fred Drake64bdc241998-04-17 02:14:12 +0000256 my($closures,$reopens) = preserve_open_tags();
257 anchor_label('lot', $CURRENT_FILE, $_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000258 join('', "<BR>\n", $closures
Fred Drake64bdc241998-04-17 02:14:12 +0000259 , make_section_heading($lot_title, 'H2'), $lot_mark
Fred Drakebc7101d1998-03-06 21:18:55 +0000260 , $reopens, $_);
261}
262# In addition to the standard stuff, add label to allow named node files.
263sub do_cmd_textohtmlinfopage {
264 local($_) = @_;
265 if ($INFO) { #
Fred Drake64bdc241998-04-17 02:14:12 +0000266 anchor_label("about",$CURRENT_FILE,$_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000267 } #
268 ( ($INFO == 1)
269 ? join('', $close_all
270 , "<STRONG>$t_title</STRONG><P>\nThis document was generated using the\n"
271 , "<A HREF=\"$TEX2HTMLADDRESS\"><STRONG>LaTeX</STRONG>2<tt>HTML</tt></A>"
272 , " translator Version $TEX2HTMLVERSION\n"
273 , "<P>Copyright &#169; 1993, 1994, 1995, 1996, 1997,\n"
274 , "<A HREF=\"$AUTHORADDRESS\">Nikos Drakos</A>, \n"
275 , "Computer Based Learning Unit, University of Leeds.\n"
276 , "<P>The command line arguments were: <BR>\n "
277 , "<STRONG>latex2html</STRONG> <tt>$argv</tt>.\n"
278 , "<P>The translation was initiated by $address_data[0] on $address_data[1]"
279 , $open_all, $_)
280 : join('', $close_all, $INFO,"\n", $open_all, $_))
281}
282
283# $idx_mark will be replaced with the real index at the end
284sub do_cmd_textohtmlindex {
285 local($_) = @_;
286 $TITLE = $idx_title;
287 $idxfile = $CURRENT_FILE;
Fred Drake235e6b11998-03-27 05:19:43 +0000288 if (%index_labels) { make_index_labels(); }
289 if (($SHORT_INDEX) && (%index_segment)) { make_preindex(); }
Fred Drakebc7101d1998-03-06 21:18:55 +0000290 else { $preindex = ''; }
Fred Drake235e6b11998-03-27 05:19:43 +0000291 my $heading = make_section_heading($idx_title, 'h2') . $idx_mark;
Fred Drake11916921998-04-02 22:30:57 +0000292 my($pre,$post) = minimize_open_tags($heading);
Fred Drake235e6b11998-03-27 05:19:43 +0000293 anchor_label('genindex',$CURRENT_FILE,$_); # this is added
294 '<br>\n' . $pre . $_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000295}
296
297# $idx_module_mark will be replaced with the real index at the end
298sub do_cmd_textohtmlmoduleindex {
299 local($_) = @_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000300 $TITLE = $idx_module_title;
Fred Drake64bdc241998-04-17 02:14:12 +0000301 anchor_label("modindex",$CURRENT_FILE,$_);
Fred Drake235e6b11998-03-27 05:19:43 +0000302 '<p>' . make_section_heading($idx_module_title, "h2")
303 . $idx_module_mark . $_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000304}
305
306# The bibliography and the index should be treated as separate sections
307# in their own HTML files. The \bibliography{} command acts as a sectioning command
308# that has the desired effect. But when the bibliography is constructed
309# manually using the thebibliography environment, or when using the
310# theindex environment it is not possible to use the normal sectioning
311# mechanism. This subroutine inserts a \bibliography{} or a dummy
312# \textohtmlindex command just before the appropriate environments
313# to force sectioning.
314
315# XXX This *assumes* that if there are two {theindex} environments, the
316# first is the module index and the second is the standard index. This
317# is sufficient for the current Python documentation, but that's about
318# it.
319
320sub add_bbl_and_idx_dummy_commands {
Fred Drake11916921998-04-02 22:30:57 +0000321 my $id = $global{'max_id'};
Fred Drakebc7101d1998-03-06 21:18:55 +0000322
323 s/([\\]begin\s*$O\d+$C\s*thebibliography)/$bbl_cnt++; $1/eg;
324 s/([\\]begin\s*$O\d+$C\s*thebibliography)/$id++; "\\bibliography$O$id$C$O$id$C $1"/geo
325 #if ($bbl_cnt == 1)
326 ;
327 #}
Fred Drake11916921998-04-02 22:30:57 +0000328 #----------------------------------------------------------------------
329 # (FLD) This was added
330 my(@parts) = split(/\\begin\s*$O\d+$C\s*theindex/);
331 if (scalar(@parts) == 3) {
332 # Be careful to re-write the string in place, since $_ is *not*
333 # returned explicity; *** nasty side-effect dependency! ***
334 print "\nadd_bbl_and_idx_dummy_commands ==> adding module index";
335 my $rx = "([\\\\]begin\\s*$O\\d+$C\\s*theindex[\\s\\S]*)"
336 . "([\\\\]begin\\s*$O\\d+$C\\s*theindex)";
337 s/$rx/\\textohtmlmoduleindex \1 \\textohtmlindex \2/o;
338 }
339 else {
340 $global{'max_id'} = $id; # not sure why....
341 s/([\\]begin\s*$O\d+$C\s*theindex)/\\textohtmlindex $1/o;
342 s/[\\]printindex/\\textohtmlindex /o;
343 }
344 #----------------------------------------------------------------------
Fred Drake64bdc241998-04-17 02:14:12 +0000345 lib_add_bbl_and_idx_dummy_commands()
Fred Drake11916921998-04-02 22:30:57 +0000346 if defined(&lib_add_bbl_and_idx_dummy_commands);
Fred Drakebc7101d1998-03-06 21:18:55 +0000347}
348
349# The bibliographic references, the appendices, the lists of figures and tables
350# etc. must appear in the contents table at the same level as the outermost
351# sectioning command. This subroutine finds what is the outermost level and
352# sets the above to the same level;
353
Fred Drake13210ed1998-03-17 06:28:05 +0000354sub set_depth_levels {
355 # Sets $outermost_level
Fred Drake11916921998-04-02 22:30:57 +0000356 my $level;
Fred Drake13210ed1998-03-17 06:28:05 +0000357 #RRM: do not alter user-set value for $MAX_SPLIT_DEPTH
358 foreach $level ("part", "chapter", "section", "subsection",
359 "subsubsection", "paragraph") {
360 last if (($outermost_level) = /\\($level)$delimiter_rx/);
361 }
362 $level = ($outermost_level ? $section_commands{$outermost_level} :
363 do {$outermost_level = 'section'; 3;});
Fred Drakebc7101d1998-03-06 21:18:55 +0000364
Fred Drake13210ed1998-03-17 06:28:05 +0000365 #RRM: but calculate value for $MAX_SPLIT_DEPTH when a $REL_DEPTH was given
366 if ($REL_DEPTH && $MAX_SPLIT_DEPTH) {
367 $MAX_SPLIT_DEPTH = $level + $MAX_SPLIT_DEPTH;
368 } elsif (!($MAX_SPLIT_DEPTH)) { $MAX_SPLIT_DEPTH = 1 };
Fred Drakebc7101d1998-03-06 21:18:55 +0000369
Fred Drake64bdc241998-04-17 02:14:12 +0000370 %unnumbered_section_commands = ('tableofcontents' => $level,
371 'listoffigures' => $level,
372 'listoftables' => $level,
373 'bibliography' => $level,
374 'textohtmlindex' => $level,
375 'textohtmlmoduleindex' => $level);
376 $section_headings{'textohtmlmoduleindex'} = 'h1';
Fred Drakebc7101d1998-03-06 21:18:55 +0000377
Fred Drake64bdc241998-04-17 02:14:12 +0000378 %section_commands = (%unnumbered_section_commands,
379 %section_commands);
Fred Drake11916921998-04-02 22:30:57 +0000380
381 make_sections_rx();
Fred Drake13210ed1998-03-17 06:28:05 +0000382}
Fred Drakebc7101d1998-03-06 21:18:55 +0000383
384
385# Fix from Ross Moore for ']' in \item[...]; this can be removed once the next
Fred Drake235e6b11998-03-27 05:19:43 +0000386# patch to LaTeX2HTML is released and tested ... if the patch gets included.
387# Be very careful to keep this around, just in case things break again!
Fred Drakebc7101d1998-03-06 21:18:55 +0000388#
389sub protect_useritems {
390 local(*_) = @_;
Fred Drake11916921998-04-02 22:30:57 +0000391 local($preitems,$thisitem);
Fred Drakebc7101d1998-03-06 21:18:55 +0000392 while (/\\item\s*\[/) {
Fred Drake11916921998-04-02 22:30:57 +0000393 $preitems .= $`;
394 $_ = $';
Fred Drakebc7101d1998-03-06 21:18:55 +0000395 $thisitem = $&.'<<'.++$global{'max_id'}.'>>';
396 s/^(((($O|$OP)\d+($C|$CP)).*\3|<[^<>]*>|[^\]<]+)*)\]/$thisitem.=$1;''/e;
Fred Drake11916921998-04-02 22:30:57 +0000397 $preitems .= $thisitem . '<<' . $global{'max_id'} . '>>]';
398 s/^]//;
Fred Drakebc7101d1998-03-06 21:18:55 +0000399 }
400 $_ = $preitems . $_;
401}
402
Fred Drake1072e461998-04-12 02:16:34 +0000403# This changes the markup used for {verbatim} environments, and is the
404# best way I've found that ensures the <dl> goes one the outside of the
405# <pre>...</pre>.
406#
407# Note that this *must* be done in the init file, not the python.perl
408# style support file. The %declarations must be set before initialize()
409# is called in the main script.
410#
Fred Drake64bdc241998-04-17 02:14:12 +0000411%declarations = ('preform' => '<dl><dd><pre></pre></dl>',
Fred Drake1072e461998-04-12 02:16:34 +0000412 %declarations);
413
Fred Drakebc7101d1998-03-06 21:18:55 +00004141; # This must be the last line