blob: bd85f686d48b0524eb5d29053d5fa6a51e01cf63 [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';
21
Fred Drake6aa5d481998-08-11 03:14:50 +000022# Control where the navigation bars should show up:
23$TOP_NAVIGATION = 1;
24$BOTTOM_NAVIGATION = 1;
25$AUTO_NAVIGATION = 0;
26
Fred Drake191439a1999-09-22 19:50:51 +000027# these exactly match the python.org colors
28$BODYTEXT = ('bgcolor="#ffffff" text="#000000"'
29 . ' link="#0000bb" vlink="#551a8b" alink="#ff0000"');
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 = '';
96$NAV_BGCOLOR = " bgcolor=\"#99CCFF\"";
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
114$BLANK_ICON = make_my_icon("blank", "");
115
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;
120$x = make_my_icon("next", "Next Page");
121$my_icons{'next_page'} = $x;
122$my_icons{'next'} = $x;
123$x = make_my_icon("previous", "Previous Page");
124$my_icons{'previous_page'} = $x;
125$my_icons{'previous'} = $x;
126$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");
130
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;
140 $NEXT = use_my_icon("$NEXT");
141 $UP = use_my_icon("$UP");
142 $PREVIOUS = use_my_icon("$PREVIOUS");
143 $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
155 . "\n<td align=\"center\"$NAV_BGCOLOR width=\"100%\">"
156 . "\n <b class=\"title\">$t_title</b></td>"
157 # right-hand side
158 . "\n<td>$CONTENTS</td>"
159 . "\n<td>$CUSTOM_BUTTONS</td>" # module index
160 . "\n<td>$INDEX</td>"
161 . "\n</tr></table>\n"
162 # textual navigation
Fred Drake4640e132000-07-31 20:13:23 +0000163 . make_nav_sectref("Previous", $PREVIOUS_TITLE)
Fred Drake85d14c92000-07-31 17:53:45 +0000164 . make_nav_sectref("Up", $UP_TITLE)
Fred Drake4640e132000-07-31 20:13:23 +0000165 . make_nav_sectref("Next", $NEXT_TITLE)
166 );
Fred Drake85d14c92000-07-31 17:53:45 +0000167 # remove these; they are unnecessary and cause errors from validation
168 $s =~ s/ NAME="tex2html\d+"\n */ /g;
169 return $s;
170}
171
172
Fred Drakebc7101d1998-03-06 21:18:55 +0000173sub top_navigation_panel {
Fred Drake85d14c92000-07-31 17:53:45 +0000174 return make_nav_panel()
175 . '<br><hr>';
Fred Drakebc7101d1998-03-06 21:18:55 +0000176}
177
178sub bot_navigation_panel {
Fred Drake85d14c92000-07-31 17:53:45 +0000179 return "<p><hr>"
180 . make_nav_panel();
Fred Drake64bdc241998-04-17 02:14:12 +0000181}
182
183sub add_link {
184 # Returns a pair (iconic link, textual link)
185 my($icon, $current_file, @link) = @_;
186 my($dummy, $file, $title) = split($delim,
Fred Drake28e7b4c1998-10-20 18:14:20 +0000187 $section_info{join(' ',@link)});
Fred Drake85d14c92000-07-31 17:53:45 +0000188 $icon =~ s/\<tex2html_([_a-z]+)_visible_mark\>/$my_icons{$1}/;
Fred Drake64bdc241998-04-17 02:14:12 +0000189 if ($title && ($file ne $current_file)) {
190 $title = purify($title);
191 $title = get_first_words($title, $WORDS_IN_NAVIGATION_PANEL_TITLES);
192 return (make_href($file, $icon), make_href($file, "$title"))
193 }
Fred Drake85d14c92000-07-31 17:53:45 +0000194 elsif ($icon eq $my_icons{"up"} && $EXTERNAL_UP_LINK) {
Fred Drake64bdc241998-04-17 02:14:12 +0000195 return (make_href($EXTERNAL_UP_LINK, $icon),
196 make_href($EXTERNAL_UP_LINK, "$EXTERNAL_UP_TITLE"))
197 }
Fred Drake85d14c92000-07-31 17:53:45 +0000198 elsif ($icon eq $my_icons{"previous"}
Fred Drake64bdc241998-04-17 02:14:12 +0000199 && $EXTERNAL_PREV_LINK && $EXTERNAL_PREV_TITLE) {
200 return (make_href($EXTERNAL_PREV_LINK, $icon),
201 make_href($EXTERNAL_PREV_LINK, "$EXTERNAL_PREV_TITLE"))
202 }
Fred Drake85d14c92000-07-31 17:53:45 +0000203 elsif ($icon eq $my_icons{"next"}
Fred Drake64bdc241998-04-17 02:14:12 +0000204 && $EXTERNAL_DOWN_LINK && $EXTERNAL_DOWN_TITLE) {
205 return (make_href($EXTERNAL_DOWN_LINK, $icon),
206 make_href($EXTERNAL_DOWN_LINK, "$EXTERNAL_DOWN_TITLE"))
207 }
Fred Drake85d14c92000-07-31 17:53:45 +0000208 return (&inactive_img($icon), "");
Fred Drake64bdc241998-04-17 02:14:12 +0000209}
210
211sub add_special_link {
212 my($icon, $file, $current_file) = @_;
Fred Drake85d14c92000-07-31 17:53:45 +0000213 $icon =~ s/\<tex2html_([_a-z]+)_visible_mark\>/$my_icons{$1}/;
214 return (($file && ($file ne $current_file))
215 ? make_href($file, $icon)
216 : undef)
Fred Drake64bdc241998-04-17 02:14:12 +0000217}
218
Fred Drake85d14c92000-07-31 17:53:45 +0000219# The img_tag() function seems only to be called with the parameter
220# 'anchor_invisible_mark', which we want to turn into ''. Since
221# replace_icon_marks() is the only interesting caller, and all it really
222# does is call img_tag(), we can just define the hook alternative to be
223# a no-op instead.
224#
225sub replace_icons_hook {}
Fred Drakebc7101d1998-03-06 21:18:55 +0000226
Fred Drake50cdd971999-02-19 23:04:59 +0000227sub do_cmd_arabic {
228 # get rid of that nasty <SPAN CLASS="arabic">...</SPAN>
Fred Drake85d14c92000-07-31 17:53:45 +0000229 my($ctr, $val, $id, $text) = &read_counter_value(@_[0]);
230 return ($val ? farabic($val) : "0") . $text;
Fred Drake50cdd971999-02-19 23:04:59 +0000231}
232
233
Fred Drakebc7101d1998-03-06 21:18:55 +0000234sub gen_index_id {
235 # this is used to ensure common index key generation and a stable sort
Fred Drake235e6b11998-03-27 05:19:43 +0000236 my($str,$extra) = @_;
Fred Drake64bdc241998-04-17 02:14:12 +0000237 sprintf('%s###%s%010d', $str, $extra, ++$global{'max_id'});
Fred Drakebc7101d1998-03-06 21:18:55 +0000238}
239
Fred Drake85d14c92000-07-31 17:53:45 +0000240sub insert_index {
Fred Drake2383f6d1999-03-02 16:00:37 +0000241 my($mark,$datafile,$columns,$letters,$prefix) = @_;
Fred Drake4d10b431998-08-07 20:51:58 +0000242 my $prog = "$myrootdir/tools/buildindex.py";
243 my $index;
244 if ($letters) {
245 $index = `$prog --columns $columns --letters $datafile`;
246 }
247 else {
248 $index = `$prog --columns $columns $datafile`;
249 }
Fred Drake2383f6d1999-03-02 16:00:37 +0000250 s/$mark/$prefix$index/;
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/);
313 add_module_idx() if (/$idx_module_mark/);
Fred Drake2383f6d1999-03-02 16:00:37 +0000314 process_python_state();
Fred Drake235e6b11998-03-27 05:19:43 +0000315}
Fred Drakebc7101d1998-03-06 21:18:55 +0000316
Fred Drakebc7101d1998-03-06 21:18:55 +0000317
Fred Drake191439a1999-09-22 19:50:51 +0000318# In addition to the standard stuff, add label to allow named node files and
319# support suppression of the page complete (for HTML Help use).
Fred Drakebc7101d1998-03-06 21:18:55 +0000320sub do_cmd_tableofcontents {
321 local($_) = @_;
322 $TITLE = $toc_title;
323 $tocfile = $CURRENT_FILE;
Fred Drake64bdc241998-04-17 02:14:12 +0000324 my($closures,$reopens) = preserve_open_tags();
325 anchor_label('contents', $CURRENT_FILE, $_); # this is added
Fred Drakebeb27bf1999-02-16 17:22:32 +0000326 join('', "<BR>\n\\tableofchildlinks[off]", $closures
Fred Drake64bdc241998-04-17 02:14:12 +0000327 , make_section_heading($toc_title, 'H2'), $toc_mark
Fred Drakebc7101d1998-03-06 21:18:55 +0000328 , $reopens, $_);
329}
330# In addition to the standard stuff, add label to allow named node files.
331sub do_cmd_listoffigures {
332 local($_) = @_;
333 $TITLE = $lof_title;
334 $loffile = $CURRENT_FILE;
Fred Drake64bdc241998-04-17 02:14:12 +0000335 my($closures,$reopens) = preserve_open_tags();
336 anchor_label('lof', $CURRENT_FILE, $_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000337 join('', "<BR>\n", $closures
Fred Drake64bdc241998-04-17 02:14:12 +0000338 , make_section_heading($lof_title, 'H2'), $lof_mark
Fred Drakebc7101d1998-03-06 21:18:55 +0000339 , $reopens, $_);
340}
341# In addition to the standard stuff, add label to allow named node files.
342sub do_cmd_listoftables {
343 local($_) = @_;
344 $TITLE = $lot_title;
345 $lotfile = $CURRENT_FILE;
Fred Drake64bdc241998-04-17 02:14:12 +0000346 my($closures,$reopens) = preserve_open_tags();
347 anchor_label('lot', $CURRENT_FILE, $_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000348 join('', "<BR>\n", $closures
Fred Drake64bdc241998-04-17 02:14:12 +0000349 , make_section_heading($lot_title, 'H2'), $lot_mark
Fred Drakebc7101d1998-03-06 21:18:55 +0000350 , $reopens, $_);
351}
352# In addition to the standard stuff, add label to allow named node files.
353sub do_cmd_textohtmlinfopage {
354 local($_) = @_;
355 if ($INFO) { #
Fred Drake64bdc241998-04-17 02:14:12 +0000356 anchor_label("about",$CURRENT_FILE,$_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000357 } #
Fred Drake15796f71998-11-30 19:25:47 +0000358 my $the_version = ''; # and the rest is
359 if ($t_date) { # mostly ours
360 $the_version = ",\n$t_date";
361 if ($PYTHON_VERSION) {
362 $the_version .= ", Release $PYTHON_VERSION";
363 }
364 }
365 $_ = (($INFO == 1)
Fred Drakeb35f2b71999-09-23 16:53:09 +0000366 ? join('',
367 $close_all,
368 "<strong>$t_title</strong>$the_version\n",
369 `cat $ABOUT_FILE`,
370 $open_all, $_)
371 : join('', $close_all, $INFO,"\n", $open_all, $_));
Fred Drake15796f71998-11-30 19:25:47 +0000372 $_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000373}
374
375# $idx_mark will be replaced with the real index at the end
376sub do_cmd_textohtmlindex {
377 local($_) = @_;
378 $TITLE = $idx_title;
379 $idxfile = $CURRENT_FILE;
Fred Drake235e6b11998-03-27 05:19:43 +0000380 if (%index_labels) { make_index_labels(); }
381 if (($SHORT_INDEX) && (%index_segment)) { make_preindex(); }
Fred Drakebc7101d1998-03-06 21:18:55 +0000382 else { $preindex = ''; }
Fred Drake235e6b11998-03-27 05:19:43 +0000383 my $heading = make_section_heading($idx_title, 'h2') . $idx_mark;
Fred Drake11916921998-04-02 22:30:57 +0000384 my($pre,$post) = minimize_open_tags($heading);
Fred Drake235e6b11998-03-27 05:19:43 +0000385 anchor_label('genindex',$CURRENT_FILE,$_); # this is added
386 '<br>\n' . $pre . $_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000387}
388
389# $idx_module_mark will be replaced with the real index at the end
390sub do_cmd_textohtmlmoduleindex {
391 local($_) = @_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000392 $TITLE = $idx_module_title;
Fred Drake64bdc241998-04-17 02:14:12 +0000393 anchor_label("modindex",$CURRENT_FILE,$_);
Fred Drake235e6b11998-03-27 05:19:43 +0000394 '<p>' . make_section_heading($idx_module_title, "h2")
395 . $idx_module_mark . $_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000396}
397
398# The bibliography and the index should be treated as separate sections
399# in their own HTML files. The \bibliography{} command acts as a sectioning command
400# that has the desired effect. But when the bibliography is constructed
401# manually using the thebibliography environment, or when using the
402# theindex environment it is not possible to use the normal sectioning
403# mechanism. This subroutine inserts a \bibliography{} or a dummy
404# \textohtmlindex command just before the appropriate environments
405# to force sectioning.
406
407# XXX This *assumes* that if there are two {theindex} environments, the
408# first is the module index and the second is the standard index. This
409# is sufficient for the current Python documentation, but that's about
410# it.
411
412sub add_bbl_and_idx_dummy_commands {
Fred Drake11916921998-04-02 22:30:57 +0000413 my $id = $global{'max_id'};
Fred Drakebc7101d1998-03-06 21:18:55 +0000414
415 s/([\\]begin\s*$O\d+$C\s*thebibliography)/$bbl_cnt++; $1/eg;
Fred Drake191439a1999-09-22 19:50:51 +0000416 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 +0000417 my(@parts) = split(/\\begin\s*$O\d+$C\s*theindex/);
418 if (scalar(@parts) == 3) {
419 # Be careful to re-write the string in place, since $_ is *not*
420 # returned explicity; *** nasty side-effect dependency! ***
421 print "\nadd_bbl_and_idx_dummy_commands ==> adding module index";
422 my $rx = "([\\\\]begin\\s*$O\\d+$C\\s*theindex[\\s\\S]*)"
423 . "([\\\\]begin\\s*$O\\d+$C\\s*theindex)";
424 s/$rx/\\textohtmlmoduleindex \1 \\textohtmlindex \2/o;
425 # Add a button to the navigation areas:
426 $CUSTOM_BUTTONS .= $my_icons{'modules'};
Fred Drake11916921998-04-02 22:30:57 +0000427 }
428 else {
Fred Drake85d14c92000-07-31 17:53:45 +0000429 $CUSTOM_BUTTONS .= $BLANK_ICON;
430 $global{'max_id'} = $id; # not sure why....
431 s/([\\]begin\s*$O\d+$C\s*theindex)/\\textohtmlindex $1/o;
Fred Drake191439a1999-09-22 19:50:51 +0000432 s/[\\]printindex/\\textohtmlindex /o;
433 }
Fred Drake11916921998-04-02 22:30:57 +0000434 #----------------------------------------------------------------------
Fred Drake64bdc241998-04-17 02:14:12 +0000435 lib_add_bbl_and_idx_dummy_commands()
Fred Drake11916921998-04-02 22:30:57 +0000436 if defined(&lib_add_bbl_and_idx_dummy_commands);
Fred Drakebc7101d1998-03-06 21:18:55 +0000437}
438
439# The bibliographic references, the appendices, the lists of figures and tables
440# etc. must appear in the contents table at the same level as the outermost
441# sectioning command. This subroutine finds what is the outermost level and
442# sets the above to the same level;
443
Fred Drake13210ed1998-03-17 06:28:05 +0000444sub set_depth_levels {
445 # Sets $outermost_level
Fred Drake11916921998-04-02 22:30:57 +0000446 my $level;
Fred Drake13210ed1998-03-17 06:28:05 +0000447 #RRM: do not alter user-set value for $MAX_SPLIT_DEPTH
448 foreach $level ("part", "chapter", "section", "subsection",
449 "subsubsection", "paragraph") {
450 last if (($outermost_level) = /\\($level)$delimiter_rx/);
451 }
452 $level = ($outermost_level ? $section_commands{$outermost_level} :
453 do {$outermost_level = 'section'; 3;});
Fred Drakebc7101d1998-03-06 21:18:55 +0000454
Fred Drake13210ed1998-03-17 06:28:05 +0000455 #RRM: but calculate value for $MAX_SPLIT_DEPTH when a $REL_DEPTH was given
456 if ($REL_DEPTH && $MAX_SPLIT_DEPTH) {
457 $MAX_SPLIT_DEPTH = $level + $MAX_SPLIT_DEPTH;
458 } elsif (!($MAX_SPLIT_DEPTH)) { $MAX_SPLIT_DEPTH = 1 };
Fred Drakebc7101d1998-03-06 21:18:55 +0000459
Fred Drake64bdc241998-04-17 02:14:12 +0000460 %unnumbered_section_commands = ('tableofcontents' => $level,
461 'listoffigures' => $level,
462 'listoftables' => $level,
463 'bibliography' => $level,
464 'textohtmlindex' => $level,
465 'textohtmlmoduleindex' => $level);
466 $section_headings{'textohtmlmoduleindex'} = 'h1';
Fred Drakebc7101d1998-03-06 21:18:55 +0000467
Fred Drake64bdc241998-04-17 02:14:12 +0000468 %section_commands = (%unnumbered_section_commands,
469 %section_commands);
Fred Drake11916921998-04-02 22:30:57 +0000470
471 make_sections_rx();
Fred Drake13210ed1998-03-17 06:28:05 +0000472}
Fred Drakebc7101d1998-03-06 21:18:55 +0000473
474
Fred Drake1072e461998-04-12 02:16:34 +0000475# This changes the markup used for {verbatim} environments, and is the
Fred Drake95474f91999-02-09 18:45:50 +0000476# best way I've found that ensures the <dl> goes on the outside of the
Fred Drake1072e461998-04-12 02:16:34 +0000477# <pre>...</pre>.
478#
479# Note that this *must* be done in the init file, not the python.perl
480# style support file. The %declarations must be set before initialize()
Fred Drakee15956b2000-04-03 04:51:13 +0000481# is called in the main LaTeX2HTML script (which happens before style files
482# are loaded).
Fred Drake1072e461998-04-12 02:16:34 +0000483#
Fred Drakee15956b2000-04-03 04:51:13 +0000484%declarations = ('preform' => '<dl><dd><pre class="verbatim"></pre></dl>',
Fred Drake1072e461998-04-12 02:16:34 +0000485 %declarations);
486
Fred Drakee15956b2000-04-03 04:51:13 +0000487
488# This is added to get rid of the long comment that follows the doctype
489# declaration; MSIE5 on NT4 SP4 barfs on it and drops the content of the
490# page.
491sub make_head_and_body {
Fred Drake85d14c92000-07-31 17:53:45 +0000492 my($title, $body) = @_;
493 my $DTDcomment = '';
494 my($version, $isolanguage) = ($HTML_VERSION, 'EN');
495 my %isolanguages = ( 'english', 'EN' , 'USenglish', 'EN.US'
496 , 'original', 'EN' , 'german' , 'DE'
497 , 'austrian', 'DE.AT', 'french' , 'FR'
498 , 'spanish', 'ES');
Fred Drakee15956b2000-04-03 04:51:13 +0000499 $isolanguage = $isolanguages{$default_language};
500 $isolanguage = 'EN' unless $isolanguage;
501 $title = &purify($title,1);
502 eval("\$title = ". $default_title ) unless ($title);
503
504 # allow user-modification of the <TITLE> tag; thanks Dan Young
505 if (defined &custom_TITLE_hook) {
506 $title = &custom_TITLE_hook($title, $toc_sec_title);
507 }
508
509 if ($DOCTYPE =~ /\/\/[\w\.]+\s*$/) { # language spec included
510 $DTDcomment = "<!DOCTYPE html PUBLIC \"$DOCTYPE\">\n";
511 } else {
512 $DTDcomment = "<!DOCTYPE html PUBLIC \"$DOCTYPE//"
513 . ($ISO_LANGUAGE ? $ISO_LANGUAGE : $isolanguage) . "\">\n";
514 }
515
516 $STYLESHEET = $FILE.".css" unless $STYLESHEET;
517 if (!$charset && $CHARSET) { $charset = $CHARSET; $charset =~ s/_/\-/go; }
518
519 join('', ($DOCTYPE ? $DTDcomment : '' )
520 ,"<html>\n<head>\n<title>", $title, "</title>\n"
521 , &meta_information($title)
522 , ($CHARSET && $HTML_VERSION ge "2.1" ?
523 "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=$charset\">\n"
524 : "" )
525 , ($BASE ? "<base href=\"$BASE\">\n" : "" )
526 , "<link rel=\"STYLESHEET\" href=\"$STYLESHEET\">"
527 , $more_links_mark
528 , "\n</head>\n<body $body>\n");
529}
530
Fred Drakebc7101d1998-03-06 21:18:55 +00005311; # This must be the last line