blob: acf69dd4e3438ab12f05532dae22d64fb5d55610 [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;
24
Fred Drakedb34a1e1998-03-10 23:02:57 +000025# Locate a file that's been "require"d. Assumes that the file name of interest
26# is unique within the set of loaded files, after directory names have been
27# stripped. Only the directory is returned.
28#
29sub find_my_file{
Fred Drake11916921998-04-02 22:30:57 +000030 my($myfile,$key,$tmp,$mydir) = (@_[0], '', '', '');
Fred Drakedb34a1e1998-03-10 23:02:57 +000031 foreach $key (keys %INC) {
32 $tmp = "$key";
33 $tmp =~ s|^.*/||o;
34 if ($tmp eq $myfile) {
Fred Drakedb34a1e1998-03-10 23:02:57 +000035 $mydir = $INC{$key};
36 }
37 }
38 $mydir =~ s|/[^/]*$||;
39 $mydir;
40}
Fred Drakebc7101d1998-03-06 21:18:55 +000041
Fred Drakec9f2c141998-03-11 12:08:21 +000042
Fred Drakedb34a1e1998-03-10 23:02:57 +000043# A little painful, but lets us clean up the top level directory a little,
44# and not be tied to the current directory (as far as I can tell).
45#
Fred Drakec9f2c141998-03-11 12:08:21 +000046use Cwd;
47use File::Basename;
48($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
49chop $mydir; # remove trailing '/'
50$mydir = getcwd() . "$dd$mydir"
51 unless $mydir =~ s|^/|/|;
Fred Drakedb34a1e1998-03-10 23:02:57 +000052$LATEX2HTMLSTYLES = "$mydir$envkey$LATEX2HTMLSTYLES";
Fred Drakebc7101d1998-03-06 21:18:55 +000053
Fred Drake235e6b11998-03-27 05:19:43 +000054($myrootname, $myrootdir, $myext) = fileparse($mydir, '\..*');
55chop $myrootdir;
56
Fred Drakebc7101d1998-03-06 21:18:55 +000057
Fred Drake13210ed1998-03-17 06:28:05 +000058sub make_nav_panel{
Fred Drake64bdc241998-04-17 02:14:12 +000059 ($NEXT_TITLE ? $NEXT : '')
60 . ($UP_TITLE ? $UP : '')
61 . ($PREVIOUS_TITLE ? $PREVIOUS : '')
62 . $CONTENTS
63 . $INDEX
Fred Drake13210ed1998-03-17 06:28:05 +000064# . " $CUSTOM_BUTTONS"
Fred Drake64bdc241998-04-17 02:14:12 +000065 . "\n<br>\n"
66 . ($NEXT_TITLE ? "<b>Next:</b> $NEXT_TITLE\n" : '')
Fred Drake13210ed1998-03-17 06:28:05 +000067 . ($UP_TITLE ? "<b>Up:</b> $UP_TITLE\n" : '')
68 . ($PREVIOUS_TITLE ? "<b>Previous:</b> $PREVIOUS_TITLE\n" : '');
69}
70
Fred Drakebc7101d1998-03-06 21:18:55 +000071sub top_navigation_panel {
Fred Drake13210ed1998-03-17 06:28:05 +000072 "<div class=navigation>\n"
Fred Drake64bdc241998-04-17 02:14:12 +000073 . make_nav_panel()
74 . '<br><hr><p></div>';
Fred Drakebc7101d1998-03-06 21:18:55 +000075}
76
77sub bot_navigation_panel {
Fred Drake9d4b6c51998-04-11 05:21:14 +000078 "<p>\n<div class=navigation><hr>"
Fred Drake64bdc241998-04-17 02:14:12 +000079 . make_nav_panel()
80 . '</div>';
81}
82
83sub add_link {
84 # Returns a pair (iconic link, textual link)
85 my($icon, $current_file, @link) = @_;
86 my($dummy, $file, $title) = split($delim,
87 $toc_section_info{join(' ',@link)});
88 if ($title && ($file ne $current_file)) {
89 $title = purify($title);
90 $title = get_first_words($title, $WORDS_IN_NAVIGATION_PANEL_TITLES);
91 return (make_href($file, $icon), make_href($file, "$title"))
92 }
93 elsif ($icon eq $up_visible_mark && $EXTERNAL_UP_LINK) {
94 return (make_href($EXTERNAL_UP_LINK, $icon),
95 make_href($EXTERNAL_UP_LINK, "$EXTERNAL_UP_TITLE"))
96 }
97 elsif (($icon eq $previous_visible_mark
98 || $icon eq $previous_page_visible_mark)
99 && $EXTERNAL_PREV_LINK && $EXTERNAL_PREV_TITLE) {
100 return (make_href($EXTERNAL_PREV_LINK, $icon),
101 make_href($EXTERNAL_PREV_LINK, "$EXTERNAL_PREV_TITLE"))
102 }
103 elsif (($icon eq $next_visible_mark
104 || $icon eq $next_page_visible_mark)
105 && $EXTERNAL_DOWN_LINK && $EXTERNAL_DOWN_TITLE) {
106 return (make_href($EXTERNAL_DOWN_LINK, $icon),
107 make_href($EXTERNAL_DOWN_LINK, "$EXTERNAL_DOWN_TITLE"))
108 }
109 (&inactive_img($icon), "");
110}
111
112sub add_special_link {
113 my($icon, $file, $current_file) = @_;
114 (($file && ($file ne $current_file)) ? make_href($file, $icon) : undef)
115}
116
117sub img_tag {
118 local($icon) = @_;
119 my $alt;
120 my $align = " align=bottom ";
121
122 $alt = join('|', 'up', 'next_group', 'previous_group'
123 , 'next', 'previous', 'change_begin_right', 'change_begin'
124 , 'change_end_right', 'change_end', 'change_delete_right'
125 , 'change_delete', 'contents', 'index');
126
127 if ($icon =~ /(gif|png)$/) {
128 $used_icons{$icon} = 1;
129 if ($icon =~ /change_(begin|end|delete)_right/) { $align = ' ' };
130 my $nav_border = "$NAV_BORDER";
131 if ($icon =~ /($alt)/) {
132 $alt = $1;
133 }
134 else {
135 $nav_border = '1';
136 $alt = '[*]';
137 };
138 if ($LOCAL_ICONS) {
139 return join('', '<img ', $iconsizes{$1}, $align
140 ,'border=', $nav_border, ' alt="', $alt
141 ,'" src="', $icon, '">' );
142 }
143 return join('', '<img ', $iconsizes{$1}, $align
144 ,'border=', $nav_border, ' alt="', $alt, '"\n'
145 ,' src="', $ICONSERVER, "/$icon", '">' );
146 }
147 else {
148 return $icon;
149 }
Fred Drakebc7101d1998-03-06 21:18:55 +0000150}
151
152
Fred Drakebc7101d1998-03-06 21:18:55 +0000153sub gen_index_id {
154 # this is used to ensure common index key generation and a stable sort
Fred Drake235e6b11998-03-27 05:19:43 +0000155 my($str,$extra) = @_;
Fred Drake64bdc241998-04-17 02:14:12 +0000156 sprintf('%s###%s%010d', $str, $extra, ++$global{'max_id'});
Fred Drakebc7101d1998-03-06 21:18:55 +0000157}
158
Fred Drake13210ed1998-03-17 06:28:05 +0000159sub make_index_entry {
Fred Drake11916921998-04-02 22:30:57 +0000160 my($br_id,$str) = @_;
Fred Drake13210ed1998-03-17 06:28:05 +0000161 # If TITLE is not yet available (i.e the \index command is in the title of the
162 # current section), use $ref_before.
163 $TITLE = $ref_before unless $TITLE;
164 # Save the reference
165 $str = gen_index_id($str, '');
Fred Drake64bdc241998-04-17 02:14:12 +0000166 $index{$str} .= make_half_href("$CURRENT_FILE#$br_id");
Fred Drake13210ed1998-03-17 06:28:05 +0000167 "<a name=\"$br_id\">$anchor_invisible_mark<\/a>";
168}
Fred Drakebc7101d1998-03-06 21:18:55 +0000169
Fred Drake64bdc241998-04-17 02:14:12 +0000170
171sub insert_index{
172 my($mark,$datafile) = @_;
173 my $index = `$myrootdir/tools/buildindex.py $datafile`;
174 s/$mark/$index/;
175}
176
Fred Drake235e6b11998-03-27 05:19:43 +0000177sub add_idx{
Fred Drake5a525191998-04-02 22:39:05 +0000178 print "\nDoing the index ...";
Fred Drake235e6b11998-03-27 05:19:43 +0000179 close(IDXFILE);
Fred Drake64bdc241998-04-17 02:14:12 +0000180 insert_index($idx_mark, 'index.dat');
Fred Drake13210ed1998-03-17 06:28:05 +0000181}
Fred Drakebc7101d1998-03-06 21:18:55 +0000182
183
184$idx_module_mark = '<tex2html_idx_module_mark>';
185$idx_module_title = 'Module Index';
186
Fred Drake13210ed1998-03-17 06:28:05 +0000187sub add_module_idx{
Fred Drakebc7101d1998-03-06 21:18:55 +0000188 print "\nDoing the module index ...";
Fred Drake235e6b11998-03-27 05:19:43 +0000189 my $key;
Fred Drake64bdc241998-04-17 02:14:12 +0000190 open(MODIDXFILE, '>modindex.dat') || die "\n$!\n";
Fred Drake235e6b11998-03-27 05:19:43 +0000191 foreach $key (keys %Modules) {
192 # dump the line in the data file; just use a dummy seqno field
Fred Drake9d4b6c51998-04-11 05:21:14 +0000193 print MODIDXFILE "$Modules{$key}" . $IDXFILE_FIELD_SEP . "$key###\n";
Fred Drakebc7101d1998-03-06 21:18:55 +0000194 }
Fred Drake235e6b11998-03-27 05:19:43 +0000195 close(MODIDXFILE);
Fred Drake64bdc241998-04-17 02:14:12 +0000196 insert_index($idx_module_mark, 'modindex.dat');
Fred Drakebc7101d1998-03-06 21:18:55 +0000197}
198
Fred Drake235e6b11998-03-27 05:19:43 +0000199# replace both indexes as needed:
200sub add_idx_hook{
201 &add_idx if (/$idx_mark/);
202 &add_module_idx if (/$idx_module_mark/);
203}
Fred Drakebc7101d1998-03-06 21:18:55 +0000204
Fred Drakebc7101d1998-03-06 21:18:55 +0000205
206# In addition to the standard stuff, add label to allow named node files.
207sub do_cmd_tableofcontents {
208 local($_) = @_;
209 $TITLE = $toc_title;
210 $tocfile = $CURRENT_FILE;
Fred Drake64bdc241998-04-17 02:14:12 +0000211 my($closures,$reopens) = preserve_open_tags();
212 anchor_label('contents', $CURRENT_FILE, $_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000213 join('', "<BR>\n", $closures
Fred Drake64bdc241998-04-17 02:14:12 +0000214 , make_section_heading($toc_title, 'H2'), $toc_mark
Fred Drakebc7101d1998-03-06 21:18:55 +0000215 , $reopens, $_);
216}
217# In addition to the standard stuff, add label to allow named node files.
218sub do_cmd_listoffigures {
219 local($_) = @_;
220 $TITLE = $lof_title;
221 $loffile = $CURRENT_FILE;
Fred Drake64bdc241998-04-17 02:14:12 +0000222 my($closures,$reopens) = preserve_open_tags();
223 anchor_label('lof', $CURRENT_FILE, $_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000224 join('', "<BR>\n", $closures
Fred Drake64bdc241998-04-17 02:14:12 +0000225 , make_section_heading($lof_title, 'H2'), $lof_mark
Fred Drakebc7101d1998-03-06 21:18:55 +0000226 , $reopens, $_);
227}
228# In addition to the standard stuff, add label to allow named node files.
229sub do_cmd_listoftables {
230 local($_) = @_;
231 $TITLE = $lot_title;
232 $lotfile = $CURRENT_FILE;
Fred Drake64bdc241998-04-17 02:14:12 +0000233 my($closures,$reopens) = preserve_open_tags();
234 anchor_label('lot', $CURRENT_FILE, $_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000235 join('', "<BR>\n", $closures
Fred Drake64bdc241998-04-17 02:14:12 +0000236 , make_section_heading($lot_title, 'H2'), $lot_mark
Fred Drakebc7101d1998-03-06 21:18:55 +0000237 , $reopens, $_);
238}
239# In addition to the standard stuff, add label to allow named node files.
240sub do_cmd_textohtmlinfopage {
241 local($_) = @_;
242 if ($INFO) { #
Fred Drake64bdc241998-04-17 02:14:12 +0000243 anchor_label("about",$CURRENT_FILE,$_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000244 } #
245 ( ($INFO == 1)
246 ? join('', $close_all
247 , "<STRONG>$t_title</STRONG><P>\nThis document was generated using the\n"
248 , "<A HREF=\"$TEX2HTMLADDRESS\"><STRONG>LaTeX</STRONG>2<tt>HTML</tt></A>"
249 , " translator Version $TEX2HTMLVERSION\n"
250 , "<P>Copyright &#169; 1993, 1994, 1995, 1996, 1997,\n"
251 , "<A HREF=\"$AUTHORADDRESS\">Nikos Drakos</A>, \n"
252 , "Computer Based Learning Unit, University of Leeds.\n"
253 , "<P>The command line arguments were: <BR>\n "
254 , "<STRONG>latex2html</STRONG> <tt>$argv</tt>.\n"
255 , "<P>The translation was initiated by $address_data[0] on $address_data[1]"
256 , $open_all, $_)
257 : join('', $close_all, $INFO,"\n", $open_all, $_))
258}
259
260# $idx_mark will be replaced with the real index at the end
261sub do_cmd_textohtmlindex {
262 local($_) = @_;
263 $TITLE = $idx_title;
264 $idxfile = $CURRENT_FILE;
Fred Drake235e6b11998-03-27 05:19:43 +0000265 if (%index_labels) { make_index_labels(); }
266 if (($SHORT_INDEX) && (%index_segment)) { make_preindex(); }
Fred Drakebc7101d1998-03-06 21:18:55 +0000267 else { $preindex = ''; }
Fred Drake235e6b11998-03-27 05:19:43 +0000268 my $heading = make_section_heading($idx_title, 'h2') . $idx_mark;
Fred Drake11916921998-04-02 22:30:57 +0000269 my($pre,$post) = minimize_open_tags($heading);
Fred Drake235e6b11998-03-27 05:19:43 +0000270 anchor_label('genindex',$CURRENT_FILE,$_); # this is added
271 '<br>\n' . $pre . $_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000272}
273
274# $idx_module_mark will be replaced with the real index at the end
275sub do_cmd_textohtmlmoduleindex {
276 local($_) = @_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000277 $TITLE = $idx_module_title;
Fred Drake64bdc241998-04-17 02:14:12 +0000278 anchor_label("modindex",$CURRENT_FILE,$_);
Fred Drake235e6b11998-03-27 05:19:43 +0000279 '<p>' . make_section_heading($idx_module_title, "h2")
280 . $idx_module_mark . $_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000281}
282
283# The bibliography and the index should be treated as separate sections
284# in their own HTML files. The \bibliography{} command acts as a sectioning command
285# that has the desired effect. But when the bibliography is constructed
286# manually using the thebibliography environment, or when using the
287# theindex environment it is not possible to use the normal sectioning
288# mechanism. This subroutine inserts a \bibliography{} or a dummy
289# \textohtmlindex command just before the appropriate environments
290# to force sectioning.
291
292# XXX This *assumes* that if there are two {theindex} environments, the
293# first is the module index and the second is the standard index. This
294# is sufficient for the current Python documentation, but that's about
295# it.
296
297sub add_bbl_and_idx_dummy_commands {
Fred Drake11916921998-04-02 22:30:57 +0000298 my $id = $global{'max_id'};
Fred Drakebc7101d1998-03-06 21:18:55 +0000299
300 s/([\\]begin\s*$O\d+$C\s*thebibliography)/$bbl_cnt++; $1/eg;
301 s/([\\]begin\s*$O\d+$C\s*thebibliography)/$id++; "\\bibliography$O$id$C$O$id$C $1"/geo
302 #if ($bbl_cnt == 1)
303 ;
304 #}
Fred Drake11916921998-04-02 22:30:57 +0000305 #----------------------------------------------------------------------
306 # (FLD) This was added
307 my(@parts) = split(/\\begin\s*$O\d+$C\s*theindex/);
308 if (scalar(@parts) == 3) {
309 # Be careful to re-write the string in place, since $_ is *not*
310 # returned explicity; *** nasty side-effect dependency! ***
311 print "\nadd_bbl_and_idx_dummy_commands ==> adding module index";
312 my $rx = "([\\\\]begin\\s*$O\\d+$C\\s*theindex[\\s\\S]*)"
313 . "([\\\\]begin\\s*$O\\d+$C\\s*theindex)";
314 s/$rx/\\textohtmlmoduleindex \1 \\textohtmlindex \2/o;
315 }
316 else {
317 $global{'max_id'} = $id; # not sure why....
318 s/([\\]begin\s*$O\d+$C\s*theindex)/\\textohtmlindex $1/o;
319 s/[\\]printindex/\\textohtmlindex /o;
320 }
321 #----------------------------------------------------------------------
Fred Drake64bdc241998-04-17 02:14:12 +0000322 lib_add_bbl_and_idx_dummy_commands()
Fred Drake11916921998-04-02 22:30:57 +0000323 if defined(&lib_add_bbl_and_idx_dummy_commands);
Fred Drakebc7101d1998-03-06 21:18:55 +0000324}
325
326# The bibliographic references, the appendices, the lists of figures and tables
327# etc. must appear in the contents table at the same level as the outermost
328# sectioning command. This subroutine finds what is the outermost level and
329# sets the above to the same level;
330
Fred Drake13210ed1998-03-17 06:28:05 +0000331sub set_depth_levels {
332 # Sets $outermost_level
Fred Drake11916921998-04-02 22:30:57 +0000333 my $level;
Fred Drake13210ed1998-03-17 06:28:05 +0000334 #RRM: do not alter user-set value for $MAX_SPLIT_DEPTH
335 foreach $level ("part", "chapter", "section", "subsection",
336 "subsubsection", "paragraph") {
337 last if (($outermost_level) = /\\($level)$delimiter_rx/);
338 }
339 $level = ($outermost_level ? $section_commands{$outermost_level} :
340 do {$outermost_level = 'section'; 3;});
Fred Drakebc7101d1998-03-06 21:18:55 +0000341
Fred Drake13210ed1998-03-17 06:28:05 +0000342 #RRM: but calculate value for $MAX_SPLIT_DEPTH when a $REL_DEPTH was given
343 if ($REL_DEPTH && $MAX_SPLIT_DEPTH) {
344 $MAX_SPLIT_DEPTH = $level + $MAX_SPLIT_DEPTH;
345 } elsif (!($MAX_SPLIT_DEPTH)) { $MAX_SPLIT_DEPTH = 1 };
Fred Drakebc7101d1998-03-06 21:18:55 +0000346
Fred Drake64bdc241998-04-17 02:14:12 +0000347 %unnumbered_section_commands = ('tableofcontents' => $level,
348 'listoffigures' => $level,
349 'listoftables' => $level,
350 'bibliography' => $level,
351 'textohtmlindex' => $level,
352 'textohtmlmoduleindex' => $level);
353 $section_headings{'textohtmlmoduleindex'} = 'h1';
Fred Drakebc7101d1998-03-06 21:18:55 +0000354
Fred Drake64bdc241998-04-17 02:14:12 +0000355 %section_commands = (%unnumbered_section_commands,
356 %section_commands);
Fred Drake11916921998-04-02 22:30:57 +0000357
358 make_sections_rx();
Fred Drake13210ed1998-03-17 06:28:05 +0000359}
Fred Drakebc7101d1998-03-06 21:18:55 +0000360
361
362# Fix from Ross Moore for ']' in \item[...]; this can be removed once the next
Fred Drake235e6b11998-03-27 05:19:43 +0000363# patch to LaTeX2HTML is released and tested ... if the patch gets included.
364# Be very careful to keep this around, just in case things break again!
Fred Drakebc7101d1998-03-06 21:18:55 +0000365#
366sub protect_useritems {
367 local(*_) = @_;
Fred Drake11916921998-04-02 22:30:57 +0000368 local($preitems,$thisitem);
Fred Drakebc7101d1998-03-06 21:18:55 +0000369 while (/\\item\s*\[/) {
Fred Drake11916921998-04-02 22:30:57 +0000370 $preitems .= $`;
371 $_ = $';
Fred Drakebc7101d1998-03-06 21:18:55 +0000372 $thisitem = $&.'<<'.++$global{'max_id'}.'>>';
373 s/^(((($O|$OP)\d+($C|$CP)).*\3|<[^<>]*>|[^\]<]+)*)\]/$thisitem.=$1;''/e;
Fred Drake11916921998-04-02 22:30:57 +0000374 $preitems .= $thisitem . '<<' . $global{'max_id'} . '>>]';
375 s/^]//;
Fred Drakebc7101d1998-03-06 21:18:55 +0000376 }
377 $_ = $preitems . $_;
378}
379
Fred Drake1072e461998-04-12 02:16:34 +0000380# This changes the markup used for {verbatim} environments, and is the
381# best way I've found that ensures the <dl> goes one the outside of the
382# <pre>...</pre>.
383#
384# Note that this *must* be done in the init file, not the python.perl
385# style support file. The %declarations must be set before initialize()
386# is called in the main script.
387#
Fred Drake64bdc241998-04-17 02:14:12 +0000388%declarations = ('preform' => '<dl><dd><pre></pre></dl>',
Fred Drake1072e461998-04-12 02:16:34 +0000389 %declarations);
390
Fred Drakebc7101d1998-03-06 21:18:55 +00003911; # This must be the last line