blob: 0085152631dcecb587d7d68f55e53b9a47e31f4f [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
20$NUMBERED_FOOTNOTES = 1;
21
22# Python documentation uses section numbers to support references to match
23# in the printed and online versions.
24#
25$SHOW_SECTION_NUMBERS = 1;
26
27$ICONSERVER = '../icons';
28
29$CHILDLINE = "\n<p><hr>\n";
30$VERBOSITY = 0;
Fred Drake89a1d4a1998-04-29 16:58:13 +000031$TEXINPUTS = ''; # avoid bogus l2h setting it to ':' !!!
32
Fred Drakebc7101d1998-03-06 21:18:55 +000033
Fred Drake41814bc1998-05-11 18:23:35 +000034sub absolutize_path{
35 my $path = @_[0];
36 my $npath = '';
37 foreach $dir (split $envkey, $path) {
38 $npath .= make_directory_absolute($dir) . $envkey;
39 }
40 $npath =~ s/$envkey$//;
41 $npath;
42}
43# This is done because latex2html doesn't do this for us, but does change the
44# directory out from under us.
45if (defined $ENV{'TEXINPUTS'}) {
46 $ENV{'TEXINPUTS'} = absolutize_path($ENV{'TEXINPUTS'});
47}
48
Fred Drakedb34a1e1998-03-10 23:02:57 +000049# Locate a file that's been "require"d. Assumes that the file name of interest
50# is unique within the set of loaded files, after directory names have been
51# stripped. Only the directory is returned.
52#
53sub find_my_file{
Fred Drake11916921998-04-02 22:30:57 +000054 my($myfile,$key,$tmp,$mydir) = (@_[0], '', '', '');
Fred Drakedb34a1e1998-03-10 23:02:57 +000055 foreach $key (keys %INC) {
56 $tmp = "$key";
57 $tmp =~ s|^.*/||o;
58 if ($tmp eq $myfile) {
Fred Drakedb34a1e1998-03-10 23:02:57 +000059 $mydir = $INC{$key};
60 }
61 }
62 $mydir =~ s|/[^/]*$||;
63 $mydir;
64}
Fred Drakebc7101d1998-03-06 21:18:55 +000065
Fred Drakec9f2c141998-03-11 12:08:21 +000066
Fred Drakedb34a1e1998-03-10 23:02:57 +000067# A little painful, but lets us clean up the top level directory a little,
68# and not be tied to the current directory (as far as I can tell).
69#
Fred Drakec9f2c141998-03-11 12:08:21 +000070use Cwd;
71use File::Basename;
72($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
73chop $mydir; # remove trailing '/'
74$mydir = getcwd() . "$dd$mydir"
75 unless $mydir =~ s|^/|/|;
Fred Drakedb34a1e1998-03-10 23:02:57 +000076$LATEX2HTMLSTYLES = "$mydir$envkey$LATEX2HTMLSTYLES";
Fred Drakebc7101d1998-03-06 21:18:55 +000077
Fred Drake235e6b11998-03-27 05:19:43 +000078($myrootname, $myrootdir, $myext) = fileparse($mydir, '\..*');
79chop $myrootdir;
80
Fred Drakebc7101d1998-03-06 21:18:55 +000081
Fred Drake13210ed1998-03-17 06:28:05 +000082sub make_nav_panel{
Fred Drake64bdc241998-04-17 02:14:12 +000083 ($NEXT_TITLE ? $NEXT : '')
84 . ($UP_TITLE ? $UP : '')
85 . ($PREVIOUS_TITLE ? $PREVIOUS : '')
86 . $CONTENTS
87 . $INDEX
Fred Drake13210ed1998-03-17 06:28:05 +000088# . " $CUSTOM_BUTTONS"
Fred Drake64bdc241998-04-17 02:14:12 +000089 . "\n<br>\n"
90 . ($NEXT_TITLE ? "<b>Next:</b> $NEXT_TITLE\n" : '')
Fred Drake13210ed1998-03-17 06:28:05 +000091 . ($UP_TITLE ? "<b>Up:</b> $UP_TITLE\n" : '')
92 . ($PREVIOUS_TITLE ? "<b>Previous:</b> $PREVIOUS_TITLE\n" : '');
93}
94
Fred Drakebc7101d1998-03-06 21:18:55 +000095sub top_navigation_panel {
Fred Drake13210ed1998-03-17 06:28:05 +000096 "<div class=navigation>\n"
Fred Drake64bdc241998-04-17 02:14:12 +000097 . make_nav_panel()
98 . '<br><hr><p></div>';
Fred Drakebc7101d1998-03-06 21:18:55 +000099}
100
101sub bot_navigation_panel {
Fred Drake9d4b6c51998-04-11 05:21:14 +0000102 "<p>\n<div class=navigation><hr>"
Fred Drake64bdc241998-04-17 02:14:12 +0000103 . make_nav_panel()
104 . '</div>';
105}
106
107sub add_link {
108 # Returns a pair (iconic link, textual link)
109 my($icon, $current_file, @link) = @_;
110 my($dummy, $file, $title) = split($delim,
111 $toc_section_info{join(' ',@link)});
112 if ($title && ($file ne $current_file)) {
113 $title = purify($title);
114 $title = get_first_words($title, $WORDS_IN_NAVIGATION_PANEL_TITLES);
115 return (make_href($file, $icon), make_href($file, "$title"))
116 }
117 elsif ($icon eq $up_visible_mark && $EXTERNAL_UP_LINK) {
118 return (make_href($EXTERNAL_UP_LINK, $icon),
119 make_href($EXTERNAL_UP_LINK, "$EXTERNAL_UP_TITLE"))
120 }
121 elsif (($icon eq $previous_visible_mark
122 || $icon eq $previous_page_visible_mark)
123 && $EXTERNAL_PREV_LINK && $EXTERNAL_PREV_TITLE) {
124 return (make_href($EXTERNAL_PREV_LINK, $icon),
125 make_href($EXTERNAL_PREV_LINK, "$EXTERNAL_PREV_TITLE"))
126 }
127 elsif (($icon eq $next_visible_mark
128 || $icon eq $next_page_visible_mark)
129 && $EXTERNAL_DOWN_LINK && $EXTERNAL_DOWN_TITLE) {
130 return (make_href($EXTERNAL_DOWN_LINK, $icon),
131 make_href($EXTERNAL_DOWN_LINK, "$EXTERNAL_DOWN_TITLE"))
132 }
133 (&inactive_img($icon), "");
134}
135
136sub add_special_link {
137 my($icon, $file, $current_file) = @_;
138 (($file && ($file ne $current_file)) ? make_href($file, $icon) : undef)
139}
140
141sub img_tag {
142 local($icon) = @_;
143 my $alt;
144 my $align = " align=bottom ";
145
146 $alt = join('|', 'up', 'next_group', 'previous_group'
147 , 'next', 'previous', 'change_begin_right', 'change_begin'
148 , 'change_end_right', 'change_end', 'change_delete_right'
149 , 'change_delete', 'contents', 'index');
150
151 if ($icon =~ /(gif|png)$/) {
152 $used_icons{$icon} = 1;
153 if ($icon =~ /change_(begin|end|delete)_right/) { $align = ' ' };
154 my $nav_border = "$NAV_BORDER";
155 if ($icon =~ /($alt)/) {
156 $alt = $1;
157 }
158 else {
159 $nav_border = '1';
160 $alt = '[*]';
161 };
162 if ($LOCAL_ICONS) {
163 return join('', '<img ', $iconsizes{$1}, $align
164 ,'border=', $nav_border, ' alt="', $alt
165 ,'" src="', $icon, '">' );
166 }
167 return join('', '<img ', $iconsizes{$1}, $align
168 ,'border=', $nav_border, ' alt="', $alt, '"\n'
169 ,' src="', $ICONSERVER, "/$icon", '">' );
170 }
171 else {
172 return $icon;
173 }
Fred Drakebc7101d1998-03-06 21:18:55 +0000174}
175
176
Fred Drakebc7101d1998-03-06 21:18:55 +0000177sub gen_index_id {
178 # this is used to ensure common index key generation and a stable sort
Fred Drake235e6b11998-03-27 05:19:43 +0000179 my($str,$extra) = @_;
Fred Drake64bdc241998-04-17 02:14:12 +0000180 sprintf('%s###%s%010d', $str, $extra, ++$global{'max_id'});
Fred Drakebc7101d1998-03-06 21:18:55 +0000181}
182
Fred Drake13210ed1998-03-17 06:28:05 +0000183sub make_index_entry {
Fred Drake11916921998-04-02 22:30:57 +0000184 my($br_id,$str) = @_;
Fred Drake13210ed1998-03-17 06:28:05 +0000185 # If TITLE is not yet available (i.e the \index command is in the title of the
186 # current section), use $ref_before.
187 $TITLE = $ref_before unless $TITLE;
188 # Save the reference
189 $str = gen_index_id($str, '');
Fred Drake64bdc241998-04-17 02:14:12 +0000190 $index{$str} .= make_half_href("$CURRENT_FILE#$br_id");
Fred Drake13210ed1998-03-17 06:28:05 +0000191 "<a name=\"$br_id\">$anchor_invisible_mark<\/a>";
192}
Fred Drakebc7101d1998-03-06 21:18:55 +0000193
Fred Drake64bdc241998-04-17 02:14:12 +0000194
195sub insert_index{
196 my($mark,$datafile) = @_;
197 my $index = `$myrootdir/tools/buildindex.py $datafile`;
198 s/$mark/$index/;
199}
200
Fred Drake235e6b11998-03-27 05:19:43 +0000201sub add_idx{
Fred Drake5a525191998-04-02 22:39:05 +0000202 print "\nDoing the index ...";
Fred Drake235e6b11998-03-27 05:19:43 +0000203 close(IDXFILE);
Fred Drake64bdc241998-04-17 02:14:12 +0000204 insert_index($idx_mark, 'index.dat');
Fred Drake13210ed1998-03-17 06:28:05 +0000205}
Fred Drakebc7101d1998-03-06 21:18:55 +0000206
207
208$idx_module_mark = '<tex2html_idx_module_mark>';
209$idx_module_title = 'Module Index';
210
Fred Drake13210ed1998-03-17 06:28:05 +0000211sub add_module_idx{
Fred Drakebc7101d1998-03-06 21:18:55 +0000212 print "\nDoing the module index ...";
Fred Drake235e6b11998-03-27 05:19:43 +0000213 my $key;
Fred Drake64bdc241998-04-17 02:14:12 +0000214 open(MODIDXFILE, '>modindex.dat') || die "\n$!\n";
Fred Drake235e6b11998-03-27 05:19:43 +0000215 foreach $key (keys %Modules) {
216 # dump the line in the data file; just use a dummy seqno field
Fred Drake9d4b6c51998-04-11 05:21:14 +0000217 print MODIDXFILE "$Modules{$key}" . $IDXFILE_FIELD_SEP . "$key###\n";
Fred Drakebc7101d1998-03-06 21:18:55 +0000218 }
Fred Drake235e6b11998-03-27 05:19:43 +0000219 close(MODIDXFILE);
Fred Drake64bdc241998-04-17 02:14:12 +0000220 insert_index($idx_module_mark, 'modindex.dat');
Fred Drakebc7101d1998-03-06 21:18:55 +0000221}
222
Fred Drake235e6b11998-03-27 05:19:43 +0000223# replace both indexes as needed:
224sub add_idx_hook{
225 &add_idx if (/$idx_mark/);
226 &add_module_idx if (/$idx_module_mark/);
227}
Fred Drakebc7101d1998-03-06 21:18:55 +0000228
Fred Drakebc7101d1998-03-06 21:18:55 +0000229
230# In addition to the standard stuff, add label to allow named node files.
231sub do_cmd_tableofcontents {
232 local($_) = @_;
233 $TITLE = $toc_title;
234 $tocfile = $CURRENT_FILE;
Fred Drake64bdc241998-04-17 02:14:12 +0000235 my($closures,$reopens) = preserve_open_tags();
236 anchor_label('contents', $CURRENT_FILE, $_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000237 join('', "<BR>\n", $closures
Fred Drake64bdc241998-04-17 02:14:12 +0000238 , make_section_heading($toc_title, 'H2'), $toc_mark
Fred Drakebc7101d1998-03-06 21:18:55 +0000239 , $reopens, $_);
240}
241# In addition to the standard stuff, add label to allow named node files.
242sub do_cmd_listoffigures {
243 local($_) = @_;
244 $TITLE = $lof_title;
245 $loffile = $CURRENT_FILE;
Fred Drake64bdc241998-04-17 02:14:12 +0000246 my($closures,$reopens) = preserve_open_tags();
247 anchor_label('lof', $CURRENT_FILE, $_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000248 join('', "<BR>\n", $closures
Fred Drake64bdc241998-04-17 02:14:12 +0000249 , make_section_heading($lof_title, 'H2'), $lof_mark
Fred Drakebc7101d1998-03-06 21:18:55 +0000250 , $reopens, $_);
251}
252# In addition to the standard stuff, add label to allow named node files.
253sub do_cmd_listoftables {
254 local($_) = @_;
255 $TITLE = $lot_title;
256 $lotfile = $CURRENT_FILE;
Fred Drake64bdc241998-04-17 02:14:12 +0000257 my($closures,$reopens) = preserve_open_tags();
258 anchor_label('lot', $CURRENT_FILE, $_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000259 join('', "<BR>\n", $closures
Fred Drake64bdc241998-04-17 02:14:12 +0000260 , make_section_heading($lot_title, 'H2'), $lot_mark
Fred Drakebc7101d1998-03-06 21:18:55 +0000261 , $reopens, $_);
262}
263# In addition to the standard stuff, add label to allow named node files.
264sub do_cmd_textohtmlinfopage {
265 local($_) = @_;
266 if ($INFO) { #
Fred Drake64bdc241998-04-17 02:14:12 +0000267 anchor_label("about",$CURRENT_FILE,$_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000268 } #
269 ( ($INFO == 1)
270 ? join('', $close_all
271 , "<STRONG>$t_title</STRONG><P>\nThis document was generated using the\n"
272 , "<A HREF=\"$TEX2HTMLADDRESS\"><STRONG>LaTeX</STRONG>2<tt>HTML</tt></A>"
273 , " translator Version $TEX2HTMLVERSION\n"
274 , "<P>Copyright &#169; 1993, 1994, 1995, 1996, 1997,\n"
275 , "<A HREF=\"$AUTHORADDRESS\">Nikos Drakos</A>, \n"
276 , "Computer Based Learning Unit, University of Leeds.\n"
277 , "<P>The command line arguments were: <BR>\n "
278 , "<STRONG>latex2html</STRONG> <tt>$argv</tt>.\n"
279 , "<P>The translation was initiated by $address_data[0] on $address_data[1]"
280 , $open_all, $_)
281 : join('', $close_all, $INFO,"\n", $open_all, $_))
282}
283
284# $idx_mark will be replaced with the real index at the end
285sub do_cmd_textohtmlindex {
286 local($_) = @_;
287 $TITLE = $idx_title;
288 $idxfile = $CURRENT_FILE;
Fred Drake235e6b11998-03-27 05:19:43 +0000289 if (%index_labels) { make_index_labels(); }
290 if (($SHORT_INDEX) && (%index_segment)) { make_preindex(); }
Fred Drakebc7101d1998-03-06 21:18:55 +0000291 else { $preindex = ''; }
Fred Drake235e6b11998-03-27 05:19:43 +0000292 my $heading = make_section_heading($idx_title, 'h2') . $idx_mark;
Fred Drake11916921998-04-02 22:30:57 +0000293 my($pre,$post) = minimize_open_tags($heading);
Fred Drake235e6b11998-03-27 05:19:43 +0000294 anchor_label('genindex',$CURRENT_FILE,$_); # this is added
295 '<br>\n' . $pre . $_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000296}
297
298# $idx_module_mark will be replaced with the real index at the end
299sub do_cmd_textohtmlmoduleindex {
300 local($_) = @_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000301 $TITLE = $idx_module_title;
Fred Drake64bdc241998-04-17 02:14:12 +0000302 anchor_label("modindex",$CURRENT_FILE,$_);
Fred Drake235e6b11998-03-27 05:19:43 +0000303 '<p>' . make_section_heading($idx_module_title, "h2")
304 . $idx_module_mark . $_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000305}
306
307# The bibliography and the index should be treated as separate sections
308# in their own HTML files. The \bibliography{} command acts as a sectioning command
309# that has the desired effect. But when the bibliography is constructed
310# manually using the thebibliography environment, or when using the
311# theindex environment it is not possible to use the normal sectioning
312# mechanism. This subroutine inserts a \bibliography{} or a dummy
313# \textohtmlindex command just before the appropriate environments
314# to force sectioning.
315
316# XXX This *assumes* that if there are two {theindex} environments, the
317# first is the module index and the second is the standard index. This
318# is sufficient for the current Python documentation, but that's about
319# it.
320
321sub add_bbl_and_idx_dummy_commands {
Fred Drake11916921998-04-02 22:30:57 +0000322 my $id = $global{'max_id'};
Fred Drakebc7101d1998-03-06 21:18:55 +0000323
324 s/([\\]begin\s*$O\d+$C\s*thebibliography)/$bbl_cnt++; $1/eg;
325 s/([\\]begin\s*$O\d+$C\s*thebibliography)/$id++; "\\bibliography$O$id$C$O$id$C $1"/geo
326 #if ($bbl_cnt == 1)
327 ;
328 #}
Fred Drake11916921998-04-02 22:30:57 +0000329 #----------------------------------------------------------------------
330 # (FLD) This was added
331 my(@parts) = split(/\\begin\s*$O\d+$C\s*theindex/);
332 if (scalar(@parts) == 3) {
333 # Be careful to re-write the string in place, since $_ is *not*
334 # returned explicity; *** nasty side-effect dependency! ***
335 print "\nadd_bbl_and_idx_dummy_commands ==> adding module index";
336 my $rx = "([\\\\]begin\\s*$O\\d+$C\\s*theindex[\\s\\S]*)"
337 . "([\\\\]begin\\s*$O\\d+$C\\s*theindex)";
338 s/$rx/\\textohtmlmoduleindex \1 \\textohtmlindex \2/o;
339 }
340 else {
341 $global{'max_id'} = $id; # not sure why....
342 s/([\\]begin\s*$O\d+$C\s*theindex)/\\textohtmlindex $1/o;
343 s/[\\]printindex/\\textohtmlindex /o;
344 }
345 #----------------------------------------------------------------------
Fred Drake64bdc241998-04-17 02:14:12 +0000346 lib_add_bbl_and_idx_dummy_commands()
Fred Drake11916921998-04-02 22:30:57 +0000347 if defined(&lib_add_bbl_and_idx_dummy_commands);
Fred Drakebc7101d1998-03-06 21:18:55 +0000348}
349
350# The bibliographic references, the appendices, the lists of figures and tables
351# etc. must appear in the contents table at the same level as the outermost
352# sectioning command. This subroutine finds what is the outermost level and
353# sets the above to the same level;
354
Fred Drake13210ed1998-03-17 06:28:05 +0000355sub set_depth_levels {
356 # Sets $outermost_level
Fred Drake11916921998-04-02 22:30:57 +0000357 my $level;
Fred Drake13210ed1998-03-17 06:28:05 +0000358 #RRM: do not alter user-set value for $MAX_SPLIT_DEPTH
359 foreach $level ("part", "chapter", "section", "subsection",
360 "subsubsection", "paragraph") {
361 last if (($outermost_level) = /\\($level)$delimiter_rx/);
362 }
363 $level = ($outermost_level ? $section_commands{$outermost_level} :
364 do {$outermost_level = 'section'; 3;});
Fred Drakebc7101d1998-03-06 21:18:55 +0000365
Fred Drake13210ed1998-03-17 06:28:05 +0000366 #RRM: but calculate value for $MAX_SPLIT_DEPTH when a $REL_DEPTH was given
367 if ($REL_DEPTH && $MAX_SPLIT_DEPTH) {
368 $MAX_SPLIT_DEPTH = $level + $MAX_SPLIT_DEPTH;
369 } elsif (!($MAX_SPLIT_DEPTH)) { $MAX_SPLIT_DEPTH = 1 };
Fred Drakebc7101d1998-03-06 21:18:55 +0000370
Fred Drake64bdc241998-04-17 02:14:12 +0000371 %unnumbered_section_commands = ('tableofcontents' => $level,
372 'listoffigures' => $level,
373 'listoftables' => $level,
374 'bibliography' => $level,
375 'textohtmlindex' => $level,
376 'textohtmlmoduleindex' => $level);
377 $section_headings{'textohtmlmoduleindex'} = 'h1';
Fred Drakebc7101d1998-03-06 21:18:55 +0000378
Fred Drake64bdc241998-04-17 02:14:12 +0000379 %section_commands = (%unnumbered_section_commands,
380 %section_commands);
Fred Drake11916921998-04-02 22:30:57 +0000381
382 make_sections_rx();
Fred Drake13210ed1998-03-17 06:28:05 +0000383}
Fred Drakebc7101d1998-03-06 21:18:55 +0000384
385
386# Fix from Ross Moore for ']' in \item[...]; this can be removed once the next
Fred Drake235e6b11998-03-27 05:19:43 +0000387# patch to LaTeX2HTML is released and tested ... if the patch gets included.
388# Be very careful to keep this around, just in case things break again!
Fred Drakebc7101d1998-03-06 21:18:55 +0000389#
390sub protect_useritems {
391 local(*_) = @_;
Fred Drake11916921998-04-02 22:30:57 +0000392 local($preitems,$thisitem);
Fred Drakebc7101d1998-03-06 21:18:55 +0000393 while (/\\item\s*\[/) {
Fred Drake11916921998-04-02 22:30:57 +0000394 $preitems .= $`;
395 $_ = $';
Fred Drakebc7101d1998-03-06 21:18:55 +0000396 $thisitem = $&.'<<'.++$global{'max_id'}.'>>';
397 s/^(((($O|$OP)\d+($C|$CP)).*\3|<[^<>]*>|[^\]<]+)*)\]/$thisitem.=$1;''/e;
Fred Drake11916921998-04-02 22:30:57 +0000398 $preitems .= $thisitem . '<<' . $global{'max_id'} . '>>]';
399 s/^]//;
Fred Drakebc7101d1998-03-06 21:18:55 +0000400 }
401 $_ = $preitems . $_;
402}
403
Fred Drake1072e461998-04-12 02:16:34 +0000404# This changes the markup used for {verbatim} environments, and is the
405# best way I've found that ensures the <dl> goes one the outside of the
406# <pre>...</pre>.
407#
408# Note that this *must* be done in the init file, not the python.perl
409# style support file. The %declarations must be set before initialize()
410# is called in the main script.
411#
Fred Drake64bdc241998-04-17 02:14:12 +0000412%declarations = ('preform' => '<dl><dd><pre></pre></dl>',
Fred Drake1072e461998-04-12 02:16:34 +0000413 %declarations);
414
Fred Drakebc7101d1998-03-06 21:18:55 +00004151; # This must be the last line