blob: 3841036c6d47d458e770a32333c6e1f14b990ddd [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
9$INFO = 1; # 0 = do not make a "About this document..." section
10$MAX_LINK_DEPTH = 3;
Fred Draked7571651998-04-23 20:06:24 +000011$ADDRESS = '';
Fred Drakebc7101d1998-03-06 21:18:55 +000012
13$NUMBERED_FOOTNOTES = 1;
14
15# Python documentation uses section numbers to support references to match
16# in the printed and online versions.
17#
18$SHOW_SECTION_NUMBERS = 1;
19
20$ICONSERVER = '../icons';
21
22$CHILDLINE = "\n<p><hr>\n";
23$VERBOSITY = 0;
Fred Drake89a1d4a1998-04-29 16:58:13 +000024$TEXINPUTS = ''; # avoid bogus l2h setting it to ':' !!!
25
Fred Drakebc7101d1998-03-06 21:18:55 +000026
Fred Drakedb34a1e1998-03-10 23:02:57 +000027# Locate a file that's been "require"d. Assumes that the file name of interest
28# is unique within the set of loaded files, after directory names have been
29# stripped. Only the directory is returned.
30#
31sub find_my_file{
Fred Drake11916921998-04-02 22:30:57 +000032 my($myfile,$key,$tmp,$mydir) = (@_[0], '', '', '');
Fred Drakedb34a1e1998-03-10 23:02:57 +000033 foreach $key (keys %INC) {
34 $tmp = "$key";
35 $tmp =~ s|^.*/||o;
36 if ($tmp eq $myfile) {
Fred Drakedb34a1e1998-03-10 23:02:57 +000037 $mydir = $INC{$key};
38 }
39 }
40 $mydir =~ s|/[^/]*$||;
41 $mydir;
42}
Fred Drakebc7101d1998-03-06 21:18:55 +000043
Fred Drakec9f2c141998-03-11 12:08:21 +000044
Fred Drakedb34a1e1998-03-10 23:02:57 +000045# A little painful, but lets us clean up the top level directory a little,
46# and not be tied to the current directory (as far as I can tell).
47#
Fred Drakec9f2c141998-03-11 12:08:21 +000048use Cwd;
49use File::Basename;
50($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
51chop $mydir; # remove trailing '/'
52$mydir = getcwd() . "$dd$mydir"
53 unless $mydir =~ s|^/|/|;
Fred Drakedb34a1e1998-03-10 23:02:57 +000054$LATEX2HTMLSTYLES = "$mydir$envkey$LATEX2HTMLSTYLES";
Fred Drakebc7101d1998-03-06 21:18:55 +000055
Fred Drake235e6b11998-03-27 05:19:43 +000056($myrootname, $myrootdir, $myext) = fileparse($mydir, '\..*');
57chop $myrootdir;
58
Fred Drakebc7101d1998-03-06 21:18:55 +000059
Fred Drake13210ed1998-03-17 06:28:05 +000060sub make_nav_panel{
Fred Drake64bdc241998-04-17 02:14:12 +000061 ($NEXT_TITLE ? $NEXT : '')
62 . ($UP_TITLE ? $UP : '')
63 . ($PREVIOUS_TITLE ? $PREVIOUS : '')
64 . $CONTENTS
65 . $INDEX
Fred Drake13210ed1998-03-17 06:28:05 +000066# . " $CUSTOM_BUTTONS"
Fred Drake64bdc241998-04-17 02:14:12 +000067 . "\n<br>\n"
68 . ($NEXT_TITLE ? "<b>Next:</b> $NEXT_TITLE\n" : '')
Fred Drake13210ed1998-03-17 06:28:05 +000069 . ($UP_TITLE ? "<b>Up:</b> $UP_TITLE\n" : '')
70 . ($PREVIOUS_TITLE ? "<b>Previous:</b> $PREVIOUS_TITLE\n" : '');
71}
72
Fred Drakebc7101d1998-03-06 21:18:55 +000073sub top_navigation_panel {
Fred Drake13210ed1998-03-17 06:28:05 +000074 "<div class=navigation>\n"
Fred Drake64bdc241998-04-17 02:14:12 +000075 . make_nav_panel()
76 . '<br><hr><p></div>';
Fred Drakebc7101d1998-03-06 21:18:55 +000077}
78
79sub bot_navigation_panel {
Fred Drake9d4b6c51998-04-11 05:21:14 +000080 "<p>\n<div class=navigation><hr>"
Fred Drake64bdc241998-04-17 02:14:12 +000081 . make_nav_panel()
82 . '</div>';
83}
84
85sub add_link {
86 # Returns a pair (iconic link, textual link)
87 my($icon, $current_file, @link) = @_;
88 my($dummy, $file, $title) = split($delim,
89 $toc_section_info{join(' ',@link)});
90 if ($title && ($file ne $current_file)) {
91 $title = purify($title);
92 $title = get_first_words($title, $WORDS_IN_NAVIGATION_PANEL_TITLES);
93 return (make_href($file, $icon), make_href($file, "$title"))
94 }
95 elsif ($icon eq $up_visible_mark && $EXTERNAL_UP_LINK) {
96 return (make_href($EXTERNAL_UP_LINK, $icon),
97 make_href($EXTERNAL_UP_LINK, "$EXTERNAL_UP_TITLE"))
98 }
99 elsif (($icon eq $previous_visible_mark
100 || $icon eq $previous_page_visible_mark)
101 && $EXTERNAL_PREV_LINK && $EXTERNAL_PREV_TITLE) {
102 return (make_href($EXTERNAL_PREV_LINK, $icon),
103 make_href($EXTERNAL_PREV_LINK, "$EXTERNAL_PREV_TITLE"))
104 }
105 elsif (($icon eq $next_visible_mark
106 || $icon eq $next_page_visible_mark)
107 && $EXTERNAL_DOWN_LINK && $EXTERNAL_DOWN_TITLE) {
108 return (make_href($EXTERNAL_DOWN_LINK, $icon),
109 make_href($EXTERNAL_DOWN_LINK, "$EXTERNAL_DOWN_TITLE"))
110 }
111 (&inactive_img($icon), "");
112}
113
114sub add_special_link {
115 my($icon, $file, $current_file) = @_;
116 (($file && ($file ne $current_file)) ? make_href($file, $icon) : undef)
117}
118
119sub img_tag {
120 local($icon) = @_;
121 my $alt;
122 my $align = " align=bottom ";
123
124 $alt = join('|', 'up', 'next_group', 'previous_group'
125 , 'next', 'previous', 'change_begin_right', 'change_begin'
126 , 'change_end_right', 'change_end', 'change_delete_right'
127 , 'change_delete', 'contents', 'index');
128
129 if ($icon =~ /(gif|png)$/) {
130 $used_icons{$icon} = 1;
131 if ($icon =~ /change_(begin|end|delete)_right/) { $align = ' ' };
132 my $nav_border = "$NAV_BORDER";
133 if ($icon =~ /($alt)/) {
134 $alt = $1;
135 }
136 else {
137 $nav_border = '1';
138 $alt = '[*]';
139 };
140 if ($LOCAL_ICONS) {
141 return join('', '<img ', $iconsizes{$1}, $align
142 ,'border=', $nav_border, ' alt="', $alt
143 ,'" src="', $icon, '">' );
144 }
145 return join('', '<img ', $iconsizes{$1}, $align
146 ,'border=', $nav_border, ' alt="', $alt, '"\n'
147 ,' src="', $ICONSERVER, "/$icon", '">' );
148 }
149 else {
150 return $icon;
151 }
Fred Drakebc7101d1998-03-06 21:18:55 +0000152}
153
154
Fred Drakebc7101d1998-03-06 21:18:55 +0000155sub gen_index_id {
156 # this is used to ensure common index key generation and a stable sort
Fred Drake235e6b11998-03-27 05:19:43 +0000157 my($str,$extra) = @_;
Fred Drake64bdc241998-04-17 02:14:12 +0000158 sprintf('%s###%s%010d', $str, $extra, ++$global{'max_id'});
Fred Drakebc7101d1998-03-06 21:18:55 +0000159}
160
Fred Drake13210ed1998-03-17 06:28:05 +0000161sub make_index_entry {
Fred Drake11916921998-04-02 22:30:57 +0000162 my($br_id,$str) = @_;
Fred Drake13210ed1998-03-17 06:28:05 +0000163 # If TITLE is not yet available (i.e the \index command is in the title of the
164 # current section), use $ref_before.
165 $TITLE = $ref_before unless $TITLE;
166 # Save the reference
167 $str = gen_index_id($str, '');
Fred Drake64bdc241998-04-17 02:14:12 +0000168 $index{$str} .= make_half_href("$CURRENT_FILE#$br_id");
Fred Drake13210ed1998-03-17 06:28:05 +0000169 "<a name=\"$br_id\">$anchor_invisible_mark<\/a>";
170}
Fred Drakebc7101d1998-03-06 21:18:55 +0000171
Fred Drake64bdc241998-04-17 02:14:12 +0000172
173sub insert_index{
174 my($mark,$datafile) = @_;
175 my $index = `$myrootdir/tools/buildindex.py $datafile`;
176 s/$mark/$index/;
177}
178
Fred Drake235e6b11998-03-27 05:19:43 +0000179sub add_idx{
Fred Drake5a525191998-04-02 22:39:05 +0000180 print "\nDoing the index ...";
Fred Drake235e6b11998-03-27 05:19:43 +0000181 close(IDXFILE);
Fred Drake64bdc241998-04-17 02:14:12 +0000182 insert_index($idx_mark, 'index.dat');
Fred Drake13210ed1998-03-17 06:28:05 +0000183}
Fred Drakebc7101d1998-03-06 21:18:55 +0000184
185
186$idx_module_mark = '<tex2html_idx_module_mark>';
187$idx_module_title = 'Module Index';
188
Fred Drake13210ed1998-03-17 06:28:05 +0000189sub add_module_idx{
Fred Drakebc7101d1998-03-06 21:18:55 +0000190 print "\nDoing the module index ...";
Fred Drake235e6b11998-03-27 05:19:43 +0000191 my $key;
Fred Drake64bdc241998-04-17 02:14:12 +0000192 open(MODIDXFILE, '>modindex.dat') || die "\n$!\n";
Fred Drake235e6b11998-03-27 05:19:43 +0000193 foreach $key (keys %Modules) {
194 # dump the line in the data file; just use a dummy seqno field
Fred Drake9d4b6c51998-04-11 05:21:14 +0000195 print MODIDXFILE "$Modules{$key}" . $IDXFILE_FIELD_SEP . "$key###\n";
Fred Drakebc7101d1998-03-06 21:18:55 +0000196 }
Fred Drake235e6b11998-03-27 05:19:43 +0000197 close(MODIDXFILE);
Fred Drake64bdc241998-04-17 02:14:12 +0000198 insert_index($idx_module_mark, 'modindex.dat');
Fred Drakebc7101d1998-03-06 21:18:55 +0000199}
200
Fred Drake235e6b11998-03-27 05:19:43 +0000201# replace both indexes as needed:
202sub add_idx_hook{
203 &add_idx if (/$idx_mark/);
204 &add_module_idx if (/$idx_module_mark/);
205}
Fred Drakebc7101d1998-03-06 21:18:55 +0000206
Fred Drakebc7101d1998-03-06 21:18:55 +0000207
208# In addition to the standard stuff, add label to allow named node files.
209sub do_cmd_tableofcontents {
210 local($_) = @_;
211 $TITLE = $toc_title;
212 $tocfile = $CURRENT_FILE;
Fred Drake64bdc241998-04-17 02:14:12 +0000213 my($closures,$reopens) = preserve_open_tags();
214 anchor_label('contents', $CURRENT_FILE, $_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000215 join('', "<BR>\n", $closures
Fred Drake64bdc241998-04-17 02:14:12 +0000216 , make_section_heading($toc_title, 'H2'), $toc_mark
Fred Drakebc7101d1998-03-06 21:18:55 +0000217 , $reopens, $_);
218}
219# In addition to the standard stuff, add label to allow named node files.
220sub do_cmd_listoffigures {
221 local($_) = @_;
222 $TITLE = $lof_title;
223 $loffile = $CURRENT_FILE;
Fred Drake64bdc241998-04-17 02:14:12 +0000224 my($closures,$reopens) = preserve_open_tags();
225 anchor_label('lof', $CURRENT_FILE, $_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000226 join('', "<BR>\n", $closures
Fred Drake64bdc241998-04-17 02:14:12 +0000227 , make_section_heading($lof_title, 'H2'), $lof_mark
Fred Drakebc7101d1998-03-06 21:18:55 +0000228 , $reopens, $_);
229}
230# In addition to the standard stuff, add label to allow named node files.
231sub do_cmd_listoftables {
232 local($_) = @_;
233 $TITLE = $lot_title;
234 $lotfile = $CURRENT_FILE;
Fred Drake64bdc241998-04-17 02:14:12 +0000235 my($closures,$reopens) = preserve_open_tags();
236 anchor_label('lot', $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($lot_title, 'H2'), $lot_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_textohtmlinfopage {
243 local($_) = @_;
244 if ($INFO) { #
Fred Drake64bdc241998-04-17 02:14:12 +0000245 anchor_label("about",$CURRENT_FILE,$_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000246 } #
247 ( ($INFO == 1)
248 ? join('', $close_all
249 , "<STRONG>$t_title</STRONG><P>\nThis document was generated using the\n"
250 , "<A HREF=\"$TEX2HTMLADDRESS\"><STRONG>LaTeX</STRONG>2<tt>HTML</tt></A>"
251 , " translator Version $TEX2HTMLVERSION\n"
252 , "<P>Copyright &#169; 1993, 1994, 1995, 1996, 1997,\n"
253 , "<A HREF=\"$AUTHORADDRESS\">Nikos Drakos</A>, \n"
254 , "Computer Based Learning Unit, University of Leeds.\n"
255 , "<P>The command line arguments were: <BR>\n "
256 , "<STRONG>latex2html</STRONG> <tt>$argv</tt>.\n"
257 , "<P>The translation was initiated by $address_data[0] on $address_data[1]"
258 , $open_all, $_)
259 : join('', $close_all, $INFO,"\n", $open_all, $_))
260}
261
262# $idx_mark will be replaced with the real index at the end
263sub do_cmd_textohtmlindex {
264 local($_) = @_;
265 $TITLE = $idx_title;
266 $idxfile = $CURRENT_FILE;
Fred Drake235e6b11998-03-27 05:19:43 +0000267 if (%index_labels) { make_index_labels(); }
268 if (($SHORT_INDEX) && (%index_segment)) { make_preindex(); }
Fred Drakebc7101d1998-03-06 21:18:55 +0000269 else { $preindex = ''; }
Fred Drake235e6b11998-03-27 05:19:43 +0000270 my $heading = make_section_heading($idx_title, 'h2') . $idx_mark;
Fred Drake11916921998-04-02 22:30:57 +0000271 my($pre,$post) = minimize_open_tags($heading);
Fred Drake235e6b11998-03-27 05:19:43 +0000272 anchor_label('genindex',$CURRENT_FILE,$_); # this is added
273 '<br>\n' . $pre . $_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000274}
275
276# $idx_module_mark will be replaced with the real index at the end
277sub do_cmd_textohtmlmoduleindex {
278 local($_) = @_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000279 $TITLE = $idx_module_title;
Fred Drake64bdc241998-04-17 02:14:12 +0000280 anchor_label("modindex",$CURRENT_FILE,$_);
Fred Drake235e6b11998-03-27 05:19:43 +0000281 '<p>' . make_section_heading($idx_module_title, "h2")
282 . $idx_module_mark . $_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000283}
284
285# The bibliography and the index should be treated as separate sections
286# in their own HTML files. The \bibliography{} command acts as a sectioning command
287# that has the desired effect. But when the bibliography is constructed
288# manually using the thebibliography environment, or when using the
289# theindex environment it is not possible to use the normal sectioning
290# mechanism. This subroutine inserts a \bibliography{} or a dummy
291# \textohtmlindex command just before the appropriate environments
292# to force sectioning.
293
294# XXX This *assumes* that if there are two {theindex} environments, the
295# first is the module index and the second is the standard index. This
296# is sufficient for the current Python documentation, but that's about
297# it.
298
299sub add_bbl_and_idx_dummy_commands {
Fred Drake11916921998-04-02 22:30:57 +0000300 my $id = $global{'max_id'};
Fred Drakebc7101d1998-03-06 21:18:55 +0000301
302 s/([\\]begin\s*$O\d+$C\s*thebibliography)/$bbl_cnt++; $1/eg;
303 s/([\\]begin\s*$O\d+$C\s*thebibliography)/$id++; "\\bibliography$O$id$C$O$id$C $1"/geo
304 #if ($bbl_cnt == 1)
305 ;
306 #}
Fred Drake11916921998-04-02 22:30:57 +0000307 #----------------------------------------------------------------------
308 # (FLD) This was added
309 my(@parts) = split(/\\begin\s*$O\d+$C\s*theindex/);
310 if (scalar(@parts) == 3) {
311 # Be careful to re-write the string in place, since $_ is *not*
312 # returned explicity; *** nasty side-effect dependency! ***
313 print "\nadd_bbl_and_idx_dummy_commands ==> adding module index";
314 my $rx = "([\\\\]begin\\s*$O\\d+$C\\s*theindex[\\s\\S]*)"
315 . "([\\\\]begin\\s*$O\\d+$C\\s*theindex)";
316 s/$rx/\\textohtmlmoduleindex \1 \\textohtmlindex \2/o;
317 }
318 else {
319 $global{'max_id'} = $id; # not sure why....
320 s/([\\]begin\s*$O\d+$C\s*theindex)/\\textohtmlindex $1/o;
321 s/[\\]printindex/\\textohtmlindex /o;
322 }
323 #----------------------------------------------------------------------
Fred Drake64bdc241998-04-17 02:14:12 +0000324 lib_add_bbl_and_idx_dummy_commands()
Fred Drake11916921998-04-02 22:30:57 +0000325 if defined(&lib_add_bbl_and_idx_dummy_commands);
Fred Drakebc7101d1998-03-06 21:18:55 +0000326}
327
328# The bibliographic references, the appendices, the lists of figures and tables
329# etc. must appear in the contents table at the same level as the outermost
330# sectioning command. This subroutine finds what is the outermost level and
331# sets the above to the same level;
332
Fred Drake13210ed1998-03-17 06:28:05 +0000333sub set_depth_levels {
334 # Sets $outermost_level
Fred Drake11916921998-04-02 22:30:57 +0000335 my $level;
Fred Drake13210ed1998-03-17 06:28:05 +0000336 #RRM: do not alter user-set value for $MAX_SPLIT_DEPTH
337 foreach $level ("part", "chapter", "section", "subsection",
338 "subsubsection", "paragraph") {
339 last if (($outermost_level) = /\\($level)$delimiter_rx/);
340 }
341 $level = ($outermost_level ? $section_commands{$outermost_level} :
342 do {$outermost_level = 'section'; 3;});
Fred Drakebc7101d1998-03-06 21:18:55 +0000343
Fred Drake13210ed1998-03-17 06:28:05 +0000344 #RRM: but calculate value for $MAX_SPLIT_DEPTH when a $REL_DEPTH was given
345 if ($REL_DEPTH && $MAX_SPLIT_DEPTH) {
346 $MAX_SPLIT_DEPTH = $level + $MAX_SPLIT_DEPTH;
347 } elsif (!($MAX_SPLIT_DEPTH)) { $MAX_SPLIT_DEPTH = 1 };
Fred Drakebc7101d1998-03-06 21:18:55 +0000348
Fred Drake64bdc241998-04-17 02:14:12 +0000349 %unnumbered_section_commands = ('tableofcontents' => $level,
350 'listoffigures' => $level,
351 'listoftables' => $level,
352 'bibliography' => $level,
353 'textohtmlindex' => $level,
354 'textohtmlmoduleindex' => $level);
355 $section_headings{'textohtmlmoduleindex'} = 'h1';
Fred Drakebc7101d1998-03-06 21:18:55 +0000356
Fred Drake64bdc241998-04-17 02:14:12 +0000357 %section_commands = (%unnumbered_section_commands,
358 %section_commands);
Fred Drake11916921998-04-02 22:30:57 +0000359
360 make_sections_rx();
Fred Drake13210ed1998-03-17 06:28:05 +0000361}
Fred Drakebc7101d1998-03-06 21:18:55 +0000362
363
364# Fix from Ross Moore for ']' in \item[...]; this can be removed once the next
Fred Drake235e6b11998-03-27 05:19:43 +0000365# patch to LaTeX2HTML is released and tested ... if the patch gets included.
366# Be very careful to keep this around, just in case things break again!
Fred Drakebc7101d1998-03-06 21:18:55 +0000367#
368sub protect_useritems {
369 local(*_) = @_;
Fred Drake11916921998-04-02 22:30:57 +0000370 local($preitems,$thisitem);
Fred Drakebc7101d1998-03-06 21:18:55 +0000371 while (/\\item\s*\[/) {
Fred Drake11916921998-04-02 22:30:57 +0000372 $preitems .= $`;
373 $_ = $';
Fred Drakebc7101d1998-03-06 21:18:55 +0000374 $thisitem = $&.'<<'.++$global{'max_id'}.'>>';
375 s/^(((($O|$OP)\d+($C|$CP)).*\3|<[^<>]*>|[^\]<]+)*)\]/$thisitem.=$1;''/e;
Fred Drake11916921998-04-02 22:30:57 +0000376 $preitems .= $thisitem . '<<' . $global{'max_id'} . '>>]';
377 s/^]//;
Fred Drakebc7101d1998-03-06 21:18:55 +0000378 }
379 $_ = $preitems . $_;
380}
381
Fred Drake1072e461998-04-12 02:16:34 +0000382# This changes the markup used for {verbatim} environments, and is the
383# best way I've found that ensures the <dl> goes one the outside of the
384# <pre>...</pre>.
385#
386# Note that this *must* be done in the init file, not the python.perl
387# style support file. The %declarations must be set before initialize()
388# is called in the main script.
389#
Fred Drake64bdc241998-04-17 02:14:12 +0000390%declarations = ('preform' => '<dl><dd><pre></pre></dl>',
Fred Drake1072e461998-04-12 02:16:34 +0000391 %declarations);
392
Fred Drakebc7101d1998-03-06 21:18:55 +00003931; # This must be the last line