blob: 76b65ce17ec67c1258c1222a2504341b8cd0e20a [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
30$CHILDLINE = "\n<p><hr>\n";
31$VERBOSITY = 0;
Fred Drakebc7101d1998-03-06 21:18:55 +000032
Fred Drakec9f2c141998-03-11 12:08:21 +000033
Fred Drakedb34a1e1998-03-10 23:02:57 +000034# A little painful, but lets us clean up the top level directory a little,
35# and not be tied to the current directory (as far as I can tell).
36#
Fred Drakec9f2c141998-03-11 12:08:21 +000037use Cwd;
38use File::Basename;
39($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
40chop $mydir; # remove trailing '/'
41$mydir = getcwd() . "$dd$mydir"
42 unless $mydir =~ s|^/|/|;
Fred Drakedb34a1e1998-03-10 23:02:57 +000043$LATEX2HTMLSTYLES = "$mydir$envkey$LATEX2HTMLSTYLES";
Fred Drakeb3a3ed81998-07-24 22:17:34 +000044push (@INC, $mydir);
Fred Drakebc7101d1998-03-06 21:18:55 +000045
Fred Drake235e6b11998-03-27 05:19:43 +000046($myrootname, $myrootdir, $myext) = fileparse($mydir, '\..*');
47chop $myrootdir;
48
Fred Drakebc7101d1998-03-06 21:18:55 +000049
Fred Drakea4565b01998-05-15 17:14:17 +000050# Hackish way to get the appropriate paper-*/ directory into $TEXINPUTS;
51# pass in the paper size (a4 or letter) as the environment variable PAPER
52# to add the right directory. If not given, the current directory is
53# added instead for use with HOWTO processing.
54#
55if (defined $ENV{'PAPER'}) {
56 $mytexinputs = "$myrootdir${dd}paper-$ENV{'PAPER'}$envkey";
57}
58else {
59 $mytexinputs = getcwd() . $envkey;
60}
61$mytexinputs .= "$myrootdir${dd}texinputs";
62
63
64sub custom_driver_hook{
65 #
66 # This adds the directory of the main input file to $TEXINPUTS; it
67 # seems to be sufficiently general that it should be fine for HOWTO
68 # processing.
69 #
70 my $file = @_[0];
71 my($jobname,$dir,$ext) = fileparse($file, '\..*');
72 $dir = make_directory_absolute($dir);
73 $dir =~ s/$dd$//;
74 $TEXINPUTS = "$dir$envkey$mytexinputs";
75 print "\nadding $dir to \$TEXINPUTS\n";
76}
77
78
Fred Drake13210ed1998-03-17 06:28:05 +000079sub make_nav_panel{
Fred Drake64bdc241998-04-17 02:14:12 +000080 ($NEXT_TITLE ? $NEXT : '')
81 . ($UP_TITLE ? $UP : '')
82 . ($PREVIOUS_TITLE ? $PREVIOUS : '')
83 . $CONTENTS
84 . $INDEX
Fred Drake13210ed1998-03-17 06:28:05 +000085# . " $CUSTOM_BUTTONS"
Fred Drake64bdc241998-04-17 02:14:12 +000086 . "\n<br>\n"
87 . ($NEXT_TITLE ? "<b>Next:</b> $NEXT_TITLE\n" : '')
Fred Drake13210ed1998-03-17 06:28:05 +000088 . ($UP_TITLE ? "<b>Up:</b> $UP_TITLE\n" : '')
89 . ($PREVIOUS_TITLE ? "<b>Previous:</b> $PREVIOUS_TITLE\n" : '');
90}
91
Fred Drakebc7101d1998-03-06 21:18:55 +000092sub top_navigation_panel {
Fred Drake13210ed1998-03-17 06:28:05 +000093 "<div class=navigation>\n"
Fred Drake64bdc241998-04-17 02:14:12 +000094 . make_nav_panel()
95 . '<br><hr><p></div>';
Fred Drakebc7101d1998-03-06 21:18:55 +000096}
97
98sub bot_navigation_panel {
Fred Drake9d4b6c51998-04-11 05:21:14 +000099 "<p>\n<div class=navigation><hr>"
Fred Drake64bdc241998-04-17 02:14:12 +0000100 . make_nav_panel()
101 . '</div>';
102}
103
104sub add_link {
105 # Returns a pair (iconic link, textual link)
106 my($icon, $current_file, @link) = @_;
107 my($dummy, $file, $title) = split($delim,
108 $toc_section_info{join(' ',@link)});
109 if ($title && ($file ne $current_file)) {
110 $title = purify($title);
111 $title = get_first_words($title, $WORDS_IN_NAVIGATION_PANEL_TITLES);
112 return (make_href($file, $icon), make_href($file, "$title"))
113 }
114 elsif ($icon eq $up_visible_mark && $EXTERNAL_UP_LINK) {
115 return (make_href($EXTERNAL_UP_LINK, $icon),
116 make_href($EXTERNAL_UP_LINK, "$EXTERNAL_UP_TITLE"))
117 }
118 elsif (($icon eq $previous_visible_mark
119 || $icon eq $previous_page_visible_mark)
120 && $EXTERNAL_PREV_LINK && $EXTERNAL_PREV_TITLE) {
121 return (make_href($EXTERNAL_PREV_LINK, $icon),
122 make_href($EXTERNAL_PREV_LINK, "$EXTERNAL_PREV_TITLE"))
123 }
124 elsif (($icon eq $next_visible_mark
125 || $icon eq $next_page_visible_mark)
126 && $EXTERNAL_DOWN_LINK && $EXTERNAL_DOWN_TITLE) {
127 return (make_href($EXTERNAL_DOWN_LINK, $icon),
128 make_href($EXTERNAL_DOWN_LINK, "$EXTERNAL_DOWN_TITLE"))
129 }
130 (&inactive_img($icon), "");
131}
132
133sub add_special_link {
134 my($icon, $file, $current_file) = @_;
135 (($file && ($file ne $current_file)) ? make_href($file, $icon) : undef)
136}
137
138sub img_tag {
139 local($icon) = @_;
140 my $alt;
141 my $align = " align=bottom ";
142
143 $alt = join('|', 'up', 'next_group', 'previous_group'
144 , 'next', 'previous', 'change_begin_right', 'change_begin'
145 , 'change_end_right', 'change_end', 'change_delete_right'
146 , 'change_delete', 'contents', 'index');
147
148 if ($icon =~ /(gif|png)$/) {
149 $used_icons{$icon} = 1;
150 if ($icon =~ /change_(begin|end|delete)_right/) { $align = ' ' };
151 my $nav_border = "$NAV_BORDER";
152 if ($icon =~ /($alt)/) {
153 $alt = $1;
154 }
155 else {
156 $nav_border = '1';
157 $alt = '[*]';
158 };
159 if ($LOCAL_ICONS) {
160 return join('', '<img ', $iconsizes{$1}, $align
161 ,'border=', $nav_border, ' alt="', $alt
162 ,'" src="', $icon, '">' );
163 }
164 return join('', '<img ', $iconsizes{$1}, $align
165 ,'border=', $nav_border, ' alt="', $alt, '"\n'
166 ,' src="', $ICONSERVER, "/$icon", '">' );
167 }
168 else {
169 return $icon;
170 }
Fred Drakebc7101d1998-03-06 21:18:55 +0000171}
172
173
Fred Drakebc7101d1998-03-06 21:18:55 +0000174sub gen_index_id {
175 # this is used to ensure common index key generation and a stable sort
Fred Drake235e6b11998-03-27 05:19:43 +0000176 my($str,$extra) = @_;
Fred Drake64bdc241998-04-17 02:14:12 +0000177 sprintf('%s###%s%010d', $str, $extra, ++$global{'max_id'});
Fred Drakebc7101d1998-03-06 21:18:55 +0000178}
179
Fred Drake13210ed1998-03-17 06:28:05 +0000180sub make_index_entry {
Fred Drake11916921998-04-02 22:30:57 +0000181 my($br_id,$str) = @_;
Fred Drake13210ed1998-03-17 06:28:05 +0000182 # If TITLE is not yet available (i.e the \index command is in the title of the
183 # current section), use $ref_before.
184 $TITLE = $ref_before unless $TITLE;
185 # Save the reference
186 $str = gen_index_id($str, '');
Fred Drake64bdc241998-04-17 02:14:12 +0000187 $index{$str} .= make_half_href("$CURRENT_FILE#$br_id");
Fred Drake13210ed1998-03-17 06:28:05 +0000188 "<a name=\"$br_id\">$anchor_invisible_mark<\/a>";
189}
Fred Drakebc7101d1998-03-06 21:18:55 +0000190
Fred Drake64bdc241998-04-17 02:14:12 +0000191
192sub insert_index{
193 my($mark,$datafile) = @_;
194 my $index = `$myrootdir/tools/buildindex.py $datafile`;
195 s/$mark/$index/;
196}
197
Fred Drake235e6b11998-03-27 05:19:43 +0000198sub add_idx{
Fred Drake5a525191998-04-02 22:39:05 +0000199 print "\nDoing the index ...";
Fred Drake235e6b11998-03-27 05:19:43 +0000200 close(IDXFILE);
Fred Drake64bdc241998-04-17 02:14:12 +0000201 insert_index($idx_mark, 'index.dat');
Fred Drake13210ed1998-03-17 06:28:05 +0000202}
Fred Drakebc7101d1998-03-06 21:18:55 +0000203
204
205$idx_module_mark = '<tex2html_idx_module_mark>';
206$idx_module_title = 'Module Index';
207
Fred Drake13210ed1998-03-17 06:28:05 +0000208sub add_module_idx{
Fred Drakebc7101d1998-03-06 21:18:55 +0000209 print "\nDoing the module index ...";
Fred Drake235e6b11998-03-27 05:19:43 +0000210 my $key;
Fred Drake64bdc241998-04-17 02:14:12 +0000211 open(MODIDXFILE, '>modindex.dat') || die "\n$!\n";
Fred Drake235e6b11998-03-27 05:19:43 +0000212 foreach $key (keys %Modules) {
213 # dump the line in the data file; just use a dummy seqno field
Fred Drake9d4b6c51998-04-11 05:21:14 +0000214 print MODIDXFILE "$Modules{$key}" . $IDXFILE_FIELD_SEP . "$key###\n";
Fred Drakebc7101d1998-03-06 21:18:55 +0000215 }
Fred Drake235e6b11998-03-27 05:19:43 +0000216 close(MODIDXFILE);
Fred Drake64bdc241998-04-17 02:14:12 +0000217 insert_index($idx_module_mark, 'modindex.dat');
Fred Drakebc7101d1998-03-06 21:18:55 +0000218}
219
Fred Drake235e6b11998-03-27 05:19:43 +0000220# replace both indexes as needed:
221sub add_idx_hook{
Fred Drakeb3a3ed81998-07-24 22:17:34 +0000222 add_idx() if (/$idx_mark/);
223 add_module_idx() if (/$idx_module_mark/);
224 process_all_localmoduletables();
Fred Drake235e6b11998-03-27 05:19:43 +0000225}
Fred Drakebc7101d1998-03-06 21:18:55 +0000226
Fred Drakebc7101d1998-03-06 21:18:55 +0000227
228# In addition to the standard stuff, add label to allow named node files.
229sub do_cmd_tableofcontents {
230 local($_) = @_;
231 $TITLE = $toc_title;
232 $tocfile = $CURRENT_FILE;
Fred Drake64bdc241998-04-17 02:14:12 +0000233 my($closures,$reopens) = preserve_open_tags();
234 anchor_label('contents', $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($toc_title, 'H2'), $toc_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_listoffigures {
241 local($_) = @_;
242 $TITLE = $lof_title;
243 $loffile = $CURRENT_FILE;
Fred Drake64bdc241998-04-17 02:14:12 +0000244 my($closures,$reopens) = preserve_open_tags();
245 anchor_label('lof', $CURRENT_FILE, $_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000246 join('', "<BR>\n", $closures
Fred Drake64bdc241998-04-17 02:14:12 +0000247 , make_section_heading($lof_title, 'H2'), $lof_mark
Fred Drakebc7101d1998-03-06 21:18:55 +0000248 , $reopens, $_);
249}
250# In addition to the standard stuff, add label to allow named node files.
251sub do_cmd_listoftables {
252 local($_) = @_;
253 $TITLE = $lot_title;
254 $lotfile = $CURRENT_FILE;
Fred Drake64bdc241998-04-17 02:14:12 +0000255 my($closures,$reopens) = preserve_open_tags();
256 anchor_label('lot', $CURRENT_FILE, $_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000257 join('', "<BR>\n", $closures
Fred Drake64bdc241998-04-17 02:14:12 +0000258 , make_section_heading($lot_title, 'H2'), $lot_mark
Fred Drakebc7101d1998-03-06 21:18:55 +0000259 , $reopens, $_);
260}
261# In addition to the standard stuff, add label to allow named node files.
262sub do_cmd_textohtmlinfopage {
263 local($_) = @_;
264 if ($INFO) { #
Fred Drake64bdc241998-04-17 02:14:12 +0000265 anchor_label("about",$CURRENT_FILE,$_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000266 } #
267 ( ($INFO == 1)
268 ? join('', $close_all
269 , "<STRONG>$t_title</STRONG><P>\nThis document was generated using the\n"
270 , "<A HREF=\"$TEX2HTMLADDRESS\"><STRONG>LaTeX</STRONG>2<tt>HTML</tt></A>"
271 , " translator Version $TEX2HTMLVERSION\n"
272 , "<P>Copyright &#169; 1993, 1994, 1995, 1996, 1997,\n"
273 , "<A HREF=\"$AUTHORADDRESS\">Nikos Drakos</A>, \n"
274 , "Computer Based Learning Unit, University of Leeds.\n"
275 , "<P>The command line arguments were: <BR>\n "
276 , "<STRONG>latex2html</STRONG> <tt>$argv</tt>.\n"
277 , "<P>The translation was initiated by $address_data[0] on $address_data[1]"
278 , $open_all, $_)
279 : join('', $close_all, $INFO,"\n", $open_all, $_))
280}
281
282# $idx_mark will be replaced with the real index at the end
283sub do_cmd_textohtmlindex {
284 local($_) = @_;
285 $TITLE = $idx_title;
286 $idxfile = $CURRENT_FILE;
Fred Drake235e6b11998-03-27 05:19:43 +0000287 if (%index_labels) { make_index_labels(); }
288 if (($SHORT_INDEX) && (%index_segment)) { make_preindex(); }
Fred Drakebc7101d1998-03-06 21:18:55 +0000289 else { $preindex = ''; }
Fred Drake235e6b11998-03-27 05:19:43 +0000290 my $heading = make_section_heading($idx_title, 'h2') . $idx_mark;
Fred Drake11916921998-04-02 22:30:57 +0000291 my($pre,$post) = minimize_open_tags($heading);
Fred Drake235e6b11998-03-27 05:19:43 +0000292 anchor_label('genindex',$CURRENT_FILE,$_); # this is added
293 '<br>\n' . $pre . $_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000294}
295
296# $idx_module_mark will be replaced with the real index at the end
297sub do_cmd_textohtmlmoduleindex {
298 local($_) = @_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000299 $TITLE = $idx_module_title;
Fred Drake64bdc241998-04-17 02:14:12 +0000300 anchor_label("modindex",$CURRENT_FILE,$_);
Fred Drake235e6b11998-03-27 05:19:43 +0000301 '<p>' . make_section_heading($idx_module_title, "h2")
302 . $idx_module_mark . $_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000303}
304
305# The bibliography and the index should be treated as separate sections
306# in their own HTML files. The \bibliography{} command acts as a sectioning command
307# that has the desired effect. But when the bibliography is constructed
308# manually using the thebibliography environment, or when using the
309# theindex environment it is not possible to use the normal sectioning
310# mechanism. This subroutine inserts a \bibliography{} or a dummy
311# \textohtmlindex command just before the appropriate environments
312# to force sectioning.
313
314# XXX This *assumes* that if there are two {theindex} environments, the
315# first is the module index and the second is the standard index. This
316# is sufficient for the current Python documentation, but that's about
317# it.
318
319sub add_bbl_and_idx_dummy_commands {
Fred Drake11916921998-04-02 22:30:57 +0000320 my $id = $global{'max_id'};
Fred Drakebc7101d1998-03-06 21:18:55 +0000321
322 s/([\\]begin\s*$O\d+$C\s*thebibliography)/$bbl_cnt++; $1/eg;
323 s/([\\]begin\s*$O\d+$C\s*thebibliography)/$id++; "\\bibliography$O$id$C$O$id$C $1"/geo
324 #if ($bbl_cnt == 1)
325 ;
326 #}
Fred Drake11916921998-04-02 22:30:57 +0000327 #----------------------------------------------------------------------
328 # (FLD) This was added
329 my(@parts) = split(/\\begin\s*$O\d+$C\s*theindex/);
330 if (scalar(@parts) == 3) {
331 # Be careful to re-write the string in place, since $_ is *not*
332 # returned explicity; *** nasty side-effect dependency! ***
333 print "\nadd_bbl_and_idx_dummy_commands ==> adding module index";
334 my $rx = "([\\\\]begin\\s*$O\\d+$C\\s*theindex[\\s\\S]*)"
335 . "([\\\\]begin\\s*$O\\d+$C\\s*theindex)";
336 s/$rx/\\textohtmlmoduleindex \1 \\textohtmlindex \2/o;
337 }
338 else {
339 $global{'max_id'} = $id; # not sure why....
340 s/([\\]begin\s*$O\d+$C\s*theindex)/\\textohtmlindex $1/o;
341 s/[\\]printindex/\\textohtmlindex /o;
342 }
343 #----------------------------------------------------------------------
Fred Drake64bdc241998-04-17 02:14:12 +0000344 lib_add_bbl_and_idx_dummy_commands()
Fred Drake11916921998-04-02 22:30:57 +0000345 if defined(&lib_add_bbl_and_idx_dummy_commands);
Fred Drakebc7101d1998-03-06 21:18:55 +0000346}
347
348# The bibliographic references, the appendices, the lists of figures and tables
349# etc. must appear in the contents table at the same level as the outermost
350# sectioning command. This subroutine finds what is the outermost level and
351# sets the above to the same level;
352
Fred Drake13210ed1998-03-17 06:28:05 +0000353sub set_depth_levels {
354 # Sets $outermost_level
Fred Drake11916921998-04-02 22:30:57 +0000355 my $level;
Fred Drake13210ed1998-03-17 06:28:05 +0000356 #RRM: do not alter user-set value for $MAX_SPLIT_DEPTH
357 foreach $level ("part", "chapter", "section", "subsection",
358 "subsubsection", "paragraph") {
359 last if (($outermost_level) = /\\($level)$delimiter_rx/);
360 }
361 $level = ($outermost_level ? $section_commands{$outermost_level} :
362 do {$outermost_level = 'section'; 3;});
Fred Drakebc7101d1998-03-06 21:18:55 +0000363
Fred Drake13210ed1998-03-17 06:28:05 +0000364 #RRM: but calculate value for $MAX_SPLIT_DEPTH when a $REL_DEPTH was given
365 if ($REL_DEPTH && $MAX_SPLIT_DEPTH) {
366 $MAX_SPLIT_DEPTH = $level + $MAX_SPLIT_DEPTH;
367 } elsif (!($MAX_SPLIT_DEPTH)) { $MAX_SPLIT_DEPTH = 1 };
Fred Drakebc7101d1998-03-06 21:18:55 +0000368
Fred Drake64bdc241998-04-17 02:14:12 +0000369 %unnumbered_section_commands = ('tableofcontents' => $level,
370 'listoffigures' => $level,
371 'listoftables' => $level,
372 'bibliography' => $level,
373 'textohtmlindex' => $level,
374 'textohtmlmoduleindex' => $level);
375 $section_headings{'textohtmlmoduleindex'} = 'h1';
Fred Drakebc7101d1998-03-06 21:18:55 +0000376
Fred Drake64bdc241998-04-17 02:14:12 +0000377 %section_commands = (%unnumbered_section_commands,
378 %section_commands);
Fred Drake11916921998-04-02 22:30:57 +0000379
380 make_sections_rx();
Fred Drake13210ed1998-03-17 06:28:05 +0000381}
Fred Drakebc7101d1998-03-06 21:18:55 +0000382
383
384# Fix from Ross Moore for ']' in \item[...]; this can be removed once the next
Fred Drake235e6b11998-03-27 05:19:43 +0000385# patch to LaTeX2HTML is released and tested ... if the patch gets included.
386# Be very careful to keep this around, just in case things break again!
Fred Drakebc7101d1998-03-06 21:18:55 +0000387#
388sub protect_useritems {
389 local(*_) = @_;
Fred Drake11916921998-04-02 22:30:57 +0000390 local($preitems,$thisitem);
Fred Drakebc7101d1998-03-06 21:18:55 +0000391 while (/\\item\s*\[/) {
Fred Drake11916921998-04-02 22:30:57 +0000392 $preitems .= $`;
393 $_ = $';
Fred Drakebc7101d1998-03-06 21:18:55 +0000394 $thisitem = $&.'<<'.++$global{'max_id'}.'>>';
395 s/^(((($O|$OP)\d+($C|$CP)).*\3|<[^<>]*>|[^\]<]+)*)\]/$thisitem.=$1;''/e;
Fred Drake11916921998-04-02 22:30:57 +0000396 $preitems .= $thisitem . '<<' . $global{'max_id'} . '>>]';
397 s/^]//;
Fred Drakebc7101d1998-03-06 21:18:55 +0000398 }
399 $_ = $preitems . $_;
400}
401
Fred Drake1072e461998-04-12 02:16:34 +0000402# This changes the markup used for {verbatim} environments, and is the
403# best way I've found that ensures the <dl> goes one the outside of the
404# <pre>...</pre>.
405#
406# Note that this *must* be done in the init file, not the python.perl
407# style support file. The %declarations must be set before initialize()
408# is called in the main script.
409#
Fred Drake64bdc241998-04-17 02:14:12 +0000410%declarations = ('preform' => '<dl><dd><pre></pre></dl>',
Fred Drake1072e461998-04-12 02:16:34 +0000411 %declarations);
412
Fred Drakebc7101d1998-03-06 21:18:55 +00004131; # This must be the last line