blob: 4862fbd3a73858194c08c706b43473f40860a5d0 [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;
11
12$NUMBERED_FOOTNOTES = 1;
13
14# Python documentation uses section numbers to support references to match
15# in the printed and online versions.
16#
17$SHOW_SECTION_NUMBERS = 1;
18
19$ICONSERVER = '../icons';
20
21$CHILDLINE = "\n<p><hr>\n";
22$VERBOSITY = 0;
23
Fred Drakedb34a1e1998-03-10 23:02:57 +000024# Locate a file that's been "require"d. Assumes that the file name of interest
25# is unique within the set of loaded files, after directory names have been
26# stripped. Only the directory is returned.
27#
28sub find_my_file{
Fred Drake11916921998-04-02 22:30:57 +000029 my($myfile,$key,$tmp,$mydir) = (@_[0], '', '', '');
Fred Drakedb34a1e1998-03-10 23:02:57 +000030 foreach $key (keys %INC) {
31 $tmp = "$key";
32 $tmp =~ s|^.*/||o;
33 if ($tmp eq $myfile) {
Fred Drakedb34a1e1998-03-10 23:02:57 +000034 $mydir = $INC{$key};
35 }
36 }
37 $mydir =~ s|/[^/]*$||;
38 $mydir;
39}
Fred Drakebc7101d1998-03-06 21:18:55 +000040
Fred Drakec9f2c141998-03-11 12:08:21 +000041
Fred Drakedb34a1e1998-03-10 23:02:57 +000042# A little painful, but lets us clean up the top level directory a little,
43# and not be tied to the current directory (as far as I can tell).
44#
Fred Drakec9f2c141998-03-11 12:08:21 +000045use Cwd;
46use File::Basename;
47($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
48chop $mydir; # remove trailing '/'
49$mydir = getcwd() . "$dd$mydir"
50 unless $mydir =~ s|^/|/|;
Fred Drakedb34a1e1998-03-10 23:02:57 +000051$LATEX2HTMLSTYLES = "$mydir$envkey$LATEX2HTMLSTYLES";
Fred Drakebc7101d1998-03-06 21:18:55 +000052
Fred Drake235e6b11998-03-27 05:19:43 +000053($myrootname, $myrootdir, $myext) = fileparse($mydir, '\..*');
54chop $myrootdir;
55
Fred Drakebc7101d1998-03-06 21:18:55 +000056
Fred Drake13210ed1998-03-17 06:28:05 +000057sub make_nav_panel{
Fred Drake64bdc241998-04-17 02:14:12 +000058 ($NEXT_TITLE ? $NEXT : '')
59 . ($UP_TITLE ? $UP : '')
60 . ($PREVIOUS_TITLE ? $PREVIOUS : '')
61 . $CONTENTS
62 . $INDEX
Fred Drake13210ed1998-03-17 06:28:05 +000063# . " $CUSTOM_BUTTONS"
Fred Drake64bdc241998-04-17 02:14:12 +000064 . "\n<br>\n"
65 . ($NEXT_TITLE ? "<b>Next:</b> $NEXT_TITLE\n" : '')
Fred Drake13210ed1998-03-17 06:28:05 +000066 . ($UP_TITLE ? "<b>Up:</b> $UP_TITLE\n" : '')
67 . ($PREVIOUS_TITLE ? "<b>Previous:</b> $PREVIOUS_TITLE\n" : '');
68}
69
Fred Drakebc7101d1998-03-06 21:18:55 +000070sub top_navigation_panel {
Fred Drake13210ed1998-03-17 06:28:05 +000071 "<div class=navigation>\n"
Fred Drake64bdc241998-04-17 02:14:12 +000072 . make_nav_panel()
73 . '<br><hr><p></div>';
Fred Drakebc7101d1998-03-06 21:18:55 +000074}
75
76sub bot_navigation_panel {
Fred Drake9d4b6c51998-04-11 05:21:14 +000077 "<p>\n<div class=navigation><hr>"
Fred Drake64bdc241998-04-17 02:14:12 +000078 . make_nav_panel()
79 . '</div>';
80}
81
82sub add_link {
83 # Returns a pair (iconic link, textual link)
84 my($icon, $current_file, @link) = @_;
85 my($dummy, $file, $title) = split($delim,
86 $toc_section_info{join(' ',@link)});
87 if ($title && ($file ne $current_file)) {
88 $title = purify($title);
89 $title = get_first_words($title, $WORDS_IN_NAVIGATION_PANEL_TITLES);
90 return (make_href($file, $icon), make_href($file, "$title"))
91 }
92 elsif ($icon eq $up_visible_mark && $EXTERNAL_UP_LINK) {
93 return (make_href($EXTERNAL_UP_LINK, $icon),
94 make_href($EXTERNAL_UP_LINK, "$EXTERNAL_UP_TITLE"))
95 }
96 elsif (($icon eq $previous_visible_mark
97 || $icon eq $previous_page_visible_mark)
98 && $EXTERNAL_PREV_LINK && $EXTERNAL_PREV_TITLE) {
99 return (make_href($EXTERNAL_PREV_LINK, $icon),
100 make_href($EXTERNAL_PREV_LINK, "$EXTERNAL_PREV_TITLE"))
101 }
102 elsif (($icon eq $next_visible_mark
103 || $icon eq $next_page_visible_mark)
104 && $EXTERNAL_DOWN_LINK && $EXTERNAL_DOWN_TITLE) {
105 return (make_href($EXTERNAL_DOWN_LINK, $icon),
106 make_href($EXTERNAL_DOWN_LINK, "$EXTERNAL_DOWN_TITLE"))
107 }
108 (&inactive_img($icon), "");
109}
110
111sub add_special_link {
112 my($icon, $file, $current_file) = @_;
113 (($file && ($file ne $current_file)) ? make_href($file, $icon) : undef)
114}
115
116sub img_tag {
117 local($icon) = @_;
118 my $alt;
119 my $align = " align=bottom ";
120
121 $alt = join('|', 'up', 'next_group', 'previous_group'
122 , 'next', 'previous', 'change_begin_right', 'change_begin'
123 , 'change_end_right', 'change_end', 'change_delete_right'
124 , 'change_delete', 'contents', 'index');
125
126 if ($icon =~ /(gif|png)$/) {
127 $used_icons{$icon} = 1;
128 if ($icon =~ /change_(begin|end|delete)_right/) { $align = ' ' };
129 my $nav_border = "$NAV_BORDER";
130 if ($icon =~ /($alt)/) {
131 $alt = $1;
132 }
133 else {
134 $nav_border = '1';
135 $alt = '[*]';
136 };
137 if ($LOCAL_ICONS) {
138 return join('', '<img ', $iconsizes{$1}, $align
139 ,'border=', $nav_border, ' alt="', $alt
140 ,'" src="', $icon, '">' );
141 }
142 return join('', '<img ', $iconsizes{$1}, $align
143 ,'border=', $nav_border, ' alt="', $alt, '"\n'
144 ,' src="', $ICONSERVER, "/$icon", '">' );
145 }
146 else {
147 return $icon;
148 }
Fred Drakebc7101d1998-03-06 21:18:55 +0000149}
150
151
Fred Drakebc7101d1998-03-06 21:18:55 +0000152sub gen_index_id {
153 # this is used to ensure common index key generation and a stable sort
Fred Drake235e6b11998-03-27 05:19:43 +0000154 my($str,$extra) = @_;
Fred Drake64bdc241998-04-17 02:14:12 +0000155 sprintf('%s###%s%010d', $str, $extra, ++$global{'max_id'});
Fred Drakebc7101d1998-03-06 21:18:55 +0000156}
157
Fred Drake13210ed1998-03-17 06:28:05 +0000158sub make_index_entry {
Fred Drake11916921998-04-02 22:30:57 +0000159 my($br_id,$str) = @_;
Fred Drake13210ed1998-03-17 06:28:05 +0000160 # If TITLE is not yet available (i.e the \index command is in the title of the
161 # current section), use $ref_before.
162 $TITLE = $ref_before unless $TITLE;
163 # Save the reference
164 $str = gen_index_id($str, '');
Fred Drake64bdc241998-04-17 02:14:12 +0000165 $index{$str} .= make_half_href("$CURRENT_FILE#$br_id");
Fred Drake13210ed1998-03-17 06:28:05 +0000166 "<a name=\"$br_id\">$anchor_invisible_mark<\/a>";
167}
Fred Drakebc7101d1998-03-06 21:18:55 +0000168
Fred Drake64bdc241998-04-17 02:14:12 +0000169
170sub insert_index{
171 my($mark,$datafile) = @_;
172 my $index = `$myrootdir/tools/buildindex.py $datafile`;
173 s/$mark/$index/;
174}
175
Fred Drake235e6b11998-03-27 05:19:43 +0000176sub add_idx{
Fred Drake5a525191998-04-02 22:39:05 +0000177 print "\nDoing the index ...";
Fred Drake235e6b11998-03-27 05:19:43 +0000178 close(IDXFILE);
Fred Drake64bdc241998-04-17 02:14:12 +0000179 insert_index($idx_mark, 'index.dat');
Fred Drake13210ed1998-03-17 06:28:05 +0000180}
Fred Drakebc7101d1998-03-06 21:18:55 +0000181
182
183$idx_module_mark = '<tex2html_idx_module_mark>';
184$idx_module_title = 'Module Index';
185
Fred Drake13210ed1998-03-17 06:28:05 +0000186sub add_module_idx{
Fred Drakebc7101d1998-03-06 21:18:55 +0000187 print "\nDoing the module index ...";
Fred Drake235e6b11998-03-27 05:19:43 +0000188 my $key;
Fred Drake64bdc241998-04-17 02:14:12 +0000189 open(MODIDXFILE, '>modindex.dat') || die "\n$!\n";
Fred Drake235e6b11998-03-27 05:19:43 +0000190 foreach $key (keys %Modules) {
191 # dump the line in the data file; just use a dummy seqno field
Fred Drake9d4b6c51998-04-11 05:21:14 +0000192 print MODIDXFILE "$Modules{$key}" . $IDXFILE_FIELD_SEP . "$key###\n";
Fred Drakebc7101d1998-03-06 21:18:55 +0000193 }
Fred Drake235e6b11998-03-27 05:19:43 +0000194 close(MODIDXFILE);
Fred Drake64bdc241998-04-17 02:14:12 +0000195 insert_index($idx_module_mark, 'modindex.dat');
Fred Drakebc7101d1998-03-06 21:18:55 +0000196}
197
Fred Drake235e6b11998-03-27 05:19:43 +0000198# replace both indexes as needed:
199sub add_idx_hook{
200 &add_idx if (/$idx_mark/);
201 &add_module_idx if (/$idx_module_mark/);
202}
Fred Drakebc7101d1998-03-06 21:18:55 +0000203
Fred Drakebc7101d1998-03-06 21:18:55 +0000204
205# In addition to the standard stuff, add label to allow named node files.
206sub do_cmd_tableofcontents {
207 local($_) = @_;
208 $TITLE = $toc_title;
209 $tocfile = $CURRENT_FILE;
Fred Drake64bdc241998-04-17 02:14:12 +0000210 my($closures,$reopens) = preserve_open_tags();
211 anchor_label('contents', $CURRENT_FILE, $_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000212 join('', "<BR>\n", $closures
Fred Drake64bdc241998-04-17 02:14:12 +0000213 , make_section_heading($toc_title, 'H2'), $toc_mark
Fred Drakebc7101d1998-03-06 21:18:55 +0000214 , $reopens, $_);
215}
216# In addition to the standard stuff, add label to allow named node files.
217sub do_cmd_listoffigures {
218 local($_) = @_;
219 $TITLE = $lof_title;
220 $loffile = $CURRENT_FILE;
Fred Drake64bdc241998-04-17 02:14:12 +0000221 my($closures,$reopens) = preserve_open_tags();
222 anchor_label('lof', $CURRENT_FILE, $_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000223 join('', "<BR>\n", $closures
Fred Drake64bdc241998-04-17 02:14:12 +0000224 , make_section_heading($lof_title, 'H2'), $lof_mark
Fred Drakebc7101d1998-03-06 21:18:55 +0000225 , $reopens, $_);
226}
227# In addition to the standard stuff, add label to allow named node files.
228sub do_cmd_listoftables {
229 local($_) = @_;
230 $TITLE = $lot_title;
231 $lotfile = $CURRENT_FILE;
Fred Drake64bdc241998-04-17 02:14:12 +0000232 my($closures,$reopens) = preserve_open_tags();
233 anchor_label('lot', $CURRENT_FILE, $_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000234 join('', "<BR>\n", $closures
Fred Drake64bdc241998-04-17 02:14:12 +0000235 , make_section_heading($lot_title, 'H2'), $lot_mark
Fred Drakebc7101d1998-03-06 21:18:55 +0000236 , $reopens, $_);
237}
238# In addition to the standard stuff, add label to allow named node files.
239sub do_cmd_textohtmlinfopage {
240 local($_) = @_;
241 if ($INFO) { #
Fred Drake64bdc241998-04-17 02:14:12 +0000242 anchor_label("about",$CURRENT_FILE,$_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000243 } #
244 ( ($INFO == 1)
245 ? join('', $close_all
246 , "<STRONG>$t_title</STRONG><P>\nThis document was generated using the\n"
247 , "<A HREF=\"$TEX2HTMLADDRESS\"><STRONG>LaTeX</STRONG>2<tt>HTML</tt></A>"
248 , " translator Version $TEX2HTMLVERSION\n"
249 , "<P>Copyright &#169; 1993, 1994, 1995, 1996, 1997,\n"
250 , "<A HREF=\"$AUTHORADDRESS\">Nikos Drakos</A>, \n"
251 , "Computer Based Learning Unit, University of Leeds.\n"
252 , "<P>The command line arguments were: <BR>\n "
253 , "<STRONG>latex2html</STRONG> <tt>$argv</tt>.\n"
254 , "<P>The translation was initiated by $address_data[0] on $address_data[1]"
255 , $open_all, $_)
256 : join('', $close_all, $INFO,"\n", $open_all, $_))
257}
258
259# $idx_mark will be replaced with the real index at the end
260sub do_cmd_textohtmlindex {
261 local($_) = @_;
262 $TITLE = $idx_title;
263 $idxfile = $CURRENT_FILE;
Fred Drake235e6b11998-03-27 05:19:43 +0000264 if (%index_labels) { make_index_labels(); }
265 if (($SHORT_INDEX) && (%index_segment)) { make_preindex(); }
Fred Drakebc7101d1998-03-06 21:18:55 +0000266 else { $preindex = ''; }
Fred Drake235e6b11998-03-27 05:19:43 +0000267 my $heading = make_section_heading($idx_title, 'h2') . $idx_mark;
Fred Drake11916921998-04-02 22:30:57 +0000268 my($pre,$post) = minimize_open_tags($heading);
Fred Drake235e6b11998-03-27 05:19:43 +0000269 anchor_label('genindex',$CURRENT_FILE,$_); # this is added
270 '<br>\n' . $pre . $_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000271}
272
273# $idx_module_mark will be replaced with the real index at the end
274sub do_cmd_textohtmlmoduleindex {
275 local($_) = @_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000276 $TITLE = $idx_module_title;
Fred Drake64bdc241998-04-17 02:14:12 +0000277 anchor_label("modindex",$CURRENT_FILE,$_);
Fred Drake235e6b11998-03-27 05:19:43 +0000278 '<p>' . make_section_heading($idx_module_title, "h2")
279 . $idx_module_mark . $_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000280}
281
282# The bibliography and the index should be treated as separate sections
283# in their own HTML files. The \bibliography{} command acts as a sectioning command
284# that has the desired effect. But when the bibliography is constructed
285# manually using the thebibliography environment, or when using the
286# theindex environment it is not possible to use the normal sectioning
287# mechanism. This subroutine inserts a \bibliography{} or a dummy
288# \textohtmlindex command just before the appropriate environments
289# to force sectioning.
290
291# XXX This *assumes* that if there are two {theindex} environments, the
292# first is the module index and the second is the standard index. This
293# is sufficient for the current Python documentation, but that's about
294# it.
295
296sub add_bbl_and_idx_dummy_commands {
Fred Drake11916921998-04-02 22:30:57 +0000297 my $id = $global{'max_id'};
Fred Drakebc7101d1998-03-06 21:18:55 +0000298
299 s/([\\]begin\s*$O\d+$C\s*thebibliography)/$bbl_cnt++; $1/eg;
300 s/([\\]begin\s*$O\d+$C\s*thebibliography)/$id++; "\\bibliography$O$id$C$O$id$C $1"/geo
301 #if ($bbl_cnt == 1)
302 ;
303 #}
Fred Drake11916921998-04-02 22:30:57 +0000304 #----------------------------------------------------------------------
305 # (FLD) This was added
306 my(@parts) = split(/\\begin\s*$O\d+$C\s*theindex/);
307 if (scalar(@parts) == 3) {
308 # Be careful to re-write the string in place, since $_ is *not*
309 # returned explicity; *** nasty side-effect dependency! ***
310 print "\nadd_bbl_and_idx_dummy_commands ==> adding module index";
311 my $rx = "([\\\\]begin\\s*$O\\d+$C\\s*theindex[\\s\\S]*)"
312 . "([\\\\]begin\\s*$O\\d+$C\\s*theindex)";
313 s/$rx/\\textohtmlmoduleindex \1 \\textohtmlindex \2/o;
314 }
315 else {
316 $global{'max_id'} = $id; # not sure why....
317 s/([\\]begin\s*$O\d+$C\s*theindex)/\\textohtmlindex $1/o;
318 s/[\\]printindex/\\textohtmlindex /o;
319 }
320 #----------------------------------------------------------------------
Fred Drake64bdc241998-04-17 02:14:12 +0000321 lib_add_bbl_and_idx_dummy_commands()
Fred Drake11916921998-04-02 22:30:57 +0000322 if defined(&lib_add_bbl_and_idx_dummy_commands);
Fred Drakebc7101d1998-03-06 21:18:55 +0000323}
324
325# The bibliographic references, the appendices, the lists of figures and tables
326# etc. must appear in the contents table at the same level as the outermost
327# sectioning command. This subroutine finds what is the outermost level and
328# sets the above to the same level;
329
Fred Drake13210ed1998-03-17 06:28:05 +0000330sub set_depth_levels {
331 # Sets $outermost_level
Fred Drake11916921998-04-02 22:30:57 +0000332 my $level;
Fred Drake13210ed1998-03-17 06:28:05 +0000333 #RRM: do not alter user-set value for $MAX_SPLIT_DEPTH
334 foreach $level ("part", "chapter", "section", "subsection",
335 "subsubsection", "paragraph") {
336 last if (($outermost_level) = /\\($level)$delimiter_rx/);
337 }
338 $level = ($outermost_level ? $section_commands{$outermost_level} :
339 do {$outermost_level = 'section'; 3;});
Fred Drakebc7101d1998-03-06 21:18:55 +0000340
Fred Drake13210ed1998-03-17 06:28:05 +0000341 #RRM: but calculate value for $MAX_SPLIT_DEPTH when a $REL_DEPTH was given
342 if ($REL_DEPTH && $MAX_SPLIT_DEPTH) {
343 $MAX_SPLIT_DEPTH = $level + $MAX_SPLIT_DEPTH;
344 } elsif (!($MAX_SPLIT_DEPTH)) { $MAX_SPLIT_DEPTH = 1 };
Fred Drakebc7101d1998-03-06 21:18:55 +0000345
Fred Drake64bdc241998-04-17 02:14:12 +0000346 %unnumbered_section_commands = ('tableofcontents' => $level,
347 'listoffigures' => $level,
348 'listoftables' => $level,
349 'bibliography' => $level,
350 'textohtmlindex' => $level,
351 'textohtmlmoduleindex' => $level);
352 $section_headings{'textohtmlmoduleindex'} = 'h1';
Fred Drakebc7101d1998-03-06 21:18:55 +0000353
Fred Drake64bdc241998-04-17 02:14:12 +0000354 %section_commands = (%unnumbered_section_commands,
355 %section_commands);
Fred Drake11916921998-04-02 22:30:57 +0000356
357 make_sections_rx();
Fred Drake13210ed1998-03-17 06:28:05 +0000358}
Fred Drakebc7101d1998-03-06 21:18:55 +0000359
360
361# Fix from Ross Moore for ']' in \item[...]; this can be removed once the next
Fred Drake235e6b11998-03-27 05:19:43 +0000362# patch to LaTeX2HTML is released and tested ... if the patch gets included.
363# Be very careful to keep this around, just in case things break again!
Fred Drakebc7101d1998-03-06 21:18:55 +0000364#
365sub protect_useritems {
366 local(*_) = @_;
Fred Drake11916921998-04-02 22:30:57 +0000367 local($preitems,$thisitem);
Fred Drakebc7101d1998-03-06 21:18:55 +0000368 while (/\\item\s*\[/) {
Fred Drake11916921998-04-02 22:30:57 +0000369 $preitems .= $`;
370 $_ = $';
Fred Drakebc7101d1998-03-06 21:18:55 +0000371 $thisitem = $&.'<<'.++$global{'max_id'}.'>>';
372 s/^(((($O|$OP)\d+($C|$CP)).*\3|<[^<>]*>|[^\]<]+)*)\]/$thisitem.=$1;''/e;
Fred Drake11916921998-04-02 22:30:57 +0000373 $preitems .= $thisitem . '<<' . $global{'max_id'} . '>>]';
374 s/^]//;
Fred Drakebc7101d1998-03-06 21:18:55 +0000375 }
376 $_ = $preitems . $_;
377}
378
Fred Drake1072e461998-04-12 02:16:34 +0000379# This changes the markup used for {verbatim} environments, and is the
380# best way I've found that ensures the <dl> goes one the outside of the
381# <pre>...</pre>.
382#
383# Note that this *must* be done in the init file, not the python.perl
384# style support file. The %declarations must be set before initialize()
385# is called in the main script.
386#
Fred Drake64bdc241998-04-17 02:14:12 +0000387%declarations = ('preform' => '<dl><dd><pre></pre></dl>',
Fred Drake1072e461998-04-12 02:16:34 +0000388 %declarations);
389
Fred Drakebc7101d1998-03-06 21:18:55 +00003901; # This must be the last line