blob: 147be516f71ddc1b757f39331878f9d5e2140d6e [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
29$BODYTEXT = ('bgcolor="#ffffff" text="#000000"'
30 . ' link="#0000bb" vlink="#551a8b" alink="#ff0000"');
Fred Drakebc7101d1998-03-06 21:18:55 +000031$CHILDLINE = "\n<p><hr>\n";
32$VERBOSITY = 0;
Fred Drakebc7101d1998-03-06 21:18:55 +000033
Fred Drake4d10b431998-08-07 20:51:58 +000034# default # of columns for the indexes
Fred Drakeaa3f9fb1998-08-07 19:52:37 +000035$INDEX_COLUMNS = 2;
Fred Drake2383f6d1999-03-02 16:00:37 +000036$MODULE_INDEX_COLUMNS = 4;
Fred Drakeaa3f9fb1998-08-07 19:52:37 +000037
Fred Drakec9f2c141998-03-11 12:08:21 +000038
Fred Drakedb34a1e1998-03-10 23:02:57 +000039# A little painful, but lets us clean up the top level directory a little,
Fred Drake85d14c92000-07-31 17:53:45 +000040# and not be tied to the current directory (as far as I can tell). Testing
41# an existing definition of $mydir is needed since it cannot be computed when
42# run under mkhowto with recent versions of LaTeX2HTML, since this file is
43# not read directly by LaTeX2HTML any more. mkhowto is required to prepend
44# the required definition at the top of the actual input file.
Fred Drakedb34a1e1998-03-10 23:02:57 +000045#
Fred Drake85d14c92000-07-31 17:53:45 +000046if (!defined $mydir) {
47 use Cwd;
48 use File::Basename;
49 ($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
50 chop $mydir; # remove trailing '/'
51 $mydir = getcwd() . "$dd$mydir"
52 unless $mydir =~ s|^/|/|;
53}
Fred Drakedb34a1e1998-03-10 23:02:57 +000054$LATEX2HTMLSTYLES = "$mydir$envkey$LATEX2HTMLSTYLES";
Fred Drakeb3a3ed81998-07-24 22:17:34 +000055push (@INC, $mydir);
Fred Drakebc7101d1998-03-06 21:18:55 +000056
Fred Drake235e6b11998-03-27 05:19:43 +000057($myrootname, $myrootdir, $myext) = fileparse($mydir, '\..*');
58chop $myrootdir;
59
Fred Drakebc7101d1998-03-06 21:18:55 +000060
Fred Drakea4565b01998-05-15 17:14:17 +000061# Hackish way to get the appropriate paper-*/ directory into $TEXINPUTS;
62# pass in the paper size (a4 or letter) as the environment variable PAPER
63# to add the right directory. If not given, the current directory is
64# added instead for use with HOWTO processing.
65#
66if (defined $ENV{'PAPER'}) {
67 $mytexinputs = "$myrootdir${dd}paper-$ENV{'PAPER'}$envkey";
68}
69else {
70 $mytexinputs = getcwd() . $envkey;
71}
72$mytexinputs .= "$myrootdir${dd}texinputs";
73
74
Fred Drakeb35f2b71999-09-23 16:53:09 +000075# Change this variable to change the text added in "About this document...";
76# this should be an absolute pathname to get it right.
77#
78$ABOUT_FILE = "$myrootdir${dd}html${dd}stdabout.dat";
79
80
Fred Drake85d14c92000-07-31 17:53:45 +000081sub custom_driver_hook {
Fred Drakea4565b01998-05-15 17:14:17 +000082 #
83 # This adds the directory of the main input file to $TEXINPUTS; it
84 # seems to be sufficiently general that it should be fine for HOWTO
85 # processing.
86 #
87 my $file = @_[0];
Fred Drake85d14c92000-07-31 17:53:45 +000088 my($jobname, $dir, $ext) = fileparse($file, '\..*');
89 $dir = L2hos->Make_directory_absolute($dir);
Fred Drakea4565b01998-05-15 17:14:17 +000090 $dir =~ s/$dd$//;
91 $TEXINPUTS = "$dir$envkey$mytexinputs";
Fred Drake85d14c92000-07-31 17:53:45 +000092 print "\nAdding $dir to \$TEXINPUTS\n";
Fred Drake191439a1999-09-22 19:50:51 +000093}
94
Fred Drakea4565b01998-05-15 17:14:17 +000095
Fred Drake85d14c92000-07-31 17:53:45 +000096$CUSTOM_BUTTONS = '';
Fred Drake062bc6e1998-08-13 22:03:46 +000097
Fred Drake85d14c92000-07-31 17:53:45 +000098sub make_nav_sectref {
Fred Drakebeb27bf1999-02-16 17:22:32 +000099 my($label,$title) = @_;
100 if ($title) {
Fred Drakee15956b2000-04-03 04:51:13 +0000101 return ("<b class='navlabel'>$label:</b> "
102 . "<span class='sectref'>$title</span>\n");
Fred Drakebeb27bf1999-02-16 17:22:32 +0000103 }
104 return '';
105}
106
Fred Drake85d14c92000-07-31 17:53:45 +0000107sub make_my_icon {
108 my($name, $text) = @_;
109 my $iconserver = ($ICONSERVER eq '.') ? '' : "$ICONSERVER/";
110 return "<img src=\"$iconserver$name.$IMAGE_TYPE\" border=\"0\""
111 . " height=\"32\"\n alt=\"$text\" width=\"32\">";
112}
113
Fred Drakef730fc32000-08-31 07:19:07 +0000114$BLANK_ICON = make_my_icon('blank', '');
Fred Drake85d14c92000-07-31 17:53:45 +0000115
116@my_icons = ();
117$my_icons{'next_page_inactive'} = $BLANK_ICON;
118$my_icons{'previous_page_inactive'} = $BLANK_ICON;
119$my_icons{'up_page_inactive'} = $BLANK_ICON;
Fred Drakef730fc32000-08-31 07:19:07 +0000120$x = make_my_icon('next', 'Next Page');
Fred Drake85d14c92000-07-31 17:53:45 +0000121$my_icons{'next_page'} = $x;
122$my_icons{'next'} = $x;
Fred Drakef730fc32000-08-31 07:19:07 +0000123$x = make_my_icon('previous', 'Previous Page');
Fred Drake85d14c92000-07-31 17:53:45 +0000124$my_icons{'previous_page'} = $x;
125$my_icons{'previous'} = $x;
Fred Drakef730fc32000-08-31 07:19:07 +0000126$my_icons{'up'} = make_my_icon('up', 'Up One Level');
127$my_icons{'contents'} = make_my_icon('contents', 'Contents');
128$my_icons{'index'} = make_my_icon('index', 'Index');
129$my_icons{'modules'} = make_my_icon('modules', 'Module Index');
Fred Drake85d14c92000-07-31 17:53:45 +0000130
131
132sub use_my_icon {
133 my $s = @_[0];
134 $s =~ s/\<tex2html_([a-z_]+)_visible_mark\>/$my_icons{$1}/;
Fred Drakea0075441999-04-29 19:06:56 +0000135 return $s;
Fred Drake13210ed1998-03-17 06:28:05 +0000136}
137
Fred Drake85d14c92000-07-31 17:53:45 +0000138sub make_nav_panel {
139 my $s;
Fred Drakef730fc32000-08-31 07:19:07 +0000140 $NEXT = $NEXT_TITLE ? use_my_icon("$NEXT") : $BLANK_ICON;
141 $UP = $UP_TITLE ? use_my_icon("$UP") : $BLANK_ICON;
142 $PREVIOUS = $PREVIOUS_TITLE ? use_my_icon("$PREVIOUS") : $BLANK_ICON;
Fred Drake85d14c92000-07-31 17:53:45 +0000143 $CONTENTS = use_my_icon("$CONTENTS");
144 $INDEX = $INDEX ? use_my_icon("$INDEX") : $BLANK_ICON;
145 if (!$CUSTOM_BUTTONS) {
146 $CUSTOM_BUTTONS = $BLANK_ICON;
147 }
148 $s = ('<table align="center" width="100%" cellpadding="0" cellspacing="2">'
149 . "\n<tr>"
150 # left-hand side
Fred Drake85d14c92000-07-31 17:53:45 +0000151 . "\n<td>$PREVIOUS</td>"
Fred Drake4640e132000-07-31 20:13:23 +0000152 . "\n<td>$UP</td>"
153 . "\n<td>$NEXT</td>"
Fred Drake85d14c92000-07-31 17:53:45 +0000154 # title box
Fred Drakef730fc32000-08-31 07:19:07 +0000155 . "\n<td align=\"center\" width=\"100%\">$t_title</td>"
Fred Drake85d14c92000-07-31 17:53:45 +0000156 # right-hand side
157 . "\n<td>$CONTENTS</td>"
158 . "\n<td>$CUSTOM_BUTTONS</td>" # module index
159 . "\n<td>$INDEX</td>"
160 . "\n</tr></table>\n"
161 # textual navigation
Fred Drake4640e132000-07-31 20:13:23 +0000162 . make_nav_sectref("Previous", $PREVIOUS_TITLE)
Fred Drake85d14c92000-07-31 17:53:45 +0000163 . make_nav_sectref("Up", $UP_TITLE)
Fred Drake4640e132000-07-31 20:13:23 +0000164 . make_nav_sectref("Next", $NEXT_TITLE)
165 );
Fred Drake85d14c92000-07-31 17:53:45 +0000166 # remove these; they are unnecessary and cause errors from validation
167 $s =~ s/ NAME="tex2html\d+"\n */ /g;
168 return $s;
169}
170
171
Fred Drakebc7101d1998-03-06 21:18:55 +0000172sub top_navigation_panel {
Fred Drake85d14c92000-07-31 17:53:45 +0000173 return make_nav_panel()
174 . '<br><hr>';
Fred Drakebc7101d1998-03-06 21:18:55 +0000175}
176
177sub bot_navigation_panel {
Fred Drake85d14c92000-07-31 17:53:45 +0000178 return "<p><hr>"
179 . make_nav_panel();
Fred Drake64bdc241998-04-17 02:14:12 +0000180}
181
182sub add_link {
183 # Returns a pair (iconic link, textual link)
184 my($icon, $current_file, @link) = @_;
185 my($dummy, $file, $title) = split($delim,
Fred Drake28e7b4c1998-10-20 18:14:20 +0000186 $section_info{join(' ',@link)});
Fred Drake85d14c92000-07-31 17:53:45 +0000187 $icon =~ s/\<tex2html_([_a-z]+)_visible_mark\>/$my_icons{$1}/;
Fred Drake64bdc241998-04-17 02:14:12 +0000188 if ($title && ($file ne $current_file)) {
189 $title = purify($title);
190 $title = get_first_words($title, $WORDS_IN_NAVIGATION_PANEL_TITLES);
191 return (make_href($file, $icon), make_href($file, "$title"))
192 }
Fred Drake85d14c92000-07-31 17:53:45 +0000193 elsif ($icon eq $my_icons{"up"} && $EXTERNAL_UP_LINK) {
Fred Drake64bdc241998-04-17 02:14:12 +0000194 return (make_href($EXTERNAL_UP_LINK, $icon),
195 make_href($EXTERNAL_UP_LINK, "$EXTERNAL_UP_TITLE"))
196 }
Fred Drake85d14c92000-07-31 17:53:45 +0000197 elsif ($icon eq $my_icons{"previous"}
Fred Drake64bdc241998-04-17 02:14:12 +0000198 && $EXTERNAL_PREV_LINK && $EXTERNAL_PREV_TITLE) {
199 return (make_href($EXTERNAL_PREV_LINK, $icon),
200 make_href($EXTERNAL_PREV_LINK, "$EXTERNAL_PREV_TITLE"))
201 }
Fred Drake85d14c92000-07-31 17:53:45 +0000202 elsif ($icon eq $my_icons{"next"}
Fred Drake64bdc241998-04-17 02:14:12 +0000203 && $EXTERNAL_DOWN_LINK && $EXTERNAL_DOWN_TITLE) {
204 return (make_href($EXTERNAL_DOWN_LINK, $icon),
205 make_href($EXTERNAL_DOWN_LINK, "$EXTERNAL_DOWN_TITLE"))
206 }
Fred Drake85d14c92000-07-31 17:53:45 +0000207 return (&inactive_img($icon), "");
Fred Drake64bdc241998-04-17 02:14:12 +0000208}
209
210sub add_special_link {
211 my($icon, $file, $current_file) = @_;
Fred Drake85d14c92000-07-31 17:53:45 +0000212 $icon =~ s/\<tex2html_([_a-z]+)_visible_mark\>/$my_icons{$1}/;
213 return (($file && ($file ne $current_file))
214 ? make_href($file, $icon)
215 : undef)
Fred Drake64bdc241998-04-17 02:14:12 +0000216}
217
Fred Drake85d14c92000-07-31 17:53:45 +0000218# The img_tag() function seems only to be called with the parameter
219# 'anchor_invisible_mark', which we want to turn into ''. Since
220# replace_icon_marks() is the only interesting caller, and all it really
221# does is call img_tag(), we can just define the hook alternative to be
222# a no-op instead.
223#
224sub replace_icons_hook {}
Fred Drakebc7101d1998-03-06 21:18:55 +0000225
Fred Drake50cdd971999-02-19 23:04:59 +0000226sub do_cmd_arabic {
227 # get rid of that nasty <SPAN CLASS="arabic">...</SPAN>
Fred Drake85d14c92000-07-31 17:53:45 +0000228 my($ctr, $val, $id, $text) = &read_counter_value(@_[0]);
229 return ($val ? farabic($val) : "0") . $text;
Fred Drake50cdd971999-02-19 23:04:59 +0000230}
231
232
Fred Drakebc7101d1998-03-06 21:18:55 +0000233sub gen_index_id {
234 # this is used to ensure common index key generation and a stable sort
Fred Drake235e6b11998-03-27 05:19:43 +0000235 my($str,$extra) = @_;
Fred Drake64bdc241998-04-17 02:14:12 +0000236 sprintf('%s###%s%010d', $str, $extra, ++$global{'max_id'});
Fred Drakebc7101d1998-03-06 21:18:55 +0000237}
238
Fred Drake85d14c92000-07-31 17:53:45 +0000239sub insert_index {
Fred Drake2383f6d1999-03-02 16:00:37 +0000240 my($mark,$datafile,$columns,$letters,$prefix) = @_;
Fred Drake4d10b431998-08-07 20:51:58 +0000241 my $prog = "$myrootdir/tools/buildindex.py";
242 my $index;
243 if ($letters) {
244 $index = `$prog --columns $columns --letters $datafile`;
245 }
246 else {
247 $index = `$prog --columns $columns $datafile`;
248 }
Fred Drakec5681732000-09-12 20:13:04 +0000249 if (!s/$mark/$prefix$index/) {
250 print "\nCould not locate index mark: $mark";
251 }
Fred Drake64bdc241998-04-17 02:14:12 +0000252}
253
Fred Drake85d14c92000-07-31 17:53:45 +0000254sub add_idx {
Fred Drake9bbdce51999-01-19 16:30:10 +0000255 print "\nBuilding HTML for the index ...";
Fred Drake235e6b11998-03-27 05:19:43 +0000256 close(IDXFILE);
Fred Drake2383f6d1999-03-02 16:00:37 +0000257 insert_index($idx_mark, 'index.dat', $INDEX_COLUMNS, 1, '');
Fred Drake13210ed1998-03-17 06:28:05 +0000258}
Fred Drakebc7101d1998-03-06 21:18:55 +0000259
260
261$idx_module_mark = '<tex2html_idx_module_mark>';
262$idx_module_title = 'Module Index';
263
Fred Drake85d14c92000-07-31 17:53:45 +0000264sub add_module_idx {
Fred Drake9bbdce51999-01-19 16:30:10 +0000265 print "\nBuilding HTML for the module index ...";
Fred Drake235e6b11998-03-27 05:19:43 +0000266 my $key;
Fred Drake2383f6d1999-03-02 16:00:37 +0000267 my $first = 1;
268 my $prevplat = '';
269 my $allthesame = 1;
270 my $prefix = '';
271 foreach $key (keys %Modules) {
272 $key =~ s/<tt>([a-zA-Z0-9._]*)<\/tt>/\1/;
273 my $plat = "$ModulePlatforms{$key}";
274 $plat = ''
Fred Drake62cc3601999-03-04 18:41:17 +0000275 if ($plat eq $IGNORE_PLATFORM_ANNOTATION);
Fred Drake2383f6d1999-03-02 16:00:37 +0000276 if (!$first) {
277 $allthesame = 0
278 if ($prevplat ne $plat);
279 }
280 else { $first = 0; }
281 $prevplat = $plat;
282 }
Fred Drake64bdc241998-04-17 02:14:12 +0000283 open(MODIDXFILE, '>modindex.dat') || die "\n$!\n";
Fred Drake235e6b11998-03-27 05:19:43 +0000284 foreach $key (keys %Modules) {
285 # dump the line in the data file; just use a dummy seqno field
Fred Drake2383f6d1999-03-02 16:00:37 +0000286 my $nkey = $1;
287 my $moditem = "$Modules{$key}";
288 my $plat = '';
289 $key =~ s/<tt>([a-zA-Z0-9._]*)<\/tt>/\1/;
290 if ($ModulePlatforms{$key} && !$allthesame) {
Fred Drakee15956b2000-04-03 04:51:13 +0000291 $plat = (" <em>(<span class='platform'>$ModulePlatforms{$key}"
Fred Drakebb584d31999-03-25 22:18:30 +0000292 . '</span>)</em>');
Fred Drake2383f6d1999-03-02 16:00:37 +0000293 }
Fred Drakee15956b2000-04-03 04:51:13 +0000294 print MODIDXFILE $moditem . $IDXFILE_FIELD_SEP
295 . "<tt class='module'>$key</tt>$plat###\n";
Fred Drakebc7101d1998-03-06 21:18:55 +0000296 }
Fred Drake235e6b11998-03-27 05:19:43 +0000297 close(MODIDXFILE);
Fred Drake2383f6d1999-03-02 16:00:37 +0000298 if (!$allthesame) {
299 $prefix = <<PLAT_DISCUSS;
300
301
302<p> Some module names are followed by an annotation indicating what
303platform they are available on.</p>
304
305PLAT_DISCUSS
306 }
307 insert_index($idx_module_mark, 'modindex.dat', $MODULE_INDEX_COLUMNS, 0,
308 $prefix);
Fred Drakebc7101d1998-03-06 21:18:55 +0000309}
310
Fred Drake235e6b11998-03-27 05:19:43 +0000311# replace both indexes as needed:
Fred Drake85d14c92000-07-31 17:53:45 +0000312sub add_idx_hook {
Fred Drakeb3a3ed81998-07-24 22:17:34 +0000313 add_idx() if (/$idx_mark/);
Fred Drake2383f6d1999-03-02 16:00:37 +0000314 process_python_state();
Fred Drakec5681732000-09-12 20:13:04 +0000315 if ($MODULE_INDEX_FILE) {
316 local ($_);
317 open(MYFILE, "<$MODULE_INDEX_FILE");
318 sysread(MYFILE, $_, 1024*1024);
319 close(MYFILE);
320 add_module_idx();
321 open(MYFILE,">$MODULE_INDEX_FILE");
322 print MYFILE $_;
323 close(MYFILE);
324 }
Fred Drake235e6b11998-03-27 05:19:43 +0000325}
Fred Drakebc7101d1998-03-06 21:18:55 +0000326
Fred Drakebc7101d1998-03-06 21:18:55 +0000327
Fred Drake191439a1999-09-22 19:50:51 +0000328# In addition to the standard stuff, add label to allow named node files and
329# support suppression of the page complete (for HTML Help use).
Fred Drakebc7101d1998-03-06 21:18:55 +0000330sub do_cmd_tableofcontents {
331 local($_) = @_;
332 $TITLE = $toc_title;
333 $tocfile = $CURRENT_FILE;
Fred Drake64bdc241998-04-17 02:14:12 +0000334 my($closures,$reopens) = preserve_open_tags();
335 anchor_label('contents', $CURRENT_FILE, $_); # this is added
Fred Drakebeb27bf1999-02-16 17:22:32 +0000336 join('', "<BR>\n\\tableofchildlinks[off]", $closures
Fred Drake64bdc241998-04-17 02:14:12 +0000337 , make_section_heading($toc_title, 'H2'), $toc_mark
Fred Drakebc7101d1998-03-06 21:18:55 +0000338 , $reopens, $_);
339}
340# In addition to the standard stuff, add label to allow named node files.
341sub do_cmd_listoffigures {
342 local($_) = @_;
343 $TITLE = $lof_title;
344 $loffile = $CURRENT_FILE;
Fred Drake64bdc241998-04-17 02:14:12 +0000345 my($closures,$reopens) = preserve_open_tags();
346 anchor_label('lof', $CURRENT_FILE, $_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000347 join('', "<BR>\n", $closures
Fred Drake64bdc241998-04-17 02:14:12 +0000348 , make_section_heading($lof_title, 'H2'), $lof_mark
Fred Drakebc7101d1998-03-06 21:18:55 +0000349 , $reopens, $_);
350}
351# In addition to the standard stuff, add label to allow named node files.
352sub do_cmd_listoftables {
353 local($_) = @_;
354 $TITLE = $lot_title;
355 $lotfile = $CURRENT_FILE;
Fred Drake64bdc241998-04-17 02:14:12 +0000356 my($closures,$reopens) = preserve_open_tags();
357 anchor_label('lot', $CURRENT_FILE, $_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000358 join('', "<BR>\n", $closures
Fred Drake64bdc241998-04-17 02:14:12 +0000359 , make_section_heading($lot_title, 'H2'), $lot_mark
Fred Drakebc7101d1998-03-06 21:18:55 +0000360 , $reopens, $_);
361}
362# In addition to the standard stuff, add label to allow named node files.
363sub do_cmd_textohtmlinfopage {
364 local($_) = @_;
365 if ($INFO) { #
Fred Drake64bdc241998-04-17 02:14:12 +0000366 anchor_label("about",$CURRENT_FILE,$_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000367 } #
Fred Drake15796f71998-11-30 19:25:47 +0000368 my $the_version = ''; # and the rest is
369 if ($t_date) { # mostly ours
370 $the_version = ",\n$t_date";
371 if ($PYTHON_VERSION) {
372 $the_version .= ", Release $PYTHON_VERSION";
373 }
374 }
375 $_ = (($INFO == 1)
Fred Drakeb35f2b71999-09-23 16:53:09 +0000376 ? join('',
377 $close_all,
378 "<strong>$t_title</strong>$the_version\n",
379 `cat $ABOUT_FILE`,
380 $open_all, $_)
381 : join('', $close_all, $INFO,"\n", $open_all, $_));
Fred Drake15796f71998-11-30 19:25:47 +0000382 $_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000383}
384
385# $idx_mark will be replaced with the real index at the end
386sub do_cmd_textohtmlindex {
387 local($_) = @_;
388 $TITLE = $idx_title;
389 $idxfile = $CURRENT_FILE;
Fred Drake235e6b11998-03-27 05:19:43 +0000390 if (%index_labels) { make_index_labels(); }
391 if (($SHORT_INDEX) && (%index_segment)) { make_preindex(); }
Fred Drakebc7101d1998-03-06 21:18:55 +0000392 else { $preindex = ''; }
Fred Drake235e6b11998-03-27 05:19:43 +0000393 my $heading = make_section_heading($idx_title, 'h2') . $idx_mark;
Fred Drake11916921998-04-02 22:30:57 +0000394 my($pre,$post) = minimize_open_tags($heading);
Fred Drake235e6b11998-03-27 05:19:43 +0000395 anchor_label('genindex',$CURRENT_FILE,$_); # this is added
Fred Drakec5681732000-09-12 20:13:04 +0000396 return "<br>\n" . $pre . $_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000397}
398
Fred Drakec5681732000-09-12 20:13:04 +0000399$MODULE_INDEX_FILE = '';
400
Fred Drakebc7101d1998-03-06 21:18:55 +0000401# $idx_module_mark will be replaced with the real index at the end
402sub do_cmd_textohtmlmoduleindex {
403 local($_) = @_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000404 $TITLE = $idx_module_title;
Fred Drakec5681732000-09-12 20:13:04 +0000405 anchor_label('modindex', $CURRENT_FILE, $_);
406 $MODULE_INDEX_FILE = "$CURRENT_FILE";
407 $_ = ('<p>' . make_section_heading($idx_module_title, 'h2')
408 . $idx_module_mark . $_);
409 return $_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000410}
411
Fred Drakec5681732000-09-12 20:13:04 +0000412# The bibliography and the index should be treated as separate
413# sections in their own HTML files. The \bibliography{} command acts
414# as a sectioning command that has the desired effect. But when the
415# bibliography is constructed manually using the thebibliography
416# environment, or when using the theindex environment it is not
417# possible to use the normal sectioning mechanism. This subroutine
418# inserts a \bibliography{} or a dummy \textohtmlindex command just
419# before the appropriate environments to force sectioning.
Fred Drakebc7101d1998-03-06 21:18:55 +0000420
Fred Drakec5681732000-09-12 20:13:04 +0000421# XXX This *assumes* that if there are two {theindex} environments,
422# the first is the module index and the second is the standard
423# index. This is sufficient for the current Python documentation,
424# but that's about it.
Fred Drakebc7101d1998-03-06 21:18:55 +0000425
426sub add_bbl_and_idx_dummy_commands {
Fred Drake11916921998-04-02 22:30:57 +0000427 my $id = $global{'max_id'};
Fred Drakebc7101d1998-03-06 21:18:55 +0000428
429 s/([\\]begin\s*$O\d+$C\s*thebibliography)/$bbl_cnt++; $1/eg;
Fred Drake191439a1999-09-22 19:50:51 +0000430 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 +0000431 my(@parts) = split(/\\begin\s*$O\d+$C\s*theindex/);
432 if (scalar(@parts) == 3) {
433 # Be careful to re-write the string in place, since $_ is *not*
434 # returned explicity; *** nasty side-effect dependency! ***
435 print "\nadd_bbl_and_idx_dummy_commands ==> adding module index";
436 my $rx = "([\\\\]begin\\s*$O\\d+$C\\s*theindex[\\s\\S]*)"
437 . "([\\\\]begin\\s*$O\\d+$C\\s*theindex)";
438 s/$rx/\\textohtmlmoduleindex \1 \\textohtmlindex \2/o;
439 # Add a button to the navigation areas:
440 $CUSTOM_BUTTONS .= $my_icons{'modules'};
Fred Drake11916921998-04-02 22:30:57 +0000441 }
442 else {
Fred Drake85d14c92000-07-31 17:53:45 +0000443 $CUSTOM_BUTTONS .= $BLANK_ICON;
444 $global{'max_id'} = $id; # not sure why....
445 s/([\\]begin\s*$O\d+$C\s*theindex)/\\textohtmlindex $1/o;
Fred Drake191439a1999-09-22 19:50:51 +0000446 s/[\\]printindex/\\textohtmlindex /o;
447 }
Fred Drake11916921998-04-02 22:30:57 +0000448 #----------------------------------------------------------------------
Fred Drake64bdc241998-04-17 02:14:12 +0000449 lib_add_bbl_and_idx_dummy_commands()
Fred Drake11916921998-04-02 22:30:57 +0000450 if defined(&lib_add_bbl_and_idx_dummy_commands);
Fred Drakebc7101d1998-03-06 21:18:55 +0000451}
452
Fred Drakec5681732000-09-12 20:13:04 +0000453# The bibliographic references, the appendices, the lists of figures
454# and tables etc. must appear in the contents table at the same level
455# as the outermost sectioning command. This subroutine finds what is
456# the outermost level and sets the above to the same level;
Fred Drakebc7101d1998-03-06 21:18:55 +0000457
Fred Drake13210ed1998-03-17 06:28:05 +0000458sub set_depth_levels {
459 # Sets $outermost_level
Fred Drake11916921998-04-02 22:30:57 +0000460 my $level;
Fred Drake13210ed1998-03-17 06:28:05 +0000461 #RRM: do not alter user-set value for $MAX_SPLIT_DEPTH
462 foreach $level ("part", "chapter", "section", "subsection",
463 "subsubsection", "paragraph") {
464 last if (($outermost_level) = /\\($level)$delimiter_rx/);
465 }
466 $level = ($outermost_level ? $section_commands{$outermost_level} :
467 do {$outermost_level = 'section'; 3;});
Fred Drakebc7101d1998-03-06 21:18:55 +0000468
Fred Drake13210ed1998-03-17 06:28:05 +0000469 #RRM: but calculate value for $MAX_SPLIT_DEPTH when a $REL_DEPTH was given
470 if ($REL_DEPTH && $MAX_SPLIT_DEPTH) {
471 $MAX_SPLIT_DEPTH = $level + $MAX_SPLIT_DEPTH;
472 } elsif (!($MAX_SPLIT_DEPTH)) { $MAX_SPLIT_DEPTH = 1 };
Fred Drakebc7101d1998-03-06 21:18:55 +0000473
Fred Drake64bdc241998-04-17 02:14:12 +0000474 %unnumbered_section_commands = ('tableofcontents' => $level,
475 'listoffigures' => $level,
476 'listoftables' => $level,
477 'bibliography' => $level,
478 'textohtmlindex' => $level,
479 'textohtmlmoduleindex' => $level);
480 $section_headings{'textohtmlmoduleindex'} = 'h1';
Fred Drakebc7101d1998-03-06 21:18:55 +0000481
Fred Drake64bdc241998-04-17 02:14:12 +0000482 %section_commands = (%unnumbered_section_commands,
483 %section_commands);
Fred Drake11916921998-04-02 22:30:57 +0000484
485 make_sections_rx();
Fred Drake13210ed1998-03-17 06:28:05 +0000486}
Fred Drakebc7101d1998-03-06 21:18:55 +0000487
488
Fred Drake1072e461998-04-12 02:16:34 +0000489# This changes the markup used for {verbatim} environments, and is the
Fred Drake95474f91999-02-09 18:45:50 +0000490# best way I've found that ensures the <dl> goes on the outside of the
Fred Drake1072e461998-04-12 02:16:34 +0000491# <pre>...</pre>.
492#
493# Note that this *must* be done in the init file, not the python.perl
Fred Drakec5681732000-09-12 20:13:04 +0000494# style support file. The %declarations must be set before
495# initialize() is called in the main LaTeX2HTML script (which happens
496# before style files are loaded).
Fred Drake1072e461998-04-12 02:16:34 +0000497#
Fred Drakee15956b2000-04-03 04:51:13 +0000498%declarations = ('preform' => '<dl><dd><pre class="verbatim"></pre></dl>',
Fred Drake1072e461998-04-12 02:16:34 +0000499 %declarations);
500
Fred Drakee15956b2000-04-03 04:51:13 +0000501
Fred Drakec5681732000-09-12 20:13:04 +0000502# This is added to get rid of the long comment that follows the
503# doctype declaration; MSIE5 on NT4 SP4 barfs on it and drops the
504# content of the page.
Fred Drakee15956b2000-04-03 04:51:13 +0000505sub make_head_and_body {
Fred Drake85d14c92000-07-31 17:53:45 +0000506 my($title, $body) = @_;
507 my $DTDcomment = '';
508 my($version, $isolanguage) = ($HTML_VERSION, 'EN');
509 my %isolanguages = ( 'english', 'EN' , 'USenglish', 'EN.US'
510 , 'original', 'EN' , 'german' , 'DE'
511 , 'austrian', 'DE.AT', 'french' , 'FR'
512 , 'spanish', 'ES');
Fred Drakee15956b2000-04-03 04:51:13 +0000513 $isolanguage = $isolanguages{$default_language};
514 $isolanguage = 'EN' unless $isolanguage;
515 $title = &purify($title,1);
516 eval("\$title = ". $default_title ) unless ($title);
517
518 # allow user-modification of the <TITLE> tag; thanks Dan Young
519 if (defined &custom_TITLE_hook) {
520 $title = &custom_TITLE_hook($title, $toc_sec_title);
521 }
522
523 if ($DOCTYPE =~ /\/\/[\w\.]+\s*$/) { # language spec included
524 $DTDcomment = "<!DOCTYPE html PUBLIC \"$DOCTYPE\">\n";
525 } else {
526 $DTDcomment = "<!DOCTYPE html PUBLIC \"$DOCTYPE//"
527 . ($ISO_LANGUAGE ? $ISO_LANGUAGE : $isolanguage) . "\">\n";
528 }
529
530 $STYLESHEET = $FILE.".css" unless $STYLESHEET;
531 if (!$charset && $CHARSET) { $charset = $CHARSET; $charset =~ s/_/\-/go; }
532
533 join('', ($DOCTYPE ? $DTDcomment : '' )
534 ,"<html>\n<head>\n<title>", $title, "</title>\n"
535 , &meta_information($title)
536 , ($CHARSET && $HTML_VERSION ge "2.1" ?
537 "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=$charset\">\n"
538 : "" )
539 , ($BASE ? "<base href=\"$BASE\">\n" : "" )
540 , "<link rel=\"STYLESHEET\" href=\"$STYLESHEET\">"
541 , $more_links_mark
542 , "\n</head>\n<body $body>\n");
543}
544
Fred Drakebc7101d1998-03-06 21:18:55 +00005451; # This must be the last line