blob: b551158287d29b788c7fc71d44100c1ed260555d [file] [log] [blame]
Fred Drake85d14c92000-07-31 17:53:45 +00001# LaTeX2HTML support base for use with Python documentation.
Fred Drake41814bc1998-05-11 18:23:35 +00002
3package main;
4
Fred Drake85d14c92000-07-31 17:53:45 +00005use L2hos;
6
Fred Drake28e7b4c1998-10-20 18:14:20 +00007$HTML_VERSION = 4.0;
8
Fred Drake6aa5d481998-08-11 03:14:50 +00009$MAX_LINK_DEPTH = 2;
Fred Draked7571651998-04-23 20:06:24 +000010$ADDRESS = '';
Fred Drakebc7101d1998-03-06 21:18:55 +000011
Fred Drakee194beb1998-05-19 19:38:49 +000012$NO_FOOTNODE = 1;
Fred Drakebc7101d1998-03-06 21:18:55 +000013$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';
Fred Drakef730fc32000-08-31 07:19:07 +000021$IMAGE_TYPE = 'gif';
Fred Drakebc7101d1998-03-06 21:18:55 +000022
Fred Drake6aa5d481998-08-11 03:14:50 +000023# Control where the navigation bars should show up:
24$TOP_NAVIGATION = 1;
25$BOTTOM_NAVIGATION = 1;
26$AUTO_NAVIGATION = 0;
27
Fred Drake191439a1999-09-22 19:50:51 +000028# these exactly match the python.org colors
Fred Drake16816272000-09-16 20:40:44 +000029$BODYTEXT = '';
Fred Drakebc7101d1998-03-06 21:18:55 +000030$CHILDLINE = "\n<p><hr>\n";
31$VERBOSITY = 0;
Fred Drakebc7101d1998-03-06 21:18:55 +000032
Fred Drake4d10b431998-08-07 20:51:58 +000033# default # of columns for the indexes
Fred Drakeaa3f9fb1998-08-07 19:52:37 +000034$INDEX_COLUMNS = 2;
Fred Drake2383f6d1999-03-02 16:00:37 +000035$MODULE_INDEX_COLUMNS = 4;
Fred Drakeaa3f9fb1998-08-07 19:52:37 +000036
Fred Drakec9f2c141998-03-11 12:08:21 +000037
Fred Drakedb34a1e1998-03-10 23:02:57 +000038# A little painful, but lets us clean up the top level directory a little,
Fred Drake85d14c92000-07-31 17:53:45 +000039# and not be tied to the current directory (as far as I can tell). Testing
40# an existing definition of $mydir is needed since it cannot be computed when
41# run under mkhowto with recent versions of LaTeX2HTML, since this file is
42# not read directly by LaTeX2HTML any more. mkhowto is required to prepend
43# the required definition at the top of the actual input file.
Fred Drakedb34a1e1998-03-10 23:02:57 +000044#
Fred Drake85d14c92000-07-31 17:53:45 +000045if (!defined $mydir) {
46 use Cwd;
47 use File::Basename;
48 ($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
49 chop $mydir; # remove trailing '/'
50 $mydir = getcwd() . "$dd$mydir"
51 unless $mydir =~ s|^/|/|;
52}
Fred Drakedb34a1e1998-03-10 23:02:57 +000053$LATEX2HTMLSTYLES = "$mydir$envkey$LATEX2HTMLSTYLES";
Fred Drakeb3a3ed81998-07-24 22:17:34 +000054push (@INC, $mydir);
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 Drakea4565b01998-05-15 17:14:17 +000060# Hackish way to get the appropriate paper-*/ directory into $TEXINPUTS;
61# pass in the paper size (a4 or letter) as the environment variable PAPER
62# to add the right directory. If not given, the current directory is
63# added instead for use with HOWTO processing.
64#
65if (defined $ENV{'PAPER'}) {
66 $mytexinputs = "$myrootdir${dd}paper-$ENV{'PAPER'}$envkey";
67}
68else {
69 $mytexinputs = getcwd() . $envkey;
70}
71$mytexinputs .= "$myrootdir${dd}texinputs";
72
73
Fred Drakeb35f2b71999-09-23 16:53:09 +000074# Change this variable to change the text added in "About this document...";
75# this should be an absolute pathname to get it right.
76#
77$ABOUT_FILE = "$myrootdir${dd}html${dd}stdabout.dat";
78
79
Fred Drake85d14c92000-07-31 17:53:45 +000080sub custom_driver_hook {
Fred Drakea4565b01998-05-15 17:14:17 +000081 #
82 # This adds the directory of the main input file to $TEXINPUTS; it
83 # seems to be sufficiently general that it should be fine for HOWTO
84 # processing.
85 #
86 my $file = @_[0];
Fred Drake85d14c92000-07-31 17:53:45 +000087 my($jobname, $dir, $ext) = fileparse($file, '\..*');
88 $dir = L2hos->Make_directory_absolute($dir);
Fred Drakea4565b01998-05-15 17:14:17 +000089 $dir =~ s/$dd$//;
90 $TEXINPUTS = "$dir$envkey$mytexinputs";
Fred Drake85d14c92000-07-31 17:53:45 +000091 print "\nAdding $dir to \$TEXINPUTS\n";
Fred Drake191439a1999-09-22 19:50:51 +000092}
93
Fred Drakea4565b01998-05-15 17:14:17 +000094
Fred Drake85d14c92000-07-31 17:53:45 +000095$CUSTOM_BUTTONS = '';
Fred Drake062bc6e1998-08-13 22:03:46 +000096
Fred Drake85d14c92000-07-31 17:53:45 +000097sub make_nav_sectref {
Fred Drakebeb27bf1999-02-16 17:22:32 +000098 my($label,$title) = @_;
99 if ($title) {
Fred Drakee15956b2000-04-03 04:51:13 +0000100 return ("<b class='navlabel'>$label:</b> "
101 . "<span class='sectref'>$title</span>\n");
Fred Drakebeb27bf1999-02-16 17:22:32 +0000102 }
103 return '';
104}
105
Fred Drake85d14c92000-07-31 17:53:45 +0000106sub make_my_icon {
107 my($name, $text) = @_;
108 my $iconserver = ($ICONSERVER eq '.') ? '' : "$ICONSERVER/";
109 return "<img src=\"$iconserver$name.$IMAGE_TYPE\" border=\"0\""
110 . " height=\"32\"\n alt=\"$text\" width=\"32\">";
111}
112
Fred Drakef730fc32000-08-31 07:19:07 +0000113$BLANK_ICON = make_my_icon('blank', '');
Fred Drake85d14c92000-07-31 17:53:45 +0000114
115@my_icons = ();
116$my_icons{'next_page_inactive'} = $BLANK_ICON;
117$my_icons{'previous_page_inactive'} = $BLANK_ICON;
118$my_icons{'up_page_inactive'} = $BLANK_ICON;
Fred Drakef730fc32000-08-31 07:19:07 +0000119$x = make_my_icon('next', 'Next Page');
Fred Drake85d14c92000-07-31 17:53:45 +0000120$my_icons{'next_page'} = $x;
121$my_icons{'next'} = $x;
Fred Drakef730fc32000-08-31 07:19:07 +0000122$x = make_my_icon('previous', 'Previous Page');
Fred Drake85d14c92000-07-31 17:53:45 +0000123$my_icons{'previous_page'} = $x;
124$my_icons{'previous'} = $x;
Fred Drakef730fc32000-08-31 07:19:07 +0000125$my_icons{'up'} = make_my_icon('up', 'Up One Level');
126$my_icons{'contents'} = make_my_icon('contents', 'Contents');
127$my_icons{'index'} = make_my_icon('index', 'Index');
128$my_icons{'modules'} = make_my_icon('modules', 'Module Index');
Fred Drake85d14c92000-07-31 17:53:45 +0000129
130
131sub use_my_icon {
132 my $s = @_[0];
133 $s =~ s/\<tex2html_([a-z_]+)_visible_mark\>/$my_icons{$1}/;
Fred Drakea0075441999-04-29 19:06:56 +0000134 return $s;
Fred Drake13210ed1998-03-17 06:28:05 +0000135}
136
Fred Drake85d14c92000-07-31 17:53:45 +0000137sub make_nav_panel {
138 my $s;
Fred Drakef730fc32000-08-31 07:19:07 +0000139 $NEXT = $NEXT_TITLE ? use_my_icon("$NEXT") : $BLANK_ICON;
140 $UP = $UP_TITLE ? use_my_icon("$UP") : $BLANK_ICON;
141 $PREVIOUS = $PREVIOUS_TITLE ? use_my_icon("$PREVIOUS") : $BLANK_ICON;
Fred Drake85d14c92000-07-31 17:53:45 +0000142 $CONTENTS = use_my_icon("$CONTENTS");
143 $INDEX = $INDEX ? use_my_icon("$INDEX") : $BLANK_ICON;
144 if (!$CUSTOM_BUTTONS) {
145 $CUSTOM_BUTTONS = $BLANK_ICON;
146 }
147 $s = ('<table align="center" width="100%" cellpadding="0" cellspacing="2">'
148 . "\n<tr>"
149 # left-hand side
Fred Drake85d14c92000-07-31 17:53:45 +0000150 . "\n<td>$PREVIOUS</td>"
Fred Drake4640e132000-07-31 20:13:23 +0000151 . "\n<td>$UP</td>"
152 . "\n<td>$NEXT</td>"
Fred Drake85d14c92000-07-31 17:53:45 +0000153 # title box
Fred Drakef730fc32000-08-31 07:19:07 +0000154 . "\n<td align=\"center\" width=\"100%\">$t_title</td>"
Fred Drake85d14c92000-07-31 17:53:45 +0000155 # right-hand side
156 . "\n<td>$CONTENTS</td>"
157 . "\n<td>$CUSTOM_BUTTONS</td>" # module index
158 . "\n<td>$INDEX</td>"
159 . "\n</tr></table>\n"
160 # textual navigation
Fred Drake4640e132000-07-31 20:13:23 +0000161 . make_nav_sectref("Previous", $PREVIOUS_TITLE)
Fred Drake85d14c92000-07-31 17:53:45 +0000162 . make_nav_sectref("Up", $UP_TITLE)
Fred Drake4640e132000-07-31 20:13:23 +0000163 . make_nav_sectref("Next", $NEXT_TITLE)
164 );
Fred Drake85d14c92000-07-31 17:53:45 +0000165 # remove these; they are unnecessary and cause errors from validation
166 $s =~ s/ NAME="tex2html\d+"\n */ /g;
167 return $s;
168}
169
170
Fred Drakebc7101d1998-03-06 21:18:55 +0000171sub top_navigation_panel {
Fred Drake85d14c92000-07-31 17:53:45 +0000172 return make_nav_panel()
173 . '<br><hr>';
Fred Drakebc7101d1998-03-06 21:18:55 +0000174}
175
176sub bot_navigation_panel {
Fred Drake85d14c92000-07-31 17:53:45 +0000177 return "<p><hr>"
178 . make_nav_panel();
Fred Drake64bdc241998-04-17 02:14:12 +0000179}
180
181sub add_link {
182 # Returns a pair (iconic link, textual link)
183 my($icon, $current_file, @link) = @_;
184 my($dummy, $file, $title) = split($delim,
Fred Drake28e7b4c1998-10-20 18:14:20 +0000185 $section_info{join(' ',@link)});
Fred Drake85d14c92000-07-31 17:53:45 +0000186 $icon =~ s/\<tex2html_([_a-z]+)_visible_mark\>/$my_icons{$1}/;
Fred Drake64bdc241998-04-17 02:14:12 +0000187 if ($title && ($file ne $current_file)) {
188 $title = purify($title);
189 $title = get_first_words($title, $WORDS_IN_NAVIGATION_PANEL_TITLES);
190 return (make_href($file, $icon), make_href($file, "$title"))
191 }
Fred Drake85d14c92000-07-31 17:53:45 +0000192 elsif ($icon eq $my_icons{"up"} && $EXTERNAL_UP_LINK) {
Fred Drake64bdc241998-04-17 02:14:12 +0000193 return (make_href($EXTERNAL_UP_LINK, $icon),
194 make_href($EXTERNAL_UP_LINK, "$EXTERNAL_UP_TITLE"))
195 }
Fred Drake85d14c92000-07-31 17:53:45 +0000196 elsif ($icon eq $my_icons{"previous"}
Fred Drake64bdc241998-04-17 02:14:12 +0000197 && $EXTERNAL_PREV_LINK && $EXTERNAL_PREV_TITLE) {
198 return (make_href($EXTERNAL_PREV_LINK, $icon),
199 make_href($EXTERNAL_PREV_LINK, "$EXTERNAL_PREV_TITLE"))
200 }
Fred Drake85d14c92000-07-31 17:53:45 +0000201 elsif ($icon eq $my_icons{"next"}
Fred Drake64bdc241998-04-17 02:14:12 +0000202 && $EXTERNAL_DOWN_LINK && $EXTERNAL_DOWN_TITLE) {
203 return (make_href($EXTERNAL_DOWN_LINK, $icon),
204 make_href($EXTERNAL_DOWN_LINK, "$EXTERNAL_DOWN_TITLE"))
205 }
Fred Drake85d14c92000-07-31 17:53:45 +0000206 return (&inactive_img($icon), "");
Fred Drake64bdc241998-04-17 02:14:12 +0000207}
208
209sub add_special_link {
210 my($icon, $file, $current_file) = @_;
Fred Drake85d14c92000-07-31 17:53:45 +0000211 $icon =~ s/\<tex2html_([_a-z]+)_visible_mark\>/$my_icons{$1}/;
212 return (($file && ($file ne $current_file))
213 ? make_href($file, $icon)
214 : undef)
Fred Drake64bdc241998-04-17 02:14:12 +0000215}
216
Fred Drake85d14c92000-07-31 17:53:45 +0000217# The img_tag() function seems only to be called with the parameter
218# 'anchor_invisible_mark', which we want to turn into ''. Since
219# replace_icon_marks() is the only interesting caller, and all it really
220# does is call img_tag(), we can just define the hook alternative to be
221# a no-op instead.
222#
223sub replace_icons_hook {}
Fred Drakebc7101d1998-03-06 21:18:55 +0000224
Fred Drake50cdd971999-02-19 23:04:59 +0000225sub do_cmd_arabic {
226 # get rid of that nasty <SPAN CLASS="arabic">...</SPAN>
Fred Drake85d14c92000-07-31 17:53:45 +0000227 my($ctr, $val, $id, $text) = &read_counter_value(@_[0]);
228 return ($val ? farabic($val) : "0") . $text;
Fred Drake50cdd971999-02-19 23:04:59 +0000229}
230
231
Fred Drakebc7101d1998-03-06 21:18:55 +0000232sub gen_index_id {
233 # this is used to ensure common index key generation and a stable sort
Fred Drake235e6b11998-03-27 05:19:43 +0000234 my($str,$extra) = @_;
Fred Drake64bdc241998-04-17 02:14:12 +0000235 sprintf('%s###%s%010d', $str, $extra, ++$global{'max_id'});
Fred Drakebc7101d1998-03-06 21:18:55 +0000236}
237
Fred Drake85d14c92000-07-31 17:53:45 +0000238sub insert_index {
Fred Drake2383f6d1999-03-02 16:00:37 +0000239 my($mark,$datafile,$columns,$letters,$prefix) = @_;
Fred Drake4d10b431998-08-07 20:51:58 +0000240 my $prog = "$myrootdir/tools/buildindex.py";
241 my $index;
242 if ($letters) {
243 $index = `$prog --columns $columns --letters $datafile`;
244 }
245 else {
246 $index = `$prog --columns $columns $datafile`;
247 }
Fred Drakec5681732000-09-12 20:13:04 +0000248 if (!s/$mark/$prefix$index/) {
249 print "\nCould not locate index mark: $mark";
250 }
Fred Drake64bdc241998-04-17 02:14:12 +0000251}
252
Fred Drake85d14c92000-07-31 17:53:45 +0000253sub add_idx {
Fred Drake9bbdce51999-01-19 16:30:10 +0000254 print "\nBuilding HTML for the index ...";
Fred Drake235e6b11998-03-27 05:19:43 +0000255 close(IDXFILE);
Fred Drake2383f6d1999-03-02 16:00:37 +0000256 insert_index($idx_mark, 'index.dat', $INDEX_COLUMNS, 1, '');
Fred Drake13210ed1998-03-17 06:28:05 +0000257}
Fred Drakebc7101d1998-03-06 21:18:55 +0000258
259
260$idx_module_mark = '<tex2html_idx_module_mark>';
261$idx_module_title = 'Module Index';
262
Fred Drake85d14c92000-07-31 17:53:45 +0000263sub add_module_idx {
Fred Drake9bbdce51999-01-19 16:30:10 +0000264 print "\nBuilding HTML for the module index ...";
Fred Drake235e6b11998-03-27 05:19:43 +0000265 my $key;
Fred Drake2383f6d1999-03-02 16:00:37 +0000266 my $first = 1;
267 my $prevplat = '';
268 my $allthesame = 1;
269 my $prefix = '';
270 foreach $key (keys %Modules) {
271 $key =~ s/<tt>([a-zA-Z0-9._]*)<\/tt>/\1/;
272 my $plat = "$ModulePlatforms{$key}";
273 $plat = ''
Fred Drake62cc3601999-03-04 18:41:17 +0000274 if ($plat eq $IGNORE_PLATFORM_ANNOTATION);
Fred Drake2383f6d1999-03-02 16:00:37 +0000275 if (!$first) {
276 $allthesame = 0
277 if ($prevplat ne $plat);
278 }
279 else { $first = 0; }
280 $prevplat = $plat;
281 }
Fred Drake64bdc241998-04-17 02:14:12 +0000282 open(MODIDXFILE, '>modindex.dat') || die "\n$!\n";
Fred Drake235e6b11998-03-27 05:19:43 +0000283 foreach $key (keys %Modules) {
284 # dump the line in the data file; just use a dummy seqno field
Fred Drake2383f6d1999-03-02 16:00:37 +0000285 my $nkey = $1;
286 my $moditem = "$Modules{$key}";
287 my $plat = '';
288 $key =~ s/<tt>([a-zA-Z0-9._]*)<\/tt>/\1/;
289 if ($ModulePlatforms{$key} && !$allthesame) {
Fred Drakee15956b2000-04-03 04:51:13 +0000290 $plat = (" <em>(<span class='platform'>$ModulePlatforms{$key}"
Fred Drakebb584d31999-03-25 22:18:30 +0000291 . '</span>)</em>');
Fred Drake2383f6d1999-03-02 16:00:37 +0000292 }
Fred Drakee15956b2000-04-03 04:51:13 +0000293 print MODIDXFILE $moditem . $IDXFILE_FIELD_SEP
294 . "<tt class='module'>$key</tt>$plat###\n";
Fred Drakebc7101d1998-03-06 21:18:55 +0000295 }
Fred Drake235e6b11998-03-27 05:19:43 +0000296 close(MODIDXFILE);
Fred Drake2383f6d1999-03-02 16:00:37 +0000297 if (!$allthesame) {
298 $prefix = <<PLAT_DISCUSS;
299
300
301<p> Some module names are followed by an annotation indicating what
302platform they are available on.</p>
303
304PLAT_DISCUSS
305 }
306 insert_index($idx_module_mark, 'modindex.dat', $MODULE_INDEX_COLUMNS, 0,
307 $prefix);
Fred Drakebc7101d1998-03-06 21:18:55 +0000308}
309
Fred Drake235e6b11998-03-27 05:19:43 +0000310# replace both indexes as needed:
Fred Drake85d14c92000-07-31 17:53:45 +0000311sub add_idx_hook {
Fred Drakeb3a3ed81998-07-24 22:17:34 +0000312 add_idx() if (/$idx_mark/);
Fred Drake2383f6d1999-03-02 16:00:37 +0000313 process_python_state();
Fred Drakec5681732000-09-12 20:13:04 +0000314 if ($MODULE_INDEX_FILE) {
315 local ($_);
316 open(MYFILE, "<$MODULE_INDEX_FILE");
317 sysread(MYFILE, $_, 1024*1024);
318 close(MYFILE);
319 add_module_idx();
320 open(MYFILE,">$MODULE_INDEX_FILE");
321 print MYFILE $_;
322 close(MYFILE);
323 }
Fred Drake235e6b11998-03-27 05:19:43 +0000324}
Fred Drakebc7101d1998-03-06 21:18:55 +0000325
Fred Drakebc7101d1998-03-06 21:18:55 +0000326
Fred Drake191439a1999-09-22 19:50:51 +0000327# In addition to the standard stuff, add label to allow named node files and
328# support suppression of the page complete (for HTML Help use).
Fred Drakebc7101d1998-03-06 21:18:55 +0000329sub do_cmd_tableofcontents {
330 local($_) = @_;
331 $TITLE = $toc_title;
332 $tocfile = $CURRENT_FILE;
Fred Drake64bdc241998-04-17 02:14:12 +0000333 my($closures,$reopens) = preserve_open_tags();
334 anchor_label('contents', $CURRENT_FILE, $_); # this is added
Fred Drakebeb27bf1999-02-16 17:22:32 +0000335 join('', "<BR>\n\\tableofchildlinks[off]", $closures
Fred Drake64bdc241998-04-17 02:14:12 +0000336 , make_section_heading($toc_title, 'H2'), $toc_mark
Fred Drakebc7101d1998-03-06 21:18:55 +0000337 , $reopens, $_);
338}
339# In addition to the standard stuff, add label to allow named node files.
340sub do_cmd_listoffigures {
341 local($_) = @_;
342 $TITLE = $lof_title;
343 $loffile = $CURRENT_FILE;
Fred Drake64bdc241998-04-17 02:14:12 +0000344 my($closures,$reopens) = preserve_open_tags();
345 anchor_label('lof', $CURRENT_FILE, $_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000346 join('', "<BR>\n", $closures
Fred Drake64bdc241998-04-17 02:14:12 +0000347 , make_section_heading($lof_title, 'H2'), $lof_mark
Fred Drakebc7101d1998-03-06 21:18:55 +0000348 , $reopens, $_);
349}
350# In addition to the standard stuff, add label to allow named node files.
351sub do_cmd_listoftables {
352 local($_) = @_;
353 $TITLE = $lot_title;
354 $lotfile = $CURRENT_FILE;
Fred Drake64bdc241998-04-17 02:14:12 +0000355 my($closures,$reopens) = preserve_open_tags();
356 anchor_label('lot', $CURRENT_FILE, $_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000357 join('', "<BR>\n", $closures
Fred Drake64bdc241998-04-17 02:14:12 +0000358 , make_section_heading($lot_title, 'H2'), $lot_mark
Fred Drakebc7101d1998-03-06 21:18:55 +0000359 , $reopens, $_);
360}
361# In addition to the standard stuff, add label to allow named node files.
362sub do_cmd_textohtmlinfopage {
363 local($_) = @_;
364 if ($INFO) { #
Fred Drake64bdc241998-04-17 02:14:12 +0000365 anchor_label("about",$CURRENT_FILE,$_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000366 } #
Fred Drake15796f71998-11-30 19:25:47 +0000367 my $the_version = ''; # and the rest is
368 if ($t_date) { # mostly ours
369 $the_version = ",\n$t_date";
370 if ($PYTHON_VERSION) {
371 $the_version .= ", Release $PYTHON_VERSION";
372 }
373 }
374 $_ = (($INFO == 1)
Fred Drakeb35f2b71999-09-23 16:53:09 +0000375 ? join('',
376 $close_all,
377 "<strong>$t_title</strong>$the_version\n",
378 `cat $ABOUT_FILE`,
379 $open_all, $_)
380 : join('', $close_all, $INFO,"\n", $open_all, $_));
Fred Drake15796f71998-11-30 19:25:47 +0000381 $_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000382}
383
384# $idx_mark will be replaced with the real index at the end
385sub do_cmd_textohtmlindex {
386 local($_) = @_;
387 $TITLE = $idx_title;
388 $idxfile = $CURRENT_FILE;
Fred Drake235e6b11998-03-27 05:19:43 +0000389 if (%index_labels) { make_index_labels(); }
390 if (($SHORT_INDEX) && (%index_segment)) { make_preindex(); }
Fred Drakebc7101d1998-03-06 21:18:55 +0000391 else { $preindex = ''; }
Fred Drake235e6b11998-03-27 05:19:43 +0000392 my $heading = make_section_heading($idx_title, 'h2') . $idx_mark;
Fred Drake11916921998-04-02 22:30:57 +0000393 my($pre,$post) = minimize_open_tags($heading);
Fred Drake235e6b11998-03-27 05:19:43 +0000394 anchor_label('genindex',$CURRENT_FILE,$_); # this is added
Fred Drakec5681732000-09-12 20:13:04 +0000395 return "<br>\n" . $pre . $_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000396}
397
Fred Drakec5681732000-09-12 20:13:04 +0000398$MODULE_INDEX_FILE = '';
399
Fred Drakebc7101d1998-03-06 21:18:55 +0000400# $idx_module_mark will be replaced with the real index at the end
401sub do_cmd_textohtmlmoduleindex {
402 local($_) = @_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000403 $TITLE = $idx_module_title;
Fred Drakec5681732000-09-12 20:13:04 +0000404 anchor_label('modindex', $CURRENT_FILE, $_);
405 $MODULE_INDEX_FILE = "$CURRENT_FILE";
406 $_ = ('<p>' . make_section_heading($idx_module_title, 'h2')
407 . $idx_module_mark . $_);
408 return $_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000409}
410
Fred Drakec5681732000-09-12 20:13:04 +0000411# The bibliography and the index should be treated as separate
412# sections in their own HTML files. The \bibliography{} command acts
413# as a sectioning command that has the desired effect. But when the
414# bibliography is constructed manually using the thebibliography
415# environment, or when using the theindex environment it is not
416# possible to use the normal sectioning mechanism. This subroutine
417# inserts a \bibliography{} or a dummy \textohtmlindex command just
418# before the appropriate environments to force sectioning.
Fred Drakebc7101d1998-03-06 21:18:55 +0000419
Fred Drakec5681732000-09-12 20:13:04 +0000420# XXX This *assumes* that if there are two {theindex} environments,
421# the first is the module index and the second is the standard
422# index. This is sufficient for the current Python documentation,
423# but that's about it.
Fred Drakebc7101d1998-03-06 21:18:55 +0000424
425sub add_bbl_and_idx_dummy_commands {
Fred Drake11916921998-04-02 22:30:57 +0000426 my $id = $global{'max_id'};
Fred Drakebc7101d1998-03-06 21:18:55 +0000427
428 s/([\\]begin\s*$O\d+$C\s*thebibliography)/$bbl_cnt++; $1/eg;
Fred Drake191439a1999-09-22 19:50:51 +0000429 s/([\\]begin\s*$O\d+$C\s*thebibliography)/$id++; "\\bibliography$O$id$C$O$id$C $1"/geo;
Fred Drake85d14c92000-07-31 17:53:45 +0000430 my(@parts) = split(/\\begin\s*$O\d+$C\s*theindex/);
431 if (scalar(@parts) == 3) {
432 # Be careful to re-write the string in place, since $_ is *not*
433 # returned explicity; *** nasty side-effect dependency! ***
434 print "\nadd_bbl_and_idx_dummy_commands ==> adding module index";
435 my $rx = "([\\\\]begin\\s*$O\\d+$C\\s*theindex[\\s\\S]*)"
436 . "([\\\\]begin\\s*$O\\d+$C\\s*theindex)";
437 s/$rx/\\textohtmlmoduleindex \1 \\textohtmlindex \2/o;
438 # Add a button to the navigation areas:
Fred Drakeaaa23852000-09-14 22:20:41 +0000439 $CUSTOM_BUTTONS .= ('<a href="modindex.html" title="Module Index">'
440 . $my_icons{'modules'}
441 . '</a>');
Fred Drake11916921998-04-02 22:30:57 +0000442 }
443 else {
Fred Drake85d14c92000-07-31 17:53:45 +0000444 $CUSTOM_BUTTONS .= $BLANK_ICON;
445 $global{'max_id'} = $id; # not sure why....
446 s/([\\]begin\s*$O\d+$C\s*theindex)/\\textohtmlindex $1/o;
Fred Drake191439a1999-09-22 19:50:51 +0000447 s/[\\]printindex/\\textohtmlindex /o;
448 }
Fred Drake11916921998-04-02 22:30:57 +0000449 #----------------------------------------------------------------------
Fred Drake64bdc241998-04-17 02:14:12 +0000450 lib_add_bbl_and_idx_dummy_commands()
Fred Drake11916921998-04-02 22:30:57 +0000451 if defined(&lib_add_bbl_and_idx_dummy_commands);
Fred Drakebc7101d1998-03-06 21:18:55 +0000452}
453
Fred Drakec5681732000-09-12 20:13:04 +0000454# The bibliographic references, the appendices, the lists of figures
455# and tables etc. must appear in the contents table at the same level
456# as the outermost sectioning command. This subroutine finds what is
457# the outermost level and sets the above to the same level;
Fred Drakebc7101d1998-03-06 21:18:55 +0000458
Fred Drake13210ed1998-03-17 06:28:05 +0000459sub set_depth_levels {
460 # Sets $outermost_level
Fred Drake11916921998-04-02 22:30:57 +0000461 my $level;
Fred Drake13210ed1998-03-17 06:28:05 +0000462 #RRM: do not alter user-set value for $MAX_SPLIT_DEPTH
463 foreach $level ("part", "chapter", "section", "subsection",
464 "subsubsection", "paragraph") {
465 last if (($outermost_level) = /\\($level)$delimiter_rx/);
466 }
467 $level = ($outermost_level ? $section_commands{$outermost_level} :
468 do {$outermost_level = 'section'; 3;});
Fred Drakebc7101d1998-03-06 21:18:55 +0000469
Fred Drake13210ed1998-03-17 06:28:05 +0000470 #RRM: but calculate value for $MAX_SPLIT_DEPTH when a $REL_DEPTH was given
471 if ($REL_DEPTH && $MAX_SPLIT_DEPTH) {
472 $MAX_SPLIT_DEPTH = $level + $MAX_SPLIT_DEPTH;
473 } elsif (!($MAX_SPLIT_DEPTH)) { $MAX_SPLIT_DEPTH = 1 };
Fred Drakebc7101d1998-03-06 21:18:55 +0000474
Fred Drake64bdc241998-04-17 02:14:12 +0000475 %unnumbered_section_commands = ('tableofcontents' => $level,
476 'listoffigures' => $level,
477 'listoftables' => $level,
478 'bibliography' => $level,
479 'textohtmlindex' => $level,
480 'textohtmlmoduleindex' => $level);
481 $section_headings{'textohtmlmoduleindex'} = 'h1';
Fred Drakebc7101d1998-03-06 21:18:55 +0000482
Fred Drake64bdc241998-04-17 02:14:12 +0000483 %section_commands = (%unnumbered_section_commands,
484 %section_commands);
Fred Drake11916921998-04-02 22:30:57 +0000485
486 make_sections_rx();
Fred Drake13210ed1998-03-17 06:28:05 +0000487}
Fred Drakebc7101d1998-03-06 21:18:55 +0000488
489
Fred Drake1072e461998-04-12 02:16:34 +0000490# This changes the markup used for {verbatim} environments, and is the
Fred Drake95474f91999-02-09 18:45:50 +0000491# best way I've found that ensures the <dl> goes on the outside of the
Fred Drake1072e461998-04-12 02:16:34 +0000492# <pre>...</pre>.
493#
494# Note that this *must* be done in the init file, not the python.perl
Fred Drakec5681732000-09-12 20:13:04 +0000495# style support file. The %declarations must be set before
496# initialize() is called in the main LaTeX2HTML script (which happens
497# before style files are loaded).
Fred Drake1072e461998-04-12 02:16:34 +0000498#
Fred Drakee15956b2000-04-03 04:51:13 +0000499%declarations = ('preform' => '<dl><dd><pre class="verbatim"></pre></dl>',
Fred Drake1072e461998-04-12 02:16:34 +0000500 %declarations);
501
Fred Drakee15956b2000-04-03 04:51:13 +0000502
Fred Drakec5681732000-09-12 20:13:04 +0000503# This is added to get rid of the long comment that follows the
504# doctype declaration; MSIE5 on NT4 SP4 barfs on it and drops the
505# content of the page.
Fred Drakee15956b2000-04-03 04:51:13 +0000506sub make_head_and_body {
Fred Drake85d14c92000-07-31 17:53:45 +0000507 my($title, $body) = @_;
Fred Drake16816272000-09-16 20:40:44 +0000508 $body = " $body" unless ($body eq '');
Fred Drake85d14c92000-07-31 17:53:45 +0000509 my $DTDcomment = '';
510 my($version, $isolanguage) = ($HTML_VERSION, 'EN');
511 my %isolanguages = ( 'english', 'EN' , 'USenglish', 'EN.US'
512 , 'original', 'EN' , 'german' , 'DE'
513 , 'austrian', 'DE.AT', 'french' , 'FR'
514 , 'spanish', 'ES');
Fred Drakee15956b2000-04-03 04:51:13 +0000515 $isolanguage = $isolanguages{$default_language};
516 $isolanguage = 'EN' unless $isolanguage;
517 $title = &purify($title,1);
518 eval("\$title = ". $default_title ) unless ($title);
519
520 # allow user-modification of the <TITLE> tag; thanks Dan Young
521 if (defined &custom_TITLE_hook) {
522 $title = &custom_TITLE_hook($title, $toc_sec_title);
523 }
524
525 if ($DOCTYPE =~ /\/\/[\w\.]+\s*$/) { # language spec included
526 $DTDcomment = "<!DOCTYPE html PUBLIC \"$DOCTYPE\">\n";
527 } else {
528 $DTDcomment = "<!DOCTYPE html PUBLIC \"$DOCTYPE//"
529 . ($ISO_LANGUAGE ? $ISO_LANGUAGE : $isolanguage) . "\">\n";
530 }
531
532 $STYLESHEET = $FILE.".css" unless $STYLESHEET;
533 if (!$charset && $CHARSET) { $charset = $CHARSET; $charset =~ s/_/\-/go; }
534
535 join('', ($DOCTYPE ? $DTDcomment : '' )
536 ,"<html>\n<head>\n<title>", $title, "</title>\n"
537 , &meta_information($title)
538 , ($CHARSET && $HTML_VERSION ge "2.1" ?
539 "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=$charset\">\n"
540 : "" )
541 , ($BASE ? "<base href=\"$BASE\">\n" : "" )
542 , "<link rel=\"STYLESHEET\" href=\"$STYLESHEET\">"
543 , $more_links_mark
Fred Drake16816272000-09-16 20:40:44 +0000544 , "\n</head>\n<body$body>");
Fred Drakee15956b2000-04-03 04:51:13 +0000545}
546
Fred Drakebc7101d1998-03-06 21:18:55 +00005471; # This must be the last line