blob: 4ffcc589f1b6cb5a5abd05b1de0017ec75df87a9 [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 Drake16816272000-09-16 20:40:44 +000028$BODYTEXT = '';
Fred Drakebc7101d1998-03-06 21:18:55 +000029$CHILDLINE = "\n<p><hr>\n";
30$VERBOSITY = 0;
Fred Drakebc7101d1998-03-06 21:18:55 +000031
Fred Drake4d10b431998-08-07 20:51:58 +000032# default # of columns for the indexes
Fred Drakeaa3f9fb1998-08-07 19:52:37 +000033$INDEX_COLUMNS = 2;
Fred Drake2383f6d1999-03-02 16:00:37 +000034$MODULE_INDEX_COLUMNS = 4;
Fred Drakeaa3f9fb1998-08-07 19:52:37 +000035
Fred Drakec9f2c141998-03-11 12:08:21 +000036
Fred Drakedb34a1e1998-03-10 23:02:57 +000037# A little painful, but lets us clean up the top level directory a little,
Fred Drake85d14c92000-07-31 17:53:45 +000038# and not be tied to the current directory (as far as I can tell). Testing
39# an existing definition of $mydir is needed since it cannot be computed when
40# run under mkhowto with recent versions of LaTeX2HTML, since this file is
41# not read directly by LaTeX2HTML any more. mkhowto is required to prepend
42# the required definition at the top of the actual input file.
Fred Drakedb34a1e1998-03-10 23:02:57 +000043#
Fred Drake85d14c92000-07-31 17:53:45 +000044if (!defined $mydir) {
45 use Cwd;
46 use File::Basename;
47 ($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
48 chop $mydir; # remove trailing '/'
49 $mydir = getcwd() . "$dd$mydir"
50 unless $mydir =~ s|^/|/|;
51}
Fred Drakedb34a1e1998-03-10 23:02:57 +000052$LATEX2HTMLSTYLES = "$mydir$envkey$LATEX2HTMLSTYLES";
Fred Drakeb3a3ed81998-07-24 22:17:34 +000053push (@INC, $mydir);
Fred Drakebc7101d1998-03-06 21:18:55 +000054
Fred Drake235e6b11998-03-27 05:19:43 +000055($myrootname, $myrootdir, $myext) = fileparse($mydir, '\..*');
56chop $myrootdir;
57
Fred Drakebc7101d1998-03-06 21:18:55 +000058
Fred Drakea4565b01998-05-15 17:14:17 +000059# Hackish way to get the appropriate paper-*/ directory into $TEXINPUTS;
60# pass in the paper size (a4 or letter) as the environment variable PAPER
61# to add the right directory. If not given, the current directory is
62# added instead for use with HOWTO processing.
63#
64if (defined $ENV{'PAPER'}) {
65 $mytexinputs = "$myrootdir${dd}paper-$ENV{'PAPER'}$envkey";
66}
67else {
68 $mytexinputs = getcwd() . $envkey;
69}
70$mytexinputs .= "$myrootdir${dd}texinputs";
71
72
Fred Drakeb35f2b71999-09-23 16:53:09 +000073# Change this variable to change the text added in "About this document...";
74# this should be an absolute pathname to get it right.
75#
76$ABOUT_FILE = "$myrootdir${dd}html${dd}stdabout.dat";
77
78
Fred Drake85d14c92000-07-31 17:53:45 +000079sub custom_driver_hook {
Fred Drakea4565b01998-05-15 17:14:17 +000080 #
81 # This adds the directory of the main input file to $TEXINPUTS; it
82 # seems to be sufficiently general that it should be fine for HOWTO
83 # processing.
84 #
85 my $file = @_[0];
Fred Drake85d14c92000-07-31 17:53:45 +000086 my($jobname, $dir, $ext) = fileparse($file, '\..*');
87 $dir = L2hos->Make_directory_absolute($dir);
Fred Drakea4565b01998-05-15 17:14:17 +000088 $dir =~ s/$dd$//;
89 $TEXINPUTS = "$dir$envkey$mytexinputs";
Fred Drake85d14c92000-07-31 17:53:45 +000090 print "\nAdding $dir to \$TEXINPUTS\n";
Fred Drake191439a1999-09-22 19:50:51 +000091}
92
Fred Drakea4565b01998-05-15 17:14:17 +000093
Fred Drake85d14c92000-07-31 17:53:45 +000094$CUSTOM_BUTTONS = '';
Fred Drake062bc6e1998-08-13 22:03:46 +000095
Fred Drake85d14c92000-07-31 17:53:45 +000096sub make_nav_sectref {
Fred Drakebeb27bf1999-02-16 17:22:32 +000097 my($label,$title) = @_;
98 if ($title) {
Fred Drake02c70822000-09-19 15:36:19 +000099 if ($title =~ /\<[aA] /) {
100 $title =~ s/\<[aA] /<a class="sectref" /;
101 }
102 else {
103 $title = "<span class=\"sectref\">$title</span>";
104 }
105 return "<b class=\"navlabel\">$label:</b> $title\n";
Fred Drakebeb27bf1999-02-16 17:22:32 +0000106 }
107 return '';
108}
109
Fred Draked18722b2001-01-02 22:08:48 +0000110@my_icon_tags = ();
111$my_icon_tags{'next'} = 'Next Page';
112$my_icon_tags{'next_page'} = 'Next Page';
113$my_icon_tags{'previous'} = 'Previous Page';
114$my_icon_tags{'previous_page'} = 'Previous Page';
115$my_icon_tags{'up'} = 'Up One Level';
116$my_icon_tags{'contents'} = 'Contents';
117$my_icon_tags{'index'} = 'Index';
118$my_icon_tags{'modules'} = 'Module Index';
119
Fred Drakeb31d36c2001-01-04 15:16:01 +0000120@my_icon_names = ();
121$my_icon_names{'previous_page'} = 'previous';
122$my_icon_names{'next_page'} = 'next';
123
Fred Draked18722b2001-01-02 22:08:48 +0000124sub get_my_icon {
125 my $name = @_[0];
126 my $text = $my_icon_tags{$name};
Fred Drakeb31d36c2001-01-04 15:16:01 +0000127 if ($my_icon_names{$name}) {
128 $name = $my_icon_names{$name};
129 }
Fred Draked18722b2001-01-02 22:08:48 +0000130 if ($text eq '') {
131 $name = 'blank';
132 }
Fred Drake85d14c92000-07-31 17:53:45 +0000133 my $iconserver = ($ICONSERVER eq '.') ? '' : "$ICONSERVER/";
Fred Draked18722b2001-01-02 22:08:48 +0000134 return "<img src=\"$iconserver$name.$IMAGE_TYPE\"\n border=\"0\""
Fred Drake85d14c92000-07-31 17:53:45 +0000135 . " height=\"32\"\n alt=\"$text\" width=\"32\">";
136}
137
Fred Drake85d14c92000-07-31 17:53:45 +0000138sub use_my_icon {
139 my $s = @_[0];
Fred Draked18722b2001-01-02 22:08:48 +0000140 if ($s =~ /\<tex2html_([a-z_]+)_visible_mark\>/) {
141 my $r = get_my_icon($1);
142 $s =~ s/\<tex2html_[a-z_]+_visible_mark\>/$r/;
143 }
Fred Drakea0075441999-04-29 19:06:56 +0000144 return $s;
Fred Drake13210ed1998-03-17 06:28:05 +0000145}
146
Fred Drake85d14c92000-07-31 17:53:45 +0000147sub make_nav_panel {
148 my $s;
Fred Draked18722b2001-01-02 22:08:48 +0000149 my $BLANK_ICON = get_my_icon('blank');
Fred Drakef730fc32000-08-31 07:19:07 +0000150 $NEXT = $NEXT_TITLE ? use_my_icon("$NEXT") : $BLANK_ICON;
151 $UP = $UP_TITLE ? use_my_icon("$UP") : $BLANK_ICON;
152 $PREVIOUS = $PREVIOUS_TITLE ? use_my_icon("$PREVIOUS") : $BLANK_ICON;
Fred Drake85d14c92000-07-31 17:53:45 +0000153 $CONTENTS = use_my_icon("$CONTENTS");
154 $INDEX = $INDEX ? use_my_icon("$INDEX") : $BLANK_ICON;
155 if (!$CUSTOM_BUTTONS) {
156 $CUSTOM_BUTTONS = $BLANK_ICON;
157 }
158 $s = ('<table align="center" width="100%" cellpadding="0" cellspacing="2">'
159 . "\n<tr>"
160 # left-hand side
Fred Drake85d14c92000-07-31 17:53:45 +0000161 . "\n<td>$PREVIOUS</td>"
Fred Drake4640e132000-07-31 20:13:23 +0000162 . "\n<td>$UP</td>"
163 . "\n<td>$NEXT</td>"
Fred Drake85d14c92000-07-31 17:53:45 +0000164 # title box
Fred Drakef730fc32000-08-31 07:19:07 +0000165 . "\n<td align=\"center\" width=\"100%\">$t_title</td>"
Fred Drake85d14c92000-07-31 17:53:45 +0000166 # right-hand side
167 . "\n<td>$CONTENTS</td>"
168 . "\n<td>$CUSTOM_BUTTONS</td>" # module index
169 . "\n<td>$INDEX</td>"
170 . "\n</tr></table>\n"
171 # textual navigation
Fred Drake4640e132000-07-31 20:13:23 +0000172 . make_nav_sectref("Previous", $PREVIOUS_TITLE)
Fred Drake85d14c92000-07-31 17:53:45 +0000173 . make_nav_sectref("Up", $UP_TITLE)
Fred Drake4640e132000-07-31 20:13:23 +0000174 . make_nav_sectref("Next", $NEXT_TITLE)
175 );
Fred Drake85d14c92000-07-31 17:53:45 +0000176 # remove these; they are unnecessary and cause errors from validation
177 $s =~ s/ NAME="tex2html\d+"\n */ /g;
178 return $s;
179}
180
Fred Drake7497bd32000-10-25 16:18:10 +0000181sub get_version_text {
182 if ($PACKAGE_VERSION ne '' && $t_date) {
183 return ("<span class=\"release-info\">"
184 . "Release $PACKAGE_VERSION,"
185 . " documentation updated on $t_date.</span>");
186 }
187 if ($PACKAGE_VERSION ne '') {
188 return ("<span class=\"release-info\">"
189 . "Release $PACKAGE_VERSION.</span>");
190 }
191 if ($t_date) {
192 return ("<span class=\"release-info\">Documentation released on "
193 . "$t_date.</span>");
194 }
195 return '';
196}
197
Fred Drake85d14c92000-07-31 17:53:45 +0000198
Fred Drakebc7101d1998-03-06 21:18:55 +0000199sub top_navigation_panel {
Fred Drake7497bd32000-10-25 16:18:10 +0000200 return "\n"
201 . make_nav_panel()
202 . "<br><hr>\n";
Fred Drakebc7101d1998-03-06 21:18:55 +0000203}
204
205sub bot_navigation_panel {
Fred Drake7497bd32000-10-25 16:18:10 +0000206 return "\n<p><hr>\n"
207 . make_nav_panel()
208 . "<hr>\n"
209 . get_version_text()
210 . "\n";
Fred Drake64bdc241998-04-17 02:14:12 +0000211}
212
213sub add_link {
214 # Returns a pair (iconic link, textual link)
215 my($icon, $current_file, @link) = @_;
216 my($dummy, $file, $title) = split($delim,
Fred Drake28e7b4c1998-10-20 18:14:20 +0000217 $section_info{join(' ',@link)});
Fred Draked18722b2001-01-02 22:08:48 +0000218 if ($icon =~ /\<tex2html_([_a-z]+)_visible_mark\>/) {
219 my $r = get_my_icon($1);
220 $icon =~ s/\<tex2html_[_a-z]+_visible_mark\>/$r/;
221 }
Fred Drake64bdc241998-04-17 02:14:12 +0000222 if ($title && ($file ne $current_file)) {
223 $title = purify($title);
224 $title = get_first_words($title, $WORDS_IN_NAVIGATION_PANEL_TITLES);
225 return (make_href($file, $icon), make_href($file, "$title"))
226 }
Fred Draked18722b2001-01-02 22:08:48 +0000227 elsif ($icon eq get_my_icon('up') && $EXTERNAL_UP_LINK) {
Fred Drake64bdc241998-04-17 02:14:12 +0000228 return (make_href($EXTERNAL_UP_LINK, $icon),
229 make_href($EXTERNAL_UP_LINK, "$EXTERNAL_UP_TITLE"))
230 }
Fred Draked18722b2001-01-02 22:08:48 +0000231 elsif ($icon eq get_my_icon('previous')
Fred Drake64bdc241998-04-17 02:14:12 +0000232 && $EXTERNAL_PREV_LINK && $EXTERNAL_PREV_TITLE) {
233 return (make_href($EXTERNAL_PREV_LINK, $icon),
234 make_href($EXTERNAL_PREV_LINK, "$EXTERNAL_PREV_TITLE"))
235 }
Fred Draked18722b2001-01-02 22:08:48 +0000236 elsif ($icon eq get_my_icon('next')
Fred Drake64bdc241998-04-17 02:14:12 +0000237 && $EXTERNAL_DOWN_LINK && $EXTERNAL_DOWN_TITLE) {
238 return (make_href($EXTERNAL_DOWN_LINK, $icon),
239 make_href($EXTERNAL_DOWN_LINK, "$EXTERNAL_DOWN_TITLE"))
240 }
Fred Drake85d14c92000-07-31 17:53:45 +0000241 return (&inactive_img($icon), "");
Fred Drake64bdc241998-04-17 02:14:12 +0000242}
243
244sub add_special_link {
245 my($icon, $file, $current_file) = @_;
Fred Draked18722b2001-01-02 22:08:48 +0000246 if ($icon =~ /\<tex2html_([_a-z]+)_visible_mark\>/) {
247 my $r = get_my_icon($1);
248 $icon =~ s/\<tex2html_[_a-z]+_visible_mark\>/$r/;
249 }
Fred Drake85d14c92000-07-31 17:53:45 +0000250 return (($file && ($file ne $current_file))
251 ? make_href($file, $icon)
252 : undef)
Fred Drake64bdc241998-04-17 02:14:12 +0000253}
254
Fred Drake85d14c92000-07-31 17:53:45 +0000255# The img_tag() function seems only to be called with the parameter
256# 'anchor_invisible_mark', which we want to turn into ''. Since
257# replace_icon_marks() is the only interesting caller, and all it really
258# does is call img_tag(), we can just define the hook alternative to be
259# a no-op instead.
260#
261sub replace_icons_hook {}
Fred Drakebc7101d1998-03-06 21:18:55 +0000262
Fred Drake50cdd971999-02-19 23:04:59 +0000263sub do_cmd_arabic {
264 # get rid of that nasty <SPAN CLASS="arabic">...</SPAN>
Fred Drake85d14c92000-07-31 17:53:45 +0000265 my($ctr, $val, $id, $text) = &read_counter_value(@_[0]);
266 return ($val ? farabic($val) : "0") . $text;
Fred Drake50cdd971999-02-19 23:04:59 +0000267}
268
269
Fred Drakebc7101d1998-03-06 21:18:55 +0000270sub gen_index_id {
271 # this is used to ensure common index key generation and a stable sort
Fred Drake235e6b11998-03-27 05:19:43 +0000272 my($str,$extra) = @_;
Fred Drake64bdc241998-04-17 02:14:12 +0000273 sprintf('%s###%s%010d', $str, $extra, ++$global{'max_id'});
Fred Drakebc7101d1998-03-06 21:18:55 +0000274}
275
Fred Drake85d14c92000-07-31 17:53:45 +0000276sub insert_index {
Fred Drake2383f6d1999-03-02 16:00:37 +0000277 my($mark,$datafile,$columns,$letters,$prefix) = @_;
Fred Drake4d10b431998-08-07 20:51:58 +0000278 my $prog = "$myrootdir/tools/buildindex.py";
279 my $index;
280 if ($letters) {
281 $index = `$prog --columns $columns --letters $datafile`;
282 }
283 else {
284 $index = `$prog --columns $columns $datafile`;
285 }
Fred Drakec5681732000-09-12 20:13:04 +0000286 if (!s/$mark/$prefix$index/) {
287 print "\nCould not locate index mark: $mark";
288 }
Fred Drake64bdc241998-04-17 02:14:12 +0000289}
290
Fred Drake85d14c92000-07-31 17:53:45 +0000291sub add_idx {
Fred Drake9bbdce51999-01-19 16:30:10 +0000292 print "\nBuilding HTML for the index ...";
Fred Drake235e6b11998-03-27 05:19:43 +0000293 close(IDXFILE);
Fred Drake2383f6d1999-03-02 16:00:37 +0000294 insert_index($idx_mark, 'index.dat', $INDEX_COLUMNS, 1, '');
Fred Drake13210ed1998-03-17 06:28:05 +0000295}
Fred Drakebc7101d1998-03-06 21:18:55 +0000296
297
298$idx_module_mark = '<tex2html_idx_module_mark>';
299$idx_module_title = 'Module Index';
300
Fred Drake85d14c92000-07-31 17:53:45 +0000301sub add_module_idx {
Fred Drake9bbdce51999-01-19 16:30:10 +0000302 print "\nBuilding HTML for the module index ...";
Fred Drake235e6b11998-03-27 05:19:43 +0000303 my $key;
Fred Drake2383f6d1999-03-02 16:00:37 +0000304 my $first = 1;
305 my $prevplat = '';
306 my $allthesame = 1;
307 my $prefix = '';
308 foreach $key (keys %Modules) {
309 $key =~ s/<tt>([a-zA-Z0-9._]*)<\/tt>/\1/;
310 my $plat = "$ModulePlatforms{$key}";
311 $plat = ''
Fred Drake62cc3601999-03-04 18:41:17 +0000312 if ($plat eq $IGNORE_PLATFORM_ANNOTATION);
Fred Drake2383f6d1999-03-02 16:00:37 +0000313 if (!$first) {
314 $allthesame = 0
315 if ($prevplat ne $plat);
316 }
317 else { $first = 0; }
318 $prevplat = $plat;
319 }
Fred Drake64bdc241998-04-17 02:14:12 +0000320 open(MODIDXFILE, '>modindex.dat') || die "\n$!\n";
Fred Drake235e6b11998-03-27 05:19:43 +0000321 foreach $key (keys %Modules) {
322 # dump the line in the data file; just use a dummy seqno field
Fred Drake2383f6d1999-03-02 16:00:37 +0000323 my $nkey = $1;
324 my $moditem = "$Modules{$key}";
325 my $plat = '';
326 $key =~ s/<tt>([a-zA-Z0-9._]*)<\/tt>/\1/;
327 if ($ModulePlatforms{$key} && !$allthesame) {
Fred Drakee15956b2000-04-03 04:51:13 +0000328 $plat = (" <em>(<span class='platform'>$ModulePlatforms{$key}"
Fred Drakebb584d31999-03-25 22:18:30 +0000329 . '</span>)</em>');
Fred Drake2383f6d1999-03-02 16:00:37 +0000330 }
Fred Drakee15956b2000-04-03 04:51:13 +0000331 print MODIDXFILE $moditem . $IDXFILE_FIELD_SEP
332 . "<tt class='module'>$key</tt>$plat###\n";
Fred Drakebc7101d1998-03-06 21:18:55 +0000333 }
Fred Drake235e6b11998-03-27 05:19:43 +0000334 close(MODIDXFILE);
Fred Drake2383f6d1999-03-02 16:00:37 +0000335 if (!$allthesame) {
Fred Draked18722b2001-01-02 22:08:48 +0000336 $prefix .= <<PLAT_DISCUSS;
Fred Drake2383f6d1999-03-02 16:00:37 +0000337
338<p> Some module names are followed by an annotation indicating what
339platform they are available on.</p>
340
341PLAT_DISCUSS
342 }
343 insert_index($idx_module_mark, 'modindex.dat', $MODULE_INDEX_COLUMNS, 0,
344 $prefix);
Fred Drakebc7101d1998-03-06 21:18:55 +0000345}
346
Fred Drake235e6b11998-03-27 05:19:43 +0000347# replace both indexes as needed:
Fred Drake85d14c92000-07-31 17:53:45 +0000348sub add_idx_hook {
Fred Drakeb3a3ed81998-07-24 22:17:34 +0000349 add_idx() if (/$idx_mark/);
Fred Drake2383f6d1999-03-02 16:00:37 +0000350 process_python_state();
Fred Drakec5681732000-09-12 20:13:04 +0000351 if ($MODULE_INDEX_FILE) {
352 local ($_);
353 open(MYFILE, "<$MODULE_INDEX_FILE");
354 sysread(MYFILE, $_, 1024*1024);
355 close(MYFILE);
356 add_module_idx();
357 open(MYFILE,">$MODULE_INDEX_FILE");
358 print MYFILE $_;
359 close(MYFILE);
360 }
Fred Drake235e6b11998-03-27 05:19:43 +0000361}
Fred Drakebc7101d1998-03-06 21:18:55 +0000362
Fred Drakebc7101d1998-03-06 21:18:55 +0000363
Fred Drake191439a1999-09-22 19:50:51 +0000364# In addition to the standard stuff, add label to allow named node files and
365# support suppression of the page complete (for HTML Help use).
Fred Drakebc7101d1998-03-06 21:18:55 +0000366sub do_cmd_tableofcontents {
367 local($_) = @_;
368 $TITLE = $toc_title;
369 $tocfile = $CURRENT_FILE;
Fred Drake64bdc241998-04-17 02:14:12 +0000370 my($closures,$reopens) = preserve_open_tags();
371 anchor_label('contents', $CURRENT_FILE, $_); # this is added
Fred Drakebeb27bf1999-02-16 17:22:32 +0000372 join('', "<BR>\n\\tableofchildlinks[off]", $closures
Fred Drake64bdc241998-04-17 02:14:12 +0000373 , make_section_heading($toc_title, 'H2'), $toc_mark
Fred Drakebc7101d1998-03-06 21:18:55 +0000374 , $reopens, $_);
375}
376# In addition to the standard stuff, add label to allow named node files.
377sub do_cmd_listoffigures {
378 local($_) = @_;
379 $TITLE = $lof_title;
380 $loffile = $CURRENT_FILE;
Fred Drake64bdc241998-04-17 02:14:12 +0000381 my($closures,$reopens) = preserve_open_tags();
382 anchor_label('lof', $CURRENT_FILE, $_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000383 join('', "<BR>\n", $closures
Fred Drake64bdc241998-04-17 02:14:12 +0000384 , make_section_heading($lof_title, 'H2'), $lof_mark
Fred Drakebc7101d1998-03-06 21:18:55 +0000385 , $reopens, $_);
386}
387# In addition to the standard stuff, add label to allow named node files.
388sub do_cmd_listoftables {
389 local($_) = @_;
390 $TITLE = $lot_title;
391 $lotfile = $CURRENT_FILE;
Fred Drake64bdc241998-04-17 02:14:12 +0000392 my($closures,$reopens) = preserve_open_tags();
393 anchor_label('lot', $CURRENT_FILE, $_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000394 join('', "<BR>\n", $closures
Fred Drake64bdc241998-04-17 02:14:12 +0000395 , make_section_heading($lot_title, 'H2'), $lot_mark
Fred Drakebc7101d1998-03-06 21:18:55 +0000396 , $reopens, $_);
397}
398# In addition to the standard stuff, add label to allow named node files.
399sub do_cmd_textohtmlinfopage {
400 local($_) = @_;
401 if ($INFO) { #
Fred Drake64bdc241998-04-17 02:14:12 +0000402 anchor_label("about",$CURRENT_FILE,$_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000403 } #
Fred Drake15796f71998-11-30 19:25:47 +0000404 my $the_version = ''; # and the rest is
405 if ($t_date) { # mostly ours
406 $the_version = ",\n$t_date";
Fred Drake7497bd32000-10-25 16:18:10 +0000407 if ($PACKAGE_VERSION) {
408 $the_version .= ", Release $PACKAGE_VERSION";
Fred Drake15796f71998-11-30 19:25:47 +0000409 }
410 }
411 $_ = (($INFO == 1)
Fred Drakeb35f2b71999-09-23 16:53:09 +0000412 ? join('',
413 $close_all,
414 "<strong>$t_title</strong>$the_version\n",
415 `cat $ABOUT_FILE`,
416 $open_all, $_)
417 : join('', $close_all, $INFO,"\n", $open_all, $_));
Fred Drake15796f71998-11-30 19:25:47 +0000418 $_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000419}
420
421# $idx_mark will be replaced with the real index at the end
422sub do_cmd_textohtmlindex {
423 local($_) = @_;
424 $TITLE = $idx_title;
425 $idxfile = $CURRENT_FILE;
Fred Drake235e6b11998-03-27 05:19:43 +0000426 if (%index_labels) { make_index_labels(); }
427 if (($SHORT_INDEX) && (%index_segment)) { make_preindex(); }
Fred Drakebc7101d1998-03-06 21:18:55 +0000428 else { $preindex = ''; }
Fred Drake235e6b11998-03-27 05:19:43 +0000429 my $heading = make_section_heading($idx_title, 'h2') . $idx_mark;
Fred Drake11916921998-04-02 22:30:57 +0000430 my($pre,$post) = minimize_open_tags($heading);
Fred Drake235e6b11998-03-27 05:19:43 +0000431 anchor_label('genindex',$CURRENT_FILE,$_); # this is added
Fred Drakec5681732000-09-12 20:13:04 +0000432 return "<br>\n" . $pre . $_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000433}
434
Fred Drakec5681732000-09-12 20:13:04 +0000435$MODULE_INDEX_FILE = '';
436
Fred Drakebc7101d1998-03-06 21:18:55 +0000437# $idx_module_mark will be replaced with the real index at the end
438sub do_cmd_textohtmlmoduleindex {
439 local($_) = @_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000440 $TITLE = $idx_module_title;
Fred Drakec5681732000-09-12 20:13:04 +0000441 anchor_label('modindex', $CURRENT_FILE, $_);
442 $MODULE_INDEX_FILE = "$CURRENT_FILE";
443 $_ = ('<p>' . make_section_heading($idx_module_title, 'h2')
444 . $idx_module_mark . $_);
445 return $_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000446}
447
Fred Drakec5681732000-09-12 20:13:04 +0000448# The bibliography and the index should be treated as separate
449# sections in their own HTML files. The \bibliography{} command acts
450# as a sectioning command that has the desired effect. But when the
451# bibliography is constructed manually using the thebibliography
452# environment, or when using the theindex environment it is not
453# possible to use the normal sectioning mechanism. This subroutine
454# inserts a \bibliography{} or a dummy \textohtmlindex command just
455# before the appropriate environments to force sectioning.
Fred Drakebc7101d1998-03-06 21:18:55 +0000456
Fred Drakec5681732000-09-12 20:13:04 +0000457# XXX This *assumes* that if there are two {theindex} environments,
458# the first is the module index and the second is the standard
459# index. This is sufficient for the current Python documentation,
460# but that's about it.
Fred Drakebc7101d1998-03-06 21:18:55 +0000461
462sub add_bbl_and_idx_dummy_commands {
Fred Drake11916921998-04-02 22:30:57 +0000463 my $id = $global{'max_id'};
Fred Drakebc7101d1998-03-06 21:18:55 +0000464
465 s/([\\]begin\s*$O\d+$C\s*thebibliography)/$bbl_cnt++; $1/eg;
Fred Drake191439a1999-09-22 19:50:51 +0000466 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 +0000467 my(@parts) = split(/\\begin\s*$O\d+$C\s*theindex/);
468 if (scalar(@parts) == 3) {
469 # Be careful to re-write the string in place, since $_ is *not*
470 # returned explicity; *** nasty side-effect dependency! ***
471 print "\nadd_bbl_and_idx_dummy_commands ==> adding module index";
472 my $rx = "([\\\\]begin\\s*$O\\d+$C\\s*theindex[\\s\\S]*)"
473 . "([\\\\]begin\\s*$O\\d+$C\\s*theindex)";
474 s/$rx/\\textohtmlmoduleindex \1 \\textohtmlindex \2/o;
475 # Add a button to the navigation areas:
Fred Drakeaaa23852000-09-14 22:20:41 +0000476 $CUSTOM_BUTTONS .= ('<a href="modindex.html" title="Module Index">'
Fred Draked18722b2001-01-02 22:08:48 +0000477 . get_my_icon('modules')
Fred Drakeaaa23852000-09-14 22:20:41 +0000478 . '</a>');
Fred Drake11916921998-04-02 22:30:57 +0000479 }
480 else {
Fred Draked18722b2001-01-02 22:08:48 +0000481 $CUSTOM_BUTTONS .= get_my_icon('blank');
Fred Drake85d14c92000-07-31 17:53:45 +0000482 $global{'max_id'} = $id; # not sure why....
483 s/([\\]begin\s*$O\d+$C\s*theindex)/\\textohtmlindex $1/o;
Fred Drake191439a1999-09-22 19:50:51 +0000484 s/[\\]printindex/\\textohtmlindex /o;
485 }
Fred Drake11916921998-04-02 22:30:57 +0000486 #----------------------------------------------------------------------
Fred Drake64bdc241998-04-17 02:14:12 +0000487 lib_add_bbl_and_idx_dummy_commands()
Fred Drake11916921998-04-02 22:30:57 +0000488 if defined(&lib_add_bbl_and_idx_dummy_commands);
Fred Drakebc7101d1998-03-06 21:18:55 +0000489}
490
Fred Drakec5681732000-09-12 20:13:04 +0000491# The bibliographic references, the appendices, the lists of figures
492# and tables etc. must appear in the contents table at the same level
493# as the outermost sectioning command. This subroutine finds what is
494# the outermost level and sets the above to the same level;
Fred Drakebc7101d1998-03-06 21:18:55 +0000495
Fred Drake13210ed1998-03-17 06:28:05 +0000496sub set_depth_levels {
497 # Sets $outermost_level
Fred Drake11916921998-04-02 22:30:57 +0000498 my $level;
Fred Drake13210ed1998-03-17 06:28:05 +0000499 #RRM: do not alter user-set value for $MAX_SPLIT_DEPTH
500 foreach $level ("part", "chapter", "section", "subsection",
501 "subsubsection", "paragraph") {
502 last if (($outermost_level) = /\\($level)$delimiter_rx/);
503 }
504 $level = ($outermost_level ? $section_commands{$outermost_level} :
505 do {$outermost_level = 'section'; 3;});
Fred Drakebc7101d1998-03-06 21:18:55 +0000506
Fred Drake13210ed1998-03-17 06:28:05 +0000507 #RRM: but calculate value for $MAX_SPLIT_DEPTH when a $REL_DEPTH was given
508 if ($REL_DEPTH && $MAX_SPLIT_DEPTH) {
509 $MAX_SPLIT_DEPTH = $level + $MAX_SPLIT_DEPTH;
510 } elsif (!($MAX_SPLIT_DEPTH)) { $MAX_SPLIT_DEPTH = 1 };
Fred Drakebc7101d1998-03-06 21:18:55 +0000511
Fred Drake64bdc241998-04-17 02:14:12 +0000512 %unnumbered_section_commands = ('tableofcontents' => $level,
513 'listoffigures' => $level,
514 'listoftables' => $level,
515 'bibliography' => $level,
516 'textohtmlindex' => $level,
517 'textohtmlmoduleindex' => $level);
518 $section_headings{'textohtmlmoduleindex'} = 'h1';
Fred Drakebc7101d1998-03-06 21:18:55 +0000519
Fred Drake64bdc241998-04-17 02:14:12 +0000520 %section_commands = (%unnumbered_section_commands,
521 %section_commands);
Fred Drake11916921998-04-02 22:30:57 +0000522
523 make_sections_rx();
Fred Drake13210ed1998-03-17 06:28:05 +0000524}
Fred Drakebc7101d1998-03-06 21:18:55 +0000525
526
Fred Drake1072e461998-04-12 02:16:34 +0000527# This changes the markup used for {verbatim} environments, and is the
Fred Drake95474f91999-02-09 18:45:50 +0000528# best way I've found that ensures the <dl> goes on the outside of the
Fred Drake1072e461998-04-12 02:16:34 +0000529# <pre>...</pre>.
530#
531# Note that this *must* be done in the init file, not the python.perl
Fred Drakec5681732000-09-12 20:13:04 +0000532# style support file. The %declarations must be set before
533# initialize() is called in the main LaTeX2HTML script (which happens
534# before style files are loaded).
Fred Drake1072e461998-04-12 02:16:34 +0000535#
Fred Drakee15956b2000-04-03 04:51:13 +0000536%declarations = ('preform' => '<dl><dd><pre class="verbatim"></pre></dl>',
Fred Drake1072e461998-04-12 02:16:34 +0000537 %declarations);
538
Fred Drakee15956b2000-04-03 04:51:13 +0000539
Fred Drakec5681732000-09-12 20:13:04 +0000540# This is added to get rid of the long comment that follows the
541# doctype declaration; MSIE5 on NT4 SP4 barfs on it and drops the
542# content of the page.
Fred Drakee15956b2000-04-03 04:51:13 +0000543sub make_head_and_body {
Fred Drake85d14c92000-07-31 17:53:45 +0000544 my($title, $body) = @_;
Fred Drake16816272000-09-16 20:40:44 +0000545 $body = " $body" unless ($body eq '');
Fred Drake85d14c92000-07-31 17:53:45 +0000546 my $DTDcomment = '';
547 my($version, $isolanguage) = ($HTML_VERSION, 'EN');
548 my %isolanguages = ( 'english', 'EN' , 'USenglish', 'EN.US'
549 , 'original', 'EN' , 'german' , 'DE'
550 , 'austrian', 'DE.AT', 'french' , 'FR'
551 , 'spanish', 'ES');
Fred Drakee15956b2000-04-03 04:51:13 +0000552 $isolanguage = $isolanguages{$default_language};
553 $isolanguage = 'EN' unless $isolanguage;
554 $title = &purify($title,1);
555 eval("\$title = ". $default_title ) unless ($title);
556
557 # allow user-modification of the <TITLE> tag; thanks Dan Young
558 if (defined &custom_TITLE_hook) {
559 $title = &custom_TITLE_hook($title, $toc_sec_title);
560 }
561
562 if ($DOCTYPE =~ /\/\/[\w\.]+\s*$/) { # language spec included
563 $DTDcomment = "<!DOCTYPE html PUBLIC \"$DOCTYPE\">\n";
564 } else {
565 $DTDcomment = "<!DOCTYPE html PUBLIC \"$DOCTYPE//"
566 . ($ISO_LANGUAGE ? $ISO_LANGUAGE : $isolanguage) . "\">\n";
567 }
568
569 $STYLESHEET = $FILE.".css" unless $STYLESHEET;
570 if (!$charset && $CHARSET) { $charset = $CHARSET; $charset =~ s/_/\-/go; }
571
572 join('', ($DOCTYPE ? $DTDcomment : '' )
573 ,"<html>\n<head>\n<title>", $title, "</title>\n"
574 , &meta_information($title)
575 , ($CHARSET && $HTML_VERSION ge "2.1" ?
576 "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=$charset\">\n"
577 : "" )
578 , ($BASE ? "<base href=\"$BASE\">\n" : "" )
579 , "<link rel=\"STYLESHEET\" href=\"$STYLESHEET\">"
580 , $more_links_mark
Fred Drake16816272000-09-16 20:40:44 +0000581 , "\n</head>\n<body$body>");
Fred Drakee15956b2000-04-03 04:51:13 +0000582}
583
Fred Drakebc7101d1998-03-06 21:18:55 +00005841; # This must be the last line