blob: 6e4b0cbead40ca2a1c558a30207ecc57b89fd56f [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
Fred Drake15a159c2002-10-01 15:20:20 +000020$ICONSERVER = '.';
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 Drakea219b412001-10-22 16:57:49 +000036$HAVE_MODULE_INDEX = 0;
37$HAVE_GENERAL_INDEX = 0;
38$HAVE_TABLE_OF_CONTENTS = 0;
39
Fred Drakee03e1fe2002-04-05 17:34:50 +000040$AESOP_META_TYPE = 'information';
41
Fred Drakec9f2c141998-03-11 12:08:21 +000042
Fred Drakedb34a1e1998-03-10 23:02:57 +000043# A little painful, but lets us clean up the top level directory a little,
Fred Drake85d14c92000-07-31 17:53:45 +000044# and not be tied to the current directory (as far as I can tell). Testing
45# an existing definition of $mydir is needed since it cannot be computed when
46# run under mkhowto with recent versions of LaTeX2HTML, since this file is
47# not read directly by LaTeX2HTML any more. mkhowto is required to prepend
48# the required definition at the top of the actual input file.
Fred Drakedb34a1e1998-03-10 23:02:57 +000049#
Fred Drake85d14c92000-07-31 17:53:45 +000050if (!defined $mydir) {
51 use Cwd;
52 use File::Basename;
53 ($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
54 chop $mydir; # remove trailing '/'
55 $mydir = getcwd() . "$dd$mydir"
56 unless $mydir =~ s|^/|/|;
57}
Fred Drakedb34a1e1998-03-10 23:02:57 +000058$LATEX2HTMLSTYLES = "$mydir$envkey$LATEX2HTMLSTYLES";
Fred Drakeb3a3ed81998-07-24 22:17:34 +000059push (@INC, $mydir);
Fred Drakebc7101d1998-03-06 21:18:55 +000060
Fred Drake235e6b11998-03-27 05:19:43 +000061($myrootname, $myrootdir, $myext) = fileparse($mydir, '\..*');
62chop $myrootdir;
63
Fred Drakebc7101d1998-03-06 21:18:55 +000064
Fred Drakea4565b01998-05-15 17:14:17 +000065# Hackish way to get the appropriate paper-*/ directory into $TEXINPUTS;
66# pass in the paper size (a4 or letter) as the environment variable PAPER
67# to add the right directory. If not given, the current directory is
68# added instead for use with HOWTO processing.
69#
70if (defined $ENV{'PAPER'}) {
71 $mytexinputs = "$myrootdir${dd}paper-$ENV{'PAPER'}$envkey";
72}
73else {
74 $mytexinputs = getcwd() . $envkey;
75}
76$mytexinputs .= "$myrootdir${dd}texinputs";
77
78
Fred Drakeb35f2b71999-09-23 16:53:09 +000079# Change this variable to change the text added in "About this document...";
80# this should be an absolute pathname to get it right.
81#
82$ABOUT_FILE = "$myrootdir${dd}html${dd}stdabout.dat";
83
84
Fred Drake85d14c92000-07-31 17:53:45 +000085sub custom_driver_hook {
Fred Drakea4565b01998-05-15 17:14:17 +000086 #
87 # This adds the directory of the main input file to $TEXINPUTS; it
88 # seems to be sufficiently general that it should be fine for HOWTO
89 # processing.
90 #
Fred Drake73c5b6602002-10-24 16:36:05 +000091 my $file = $_[0];
Fred Drake85d14c92000-07-31 17:53:45 +000092 my($jobname, $dir, $ext) = fileparse($file, '\..*');
93 $dir = L2hos->Make_directory_absolute($dir);
Fred Drakea4565b01998-05-15 17:14:17 +000094 $dir =~ s/$dd$//;
95 $TEXINPUTS = "$dir$envkey$mytexinputs";
Fred Drake85d14c92000-07-31 17:53:45 +000096 print "\nAdding $dir to \$TEXINPUTS\n";
Fred Drake191439a1999-09-22 19:50:51 +000097}
98
Fred Drakea4565b01998-05-15 17:14:17 +000099
Fred Drake85d14c92000-07-31 17:53:45 +0000100$CUSTOM_BUTTONS = '';
Fred Drake062bc6e1998-08-13 22:03:46 +0000101
Fred Drakebf8ec3e2003-05-02 20:18:01 +0000102sub make_nav_sectref($$$) {
103 my($label, $linktype, $title) = @_;
Fred Drakebeb27bf1999-02-16 17:22:32 +0000104 if ($title) {
Fred Drake02c70822000-09-19 15:36:19 +0000105 if ($title =~ /\<[aA] /) {
Fred Drakebf8ec3e2003-05-02 20:18:01 +0000106 $title =~ s/\<[aA] /<a class="sectref" rel="$linktype" /;
Fred Drake02c70822000-09-19 15:36:19 +0000107 }
108 else {
109 $title = "<span class=\"sectref\">$title</span>";
110 }
Fred Drakebf8ec3e2003-05-02 20:18:01 +0000111 return "<b class=\"navlabel\">$label:</b>\n$title\n";
Fred Drakebeb27bf1999-02-16 17:22:32 +0000112 }
113 return '';
114}
115
Fred Draked18722b2001-01-02 22:08:48 +0000116@my_icon_tags = ();
117$my_icon_tags{'next'} = 'Next Page';
118$my_icon_tags{'next_page'} = 'Next Page';
119$my_icon_tags{'previous'} = 'Previous Page';
120$my_icon_tags{'previous_page'} = 'Previous Page';
121$my_icon_tags{'up'} = 'Up One Level';
122$my_icon_tags{'contents'} = 'Contents';
123$my_icon_tags{'index'} = 'Index';
124$my_icon_tags{'modules'} = 'Module Index';
125
Fred Drakeb31d36c2001-01-04 15:16:01 +0000126@my_icon_names = ();
127$my_icon_names{'previous_page'} = 'previous';
128$my_icon_names{'next_page'} = 'next';
129
Fred Drakef5478632002-05-23 17:59:16 +0000130sub get_my_icon($) {
Fred Drake73c5b6602002-10-24 16:36:05 +0000131 my $name = $_[0];
Fred Draked18722b2001-01-02 22:08:48 +0000132 my $text = $my_icon_tags{$name};
Fred Drakeb31d36c2001-01-04 15:16:01 +0000133 if ($my_icon_names{$name}) {
134 $name = $my_icon_names{$name};
135 }
Fred Draked18722b2001-01-02 22:08:48 +0000136 if ($text eq '') {
137 $name = 'blank';
138 }
Fred Drake85d14c92000-07-31 17:53:45 +0000139 my $iconserver = ($ICONSERVER eq '.') ? '' : "$ICONSERVER/";
Fred Drakedd3d6a02002-10-30 17:00:58 +0000140 return "<img src='$iconserver$name.$IMAGE_TYPE'\n border='0'"
141 . " height='32' alt='$text' width='32'>";
Fred Drake85d14c92000-07-31 17:53:45 +0000142}
143
Fred Drake05404c32003-05-02 20:30:18 +0000144sub use_my_icon($$) {
145 my($s,$rel) = @_;
Fred Draked18722b2001-01-02 22:08:48 +0000146 if ($s =~ /\<tex2html_([a-z_]+)_visible_mark\>/) {
147 my $r = get_my_icon($1);
148 $s =~ s/\<tex2html_[a-z_]+_visible_mark\>/$r/;
149 }
Fred Drake05404c32003-05-02 20:30:18 +0000150 $s =~ s/<[aA] /<a rel="$rel" /;
Fred Drakea0075441999-04-29 19:06:56 +0000151 return $s;
Fred Drake13210ed1998-03-17 06:28:05 +0000152}
153
Fred Drakef5478632002-05-23 17:59:16 +0000154sub make_nav_panel() {
Fred Drake85d14c92000-07-31 17:53:45 +0000155 my $s;
Fred Draked18722b2001-01-02 22:08:48 +0000156 my $BLANK_ICON = get_my_icon('blank');
Fred Drake05404c32003-05-02 20:30:18 +0000157 $NEXT = $NEXT_TITLE ? use_my_icon("$NEXT", 'next') : $BLANK_ICON;
158 $UP = $UP_TITLE ? use_my_icon("$UP", 'parent') : $BLANK_ICON;
159 $PREVIOUS = ($PREVIOUS_TITLE
160 ? use_my_icon("$PREVIOUS", 'prev') : $BLANK_ICON);
161 $CONTENTS = use_my_icon("$CONTENTS", 'contents');
162 $INDEX = $INDEX ? use_my_icon("$INDEX", 'index') : $BLANK_ICON;
Fred Drake85d14c92000-07-31 17:53:45 +0000163 if (!$CUSTOM_BUTTONS) {
164 $CUSTOM_BUTTONS = $BLANK_ICON;
165 }
166 $s = ('<table align="center" width="100%" cellpadding="0" cellspacing="2">'
167 . "\n<tr>"
168 # left-hand side
Fred Drake85d14c92000-07-31 17:53:45 +0000169 . "\n<td>$PREVIOUS</td>"
Fred Drake4640e132000-07-31 20:13:23 +0000170 . "\n<td>$UP</td>"
171 . "\n<td>$NEXT</td>"
Fred Drake85d14c92000-07-31 17:53:45 +0000172 # title box
Fred Drakef730fc32000-08-31 07:19:07 +0000173 . "\n<td align=\"center\" width=\"100%\">$t_title</td>"
Fred Drake85d14c92000-07-31 17:53:45 +0000174 # right-hand side
175 . "\n<td>$CONTENTS</td>"
176 . "\n<td>$CUSTOM_BUTTONS</td>" # module index
177 . "\n<td>$INDEX</td>"
178 . "\n</tr></table>\n"
179 # textual navigation
Fred Drakebf8ec3e2003-05-02 20:18:01 +0000180 . make_nav_sectref("Previous", "prev", $PREVIOUS_TITLE)
181 . make_nav_sectref("Up", "parent", $UP_TITLE)
182 . make_nav_sectref("Next", "next", $NEXT_TITLE)
Fred Drake4640e132000-07-31 20:13:23 +0000183 );
Fred Drake85d14c92000-07-31 17:53:45 +0000184 # remove these; they are unnecessary and cause errors from validation
185 $s =~ s/ NAME="tex2html\d+"\n */ /g;
186 return $s;
187}
188
Fred Drakefb6499f2001-10-26 14:16:23 +0000189sub add_child_links {
190 my $toc = add_real_child_links(@_);
191 $toc =~ s|\s*</[aA]>|</a>|g;
192 $toc =~ s/ NAME=\"tex2html\d+\"\s*href=/ href=/gi;
193 $toc =~ s|</UL>(\s*<BR>)?|</ul>|gi;
194 return $toc;
195}
196
Fred Drakef5478632002-05-23 17:59:16 +0000197sub get_version_text() {
Fred Drake7497bd32000-10-25 16:18:10 +0000198 if ($PACKAGE_VERSION ne '' && $t_date) {
199 return ("<span class=\"release-info\">"
Fred Drakedce975c2001-06-20 21:31:36 +0000200 . "Release $PACKAGE_VERSION$RELEASE_INFO,"
Fred Drake7497bd32000-10-25 16:18:10 +0000201 . " documentation updated on $t_date.</span>");
202 }
203 if ($PACKAGE_VERSION ne '') {
204 return ("<span class=\"release-info\">"
Fred Drakedce975c2001-06-20 21:31:36 +0000205 . "Release $PACKAGE_VERSION$RELEASE_INFO.</span>");
Fred Drake7497bd32000-10-25 16:18:10 +0000206 }
207 if ($t_date) {
208 return ("<span class=\"release-info\">Documentation released on "
209 . "$t_date.</span>");
210 }
211 return '';
212}
213
Fred Drake85d14c92000-07-31 17:53:45 +0000214
Fred Drakef5478632002-05-23 17:59:16 +0000215sub top_navigation_panel() {
Fred Drake7497bd32000-10-25 16:18:10 +0000216 return "\n"
217 . make_nav_panel()
218 . "<br><hr>\n";
Fred Drakebc7101d1998-03-06 21:18:55 +0000219}
220
Fred Drakef5478632002-05-23 17:59:16 +0000221sub bot_navigation_panel() {
Fred Drake7497bd32000-10-25 16:18:10 +0000222 return "\n<p><hr>\n"
223 . make_nav_panel()
224 . "<hr>\n"
225 . get_version_text()
226 . "\n";
Fred Drake64bdc241998-04-17 02:14:12 +0000227}
228
229sub add_link {
230 # Returns a pair (iconic link, textual link)
231 my($icon, $current_file, @link) = @_;
232 my($dummy, $file, $title) = split($delim,
Fred Drake28e7b4c1998-10-20 18:14:20 +0000233 $section_info{join(' ',@link)});
Fred Draked18722b2001-01-02 22:08:48 +0000234 if ($icon =~ /\<tex2html_([_a-z]+)_visible_mark\>/) {
235 my $r = get_my_icon($1);
236 $icon =~ s/\<tex2html_[_a-z]+_visible_mark\>/$r/;
237 }
Fred Drake64bdc241998-04-17 02:14:12 +0000238 if ($title && ($file ne $current_file)) {
239 $title = purify($title);
240 $title = get_first_words($title, $WORDS_IN_NAVIGATION_PANEL_TITLES);
241 return (make_href($file, $icon), make_href($file, "$title"))
242 }
Fred Draked18722b2001-01-02 22:08:48 +0000243 elsif ($icon eq get_my_icon('up') && $EXTERNAL_UP_LINK) {
Fred Drake64bdc241998-04-17 02:14:12 +0000244 return (make_href($EXTERNAL_UP_LINK, $icon),
245 make_href($EXTERNAL_UP_LINK, "$EXTERNAL_UP_TITLE"))
246 }
Fred Draked18722b2001-01-02 22:08:48 +0000247 elsif ($icon eq get_my_icon('previous')
Fred Drake64bdc241998-04-17 02:14:12 +0000248 && $EXTERNAL_PREV_LINK && $EXTERNAL_PREV_TITLE) {
249 return (make_href($EXTERNAL_PREV_LINK, $icon),
250 make_href($EXTERNAL_PREV_LINK, "$EXTERNAL_PREV_TITLE"))
251 }
Fred Draked18722b2001-01-02 22:08:48 +0000252 elsif ($icon eq get_my_icon('next')
Fred Drake64bdc241998-04-17 02:14:12 +0000253 && $EXTERNAL_DOWN_LINK && $EXTERNAL_DOWN_TITLE) {
254 return (make_href($EXTERNAL_DOWN_LINK, $icon),
255 make_href($EXTERNAL_DOWN_LINK, "$EXTERNAL_DOWN_TITLE"))
256 }
Fred Drake85d14c92000-07-31 17:53:45 +0000257 return (&inactive_img($icon), "");
Fred Drake64bdc241998-04-17 02:14:12 +0000258}
259
Fred Drakef5478632002-05-23 17:59:16 +0000260sub add_special_link($$$) {
Fred Drake64bdc241998-04-17 02:14:12 +0000261 my($icon, $file, $current_file) = @_;
Fred Draked18722b2001-01-02 22:08:48 +0000262 if ($icon =~ /\<tex2html_([_a-z]+)_visible_mark\>/) {
263 my $r = get_my_icon($1);
264 $icon =~ s/\<tex2html_[_a-z]+_visible_mark\>/$r/;
265 }
Fred Drake85d14c92000-07-31 17:53:45 +0000266 return (($file && ($file ne $current_file))
267 ? make_href($file, $icon)
268 : undef)
Fred Drake64bdc241998-04-17 02:14:12 +0000269}
270
Fred Drake85d14c92000-07-31 17:53:45 +0000271# The img_tag() function seems only to be called with the parameter
272# 'anchor_invisible_mark', which we want to turn into ''. Since
273# replace_icon_marks() is the only interesting caller, and all it really
274# does is call img_tag(), we can just define the hook alternative to be
275# a no-op instead.
276#
277sub replace_icons_hook {}
Fred Drakebc7101d1998-03-06 21:18:55 +0000278
Fred Drake50cdd971999-02-19 23:04:59 +0000279sub do_cmd_arabic {
280 # get rid of that nasty <SPAN CLASS="arabic">...</SPAN>
Fred Drake73c5b6602002-10-24 16:36:05 +0000281 my($ctr, $val, $id, $text) = &read_counter_value($_[0]);
Fred Drake85d14c92000-07-31 17:53:45 +0000282 return ($val ? farabic($val) : "0") . $text;
Fred Drake50cdd971999-02-19 23:04:59 +0000283}
284
285
Fred Drakef5478632002-05-23 17:59:16 +0000286sub gen_index_id($$) {
Fred Drakebc7101d1998-03-06 21:18:55 +0000287 # this is used to ensure common index key generation and a stable sort
Fred Drakef5478632002-05-23 17:59:16 +0000288 my($str, $extra) = @_;
Fred Drake64bdc241998-04-17 02:14:12 +0000289 sprintf('%s###%s%010d', $str, $extra, ++$global{'max_id'});
Fred Drakebc7101d1998-03-06 21:18:55 +0000290}
291
Fred Drakef5478632002-05-23 17:59:16 +0000292sub insert_index($$$$$) {
293 my($mark, $datafile, $columns, $letters, $prefix) = @_;
Fred Drake4d10b431998-08-07 20:51:58 +0000294 my $prog = "$myrootdir/tools/buildindex.py";
295 my $index;
296 if ($letters) {
297 $index = `$prog --columns $columns --letters $datafile`;
298 }
299 else {
300 $index = `$prog --columns $columns $datafile`;
301 }
Fred Drakec5681732000-09-12 20:13:04 +0000302 if (!s/$mark/$prefix$index/) {
303 print "\nCould not locate index mark: $mark";
304 }
Fred Drake64bdc241998-04-17 02:14:12 +0000305}
306
Fred Drakef5478632002-05-23 17:59:16 +0000307sub add_idx() {
Fred Drake9bbdce51999-01-19 16:30:10 +0000308 print "\nBuilding HTML for the index ...";
Fred Drake235e6b11998-03-27 05:19:43 +0000309 close(IDXFILE);
Fred Drake2383f6d1999-03-02 16:00:37 +0000310 insert_index($idx_mark, 'index.dat', $INDEX_COLUMNS, 1, '');
Fred Drake13210ed1998-03-17 06:28:05 +0000311}
Fred Drakebc7101d1998-03-06 21:18:55 +0000312
313
314$idx_module_mark = '<tex2html_idx_module_mark>';
315$idx_module_title = 'Module Index';
316
Fred Drakef5478632002-05-23 17:59:16 +0000317sub add_module_idx() {
Fred Drake9bbdce51999-01-19 16:30:10 +0000318 print "\nBuilding HTML for the module index ...";
Fred Drake235e6b11998-03-27 05:19:43 +0000319 my $key;
Fred Drake2383f6d1999-03-02 16:00:37 +0000320 my $first = 1;
321 my $prevplat = '';
322 my $allthesame = 1;
323 my $prefix = '';
324 foreach $key (keys %Modules) {
Fred Drake73c5b6602002-10-24 16:36:05 +0000325 $key =~ s/<tt>([a-zA-Z0-9._]*)<\/tt>/$1/;
Fred Drake2383f6d1999-03-02 16:00:37 +0000326 my $plat = "$ModulePlatforms{$key}";
327 $plat = ''
Fred Drake62cc3601999-03-04 18:41:17 +0000328 if ($plat eq $IGNORE_PLATFORM_ANNOTATION);
Fred Drake2383f6d1999-03-02 16:00:37 +0000329 if (!$first) {
330 $allthesame = 0
331 if ($prevplat ne $plat);
332 }
333 else { $first = 0; }
334 $prevplat = $plat;
335 }
Fred Drake64bdc241998-04-17 02:14:12 +0000336 open(MODIDXFILE, '>modindex.dat') || die "\n$!\n";
Fred Drake235e6b11998-03-27 05:19:43 +0000337 foreach $key (keys %Modules) {
338 # dump the line in the data file; just use a dummy seqno field
Fred Drake2383f6d1999-03-02 16:00:37 +0000339 my $nkey = $1;
340 my $moditem = "$Modules{$key}";
341 my $plat = '';
Fred Drake73c5b6602002-10-24 16:36:05 +0000342 $key =~ s/<tt>([a-zA-Z0-9._]*)<\/tt>/$1/;
Fred Drake2383f6d1999-03-02 16:00:37 +0000343 if ($ModulePlatforms{$key} && !$allthesame) {
Fred Drakedce975c2001-06-20 21:31:36 +0000344 $plat = (" <em>(<span class=\"platform\">$ModulePlatforms{$key}"
Fred Drakebb584d31999-03-25 22:18:30 +0000345 . '</span>)</em>');
Fred Drake2383f6d1999-03-02 16:00:37 +0000346 }
Fred Drakee15956b2000-04-03 04:51:13 +0000347 print MODIDXFILE $moditem . $IDXFILE_FIELD_SEP
Fred Drakedce975c2001-06-20 21:31:36 +0000348 . "<tt class=\"module\">$key</tt>$plat###\n";
Fred Drakebc7101d1998-03-06 21:18:55 +0000349 }
Fred Drake235e6b11998-03-27 05:19:43 +0000350 close(MODIDXFILE);
Fred Drake42181db2001-01-09 22:02:10 +0000351
352 if ($GLOBAL_MODULE_INDEX) {
353 $prefix = <<MODULE_INDEX_PREFIX;
354
355<p> This index only lists modules documented in this manual.
356 The <em class="citetitle"><a href="$GLOBAL_MODULE_INDEX">Global Module
357 Index</a></em> lists all modules that are documented in this set
358 of manuals.</p>
359MODULE_INDEX_PREFIX
360 }
Fred Drake2383f6d1999-03-02 16:00:37 +0000361 if (!$allthesame) {
Fred Draked18722b2001-01-02 22:08:48 +0000362 $prefix .= <<PLAT_DISCUSS;
Fred Drake2383f6d1999-03-02 16:00:37 +0000363
364<p> Some module names are followed by an annotation indicating what
365platform they are available on.</p>
366
367PLAT_DISCUSS
368 }
369 insert_index($idx_module_mark, 'modindex.dat', $MODULE_INDEX_COLUMNS, 0,
370 $prefix);
Fred Drakebc7101d1998-03-06 21:18:55 +0000371}
372
Fred Drake235e6b11998-03-27 05:19:43 +0000373# replace both indexes as needed:
Fred Drake85d14c92000-07-31 17:53:45 +0000374sub add_idx_hook {
Fred Drakeb3a3ed81998-07-24 22:17:34 +0000375 add_idx() if (/$idx_mark/);
Fred Drake2383f6d1999-03-02 16:00:37 +0000376 process_python_state();
Fred Drakec5681732000-09-12 20:13:04 +0000377 if ($MODULE_INDEX_FILE) {
378 local ($_);
379 open(MYFILE, "<$MODULE_INDEX_FILE");
380 sysread(MYFILE, $_, 1024*1024);
381 close(MYFILE);
382 add_module_idx();
383 open(MYFILE,">$MODULE_INDEX_FILE");
384 print MYFILE $_;
385 close(MYFILE);
386 }
Fred Drake235e6b11998-03-27 05:19:43 +0000387}
Fred Drakebc7101d1998-03-06 21:18:55 +0000388
Fred Drakebc7101d1998-03-06 21:18:55 +0000389
Fred Drake191439a1999-09-22 19:50:51 +0000390# In addition to the standard stuff, add label to allow named node files and
391# support suppression of the page complete (for HTML Help use).
Fred Drakebc7101d1998-03-06 21:18:55 +0000392sub do_cmd_tableofcontents {
393 local($_) = @_;
394 $TITLE = $toc_title;
395 $tocfile = $CURRENT_FILE;
Fred Drakef5478632002-05-23 17:59:16 +0000396 my($closures, $reopens) = preserve_open_tags();
Fred Drake64bdc241998-04-17 02:14:12 +0000397 anchor_label('contents', $CURRENT_FILE, $_); # this is added
Fred Drakebeb27bf1999-02-16 17:22:32 +0000398 join('', "<BR>\n\\tableofchildlinks[off]", $closures
Fred Drake64bdc241998-04-17 02:14:12 +0000399 , make_section_heading($toc_title, 'H2'), $toc_mark
Fred Drakebc7101d1998-03-06 21:18:55 +0000400 , $reopens, $_);
401}
402# In addition to the standard stuff, add label to allow named node files.
403sub do_cmd_listoffigures {
404 local($_) = @_;
405 $TITLE = $lof_title;
406 $loffile = $CURRENT_FILE;
Fred Drakef5478632002-05-23 17:59:16 +0000407 my($closures, $reopens) = preserve_open_tags();
Fred Drake64bdc241998-04-17 02:14:12 +0000408 anchor_label('lof', $CURRENT_FILE, $_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000409 join('', "<BR>\n", $closures
Fred Drake64bdc241998-04-17 02:14:12 +0000410 , make_section_heading($lof_title, 'H2'), $lof_mark
Fred Drakebc7101d1998-03-06 21:18:55 +0000411 , $reopens, $_);
412}
413# In addition to the standard stuff, add label to allow named node files.
414sub do_cmd_listoftables {
415 local($_) = @_;
416 $TITLE = $lot_title;
417 $lotfile = $CURRENT_FILE;
Fred Drakef5478632002-05-23 17:59:16 +0000418 my($closures, $reopens) = preserve_open_tags();
Fred Drake64bdc241998-04-17 02:14:12 +0000419 anchor_label('lot', $CURRENT_FILE, $_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000420 join('', "<BR>\n", $closures
Fred Drake64bdc241998-04-17 02:14:12 +0000421 , make_section_heading($lot_title, 'H2'), $lot_mark
Fred Drakebc7101d1998-03-06 21:18:55 +0000422 , $reopens, $_);
423}
424# In addition to the standard stuff, add label to allow named node files.
425sub do_cmd_textohtmlinfopage {
426 local($_) = @_;
427 if ($INFO) { #
Fred Drake64bdc241998-04-17 02:14:12 +0000428 anchor_label("about",$CURRENT_FILE,$_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000429 } #
Fred Drake15796f71998-11-30 19:25:47 +0000430 my $the_version = ''; # and the rest is
431 if ($t_date) { # mostly ours
432 $the_version = ",\n$t_date";
Fred Drake7497bd32000-10-25 16:18:10 +0000433 if ($PACKAGE_VERSION) {
Fred Drakedce975c2001-06-20 21:31:36 +0000434 $the_version .= ", Release $PACKAGE_VERSION$RELEASE_INFO";
Fred Drake15796f71998-11-30 19:25:47 +0000435 }
436 }
Fred Drake9443dc32001-08-10 20:12:09 +0000437 my $about;
438 open(ABOUT, "<$ABOUT_FILE") || die "\n$!\n";
439 sysread(ABOUT, $about, 1024*1024);
440 close(ABOUT);
Fred Drake15796f71998-11-30 19:25:47 +0000441 $_ = (($INFO == 1)
Fred Drakeb35f2b71999-09-23 16:53:09 +0000442 ? join('',
443 $close_all,
444 "<strong>$t_title</strong>$the_version\n",
Fred Drake9443dc32001-08-10 20:12:09 +0000445 $about,
Fred Drakeb35f2b71999-09-23 16:53:09 +0000446 $open_all, $_)
447 : join('', $close_all, $INFO,"\n", $open_all, $_));
Fred Drake15796f71998-11-30 19:25:47 +0000448 $_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000449}
450
451# $idx_mark will be replaced with the real index at the end
452sub do_cmd_textohtmlindex {
453 local($_) = @_;
454 $TITLE = $idx_title;
455 $idxfile = $CURRENT_FILE;
Fred Drake235e6b11998-03-27 05:19:43 +0000456 if (%index_labels) { make_index_labels(); }
457 if (($SHORT_INDEX) && (%index_segment)) { make_preindex(); }
Fred Drakebc7101d1998-03-06 21:18:55 +0000458 else { $preindex = ''; }
Fred Drake235e6b11998-03-27 05:19:43 +0000459 my $heading = make_section_heading($idx_title, 'h2') . $idx_mark;
Fred Drakef5478632002-05-23 17:59:16 +0000460 my($pre, $post) = minimize_open_tags($heading);
Fred Drake235e6b11998-03-27 05:19:43 +0000461 anchor_label('genindex',$CURRENT_FILE,$_); # this is added
Fred Drakec5681732000-09-12 20:13:04 +0000462 return "<br>\n" . $pre . $_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000463}
464
Fred Drakec5681732000-09-12 20:13:04 +0000465$MODULE_INDEX_FILE = '';
466
Fred Drakebc7101d1998-03-06 21:18:55 +0000467# $idx_module_mark will be replaced with the real index at the end
468sub do_cmd_textohtmlmoduleindex {
469 local($_) = @_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000470 $TITLE = $idx_module_title;
Fred Drakec5681732000-09-12 20:13:04 +0000471 anchor_label('modindex', $CURRENT_FILE, $_);
472 $MODULE_INDEX_FILE = "$CURRENT_FILE";
473 $_ = ('<p>' . make_section_heading($idx_module_title, 'h2')
474 . $idx_module_mark . $_);
475 return $_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000476}
477
Fred Drakec5681732000-09-12 20:13:04 +0000478# The bibliography and the index should be treated as separate
479# sections in their own HTML files. The \bibliography{} command acts
480# as a sectioning command that has the desired effect. But when the
481# bibliography is constructed manually using the thebibliography
482# environment, or when using the theindex environment it is not
483# possible to use the normal sectioning mechanism. This subroutine
484# inserts a \bibliography{} or a dummy \textohtmlindex command just
485# before the appropriate environments to force sectioning.
Fred Drakebc7101d1998-03-06 21:18:55 +0000486
Fred Drakec5681732000-09-12 20:13:04 +0000487# XXX This *assumes* that if there are two {theindex} environments,
488# the first is the module index and the second is the standard
489# index. This is sufficient for the current Python documentation,
490# but that's about it.
Fred Drakebc7101d1998-03-06 21:18:55 +0000491
492sub add_bbl_and_idx_dummy_commands {
Fred Drake11916921998-04-02 22:30:57 +0000493 my $id = $global{'max_id'};
Fred Drakebc7101d1998-03-06 21:18:55 +0000494
Fred Drakea219b412001-10-22 16:57:49 +0000495 if (/[\\]tableofcontents/) {
496 $HAVE_TABLE_OF_CONTENTS = 1;
497 }
Fred Drakebc7101d1998-03-06 21:18:55 +0000498 s/([\\]begin\s*$O\d+$C\s*thebibliography)/$bbl_cnt++; $1/eg;
Fred Drake191439a1999-09-22 19:50:51 +0000499 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 +0000500 my(@parts) = split(/\\begin\s*$O\d+$C\s*theindex/);
501 if (scalar(@parts) == 3) {
502 # Be careful to re-write the string in place, since $_ is *not*
503 # returned explicity; *** nasty side-effect dependency! ***
Fred Drakebb7775a2001-12-04 17:03:54 +0000504 print "\nadd_bbl_and_idx_dummy_commands ==> adding general index";
Fred Drake85d14c92000-07-31 17:53:45 +0000505 print "\nadd_bbl_and_idx_dummy_commands ==> adding module index";
506 my $rx = "([\\\\]begin\\s*$O\\d+$C\\s*theindex[\\s\\S]*)"
507 . "([\\\\]begin\\s*$O\\d+$C\\s*theindex)";
Fred Drake73c5b6602002-10-24 16:36:05 +0000508 s/$rx/\\textohtmlmoduleindex $1 \\textohtmlindex $2/o;
Fred Drake85d14c92000-07-31 17:53:45 +0000509 # Add a button to the navigation areas:
Fred Drakeaaa23852000-09-14 22:20:41 +0000510 $CUSTOM_BUTTONS .= ('<a href="modindex.html" title="Module Index">'
Fred Draked18722b2001-01-02 22:08:48 +0000511 . get_my_icon('modules')
Fred Drakeaaa23852000-09-14 22:20:41 +0000512 . '</a>');
Fred Drakea219b412001-10-22 16:57:49 +0000513 $HAVE_MODULE_INDEX = 1;
514 $HAVE_GENERAL_INDEX = 1;
515 }
516 elsif (scalar(@parts) == 2) {
Fred Drakebb7775a2001-12-04 17:03:54 +0000517 print "\nadd_bbl_and_idx_dummy_commands ==> adding general index";
518 my $rx = "([\\\\]begin\\s*$O\\d+$C\\s*theindex)";
Fred Drake73c5b6602002-10-24 16:36:05 +0000519 s/$rx/\\textohtmlindex $1/o;
Fred Drakea219b412001-10-22 16:57:49 +0000520 $HAVE_GENERAL_INDEX = 1;
Fred Drake11916921998-04-02 22:30:57 +0000521 }
Fred Drakebb7775a2001-12-04 17:03:54 +0000522 elsif (scalar(@parts) == 1) {
523 print "\nadd_bbl_and_idx_dummy_commands ==> no index found";
Fred Draked18722b2001-01-02 22:08:48 +0000524 $CUSTOM_BUTTONS .= get_my_icon('blank');
Fred Drake85d14c92000-07-31 17:53:45 +0000525 $global{'max_id'} = $id; # not sure why....
526 s/([\\]begin\s*$O\d+$C\s*theindex)/\\textohtmlindex $1/o;
Fred Drake191439a1999-09-22 19:50:51 +0000527 s/[\\]printindex/\\textohtmlindex /o;
Fred Drakebb7775a2001-12-04 17:03:54 +0000528 }
529 else {
530 die "\n\nBad number of index environments!\n\n";
531 }
Fred Drake11916921998-04-02 22:30:57 +0000532 #----------------------------------------------------------------------
Fred Drake64bdc241998-04-17 02:14:12 +0000533 lib_add_bbl_and_idx_dummy_commands()
Fred Drake11916921998-04-02 22:30:57 +0000534 if defined(&lib_add_bbl_and_idx_dummy_commands);
Fred Drakebc7101d1998-03-06 21:18:55 +0000535}
536
Fred Drakec5681732000-09-12 20:13:04 +0000537# The bibliographic references, the appendices, the lists of figures
538# and tables etc. must appear in the contents table at the same level
539# as the outermost sectioning command. This subroutine finds what is
540# the outermost level and sets the above to the same level;
Fred Drakebc7101d1998-03-06 21:18:55 +0000541
Fred Drake13210ed1998-03-17 06:28:05 +0000542sub set_depth_levels {
543 # Sets $outermost_level
Fred Drake11916921998-04-02 22:30:57 +0000544 my $level;
Fred Drake13210ed1998-03-17 06:28:05 +0000545 #RRM: do not alter user-set value for $MAX_SPLIT_DEPTH
546 foreach $level ("part", "chapter", "section", "subsection",
547 "subsubsection", "paragraph") {
548 last if (($outermost_level) = /\\($level)$delimiter_rx/);
549 }
550 $level = ($outermost_level ? $section_commands{$outermost_level} :
551 do {$outermost_level = 'section'; 3;});
Fred Drakebc7101d1998-03-06 21:18:55 +0000552
Fred Drake13210ed1998-03-17 06:28:05 +0000553 #RRM: but calculate value for $MAX_SPLIT_DEPTH when a $REL_DEPTH was given
554 if ($REL_DEPTH && $MAX_SPLIT_DEPTH) {
555 $MAX_SPLIT_DEPTH = $level + $MAX_SPLIT_DEPTH;
556 } elsif (!($MAX_SPLIT_DEPTH)) { $MAX_SPLIT_DEPTH = 1 };
Fred Drakebc7101d1998-03-06 21:18:55 +0000557
Fred Drake64bdc241998-04-17 02:14:12 +0000558 %unnumbered_section_commands = ('tableofcontents' => $level,
559 'listoffigures' => $level,
560 'listoftables' => $level,
561 'bibliography' => $level,
562 'textohtmlindex' => $level,
563 'textohtmlmoduleindex' => $level);
564 $section_headings{'textohtmlmoduleindex'} = 'h1';
Fred Drakebc7101d1998-03-06 21:18:55 +0000565
Fred Drake64bdc241998-04-17 02:14:12 +0000566 %section_commands = (%unnumbered_section_commands,
567 %section_commands);
Fred Drake11916921998-04-02 22:30:57 +0000568
569 make_sections_rx();
Fred Drake13210ed1998-03-17 06:28:05 +0000570}
Fred Drakebc7101d1998-03-06 21:18:55 +0000571
572
Fred Drake1072e461998-04-12 02:16:34 +0000573# This changes the markup used for {verbatim} environments, and is the
Fred Drake95474f91999-02-09 18:45:50 +0000574# best way I've found that ensures the <dl> goes on the outside of the
Fred Drake1072e461998-04-12 02:16:34 +0000575# <pre>...</pre>.
576#
577# Note that this *must* be done in the init file, not the python.perl
Fred Drakec5681732000-09-12 20:13:04 +0000578# style support file. The %declarations must be set before
579# initialize() is called in the main LaTeX2HTML script (which happens
580# before style files are loaded).
Fred Drake1072e461998-04-12 02:16:34 +0000581#
Fred Drake8a5e6792002-04-15 18:41:31 +0000582%declarations = ('preform' => '<div class="verbatim"><pre></pre></div>',
Fred Drake1072e461998-04-12 02:16:34 +0000583 %declarations);
584
Fred Drakee15956b2000-04-03 04:51:13 +0000585
Fred Drakebf8ec3e2003-05-02 20:18:01 +0000586# This is used to map the link rel attributes LaTeX2HTML uses to those
587# currently recommended by the W3C.
588sub custom_REL_hook {
589 my($rel,$junk) = @_;
590 return 'parent' if $rel eq 'up';
591 return 'prev' if $rel eq 'previous';
592 return $rel;
593}
594
Fred Drakec5681732000-09-12 20:13:04 +0000595# This is added to get rid of the long comment that follows the
596# doctype declaration; MSIE5 on NT4 SP4 barfs on it and drops the
597# content of the page.
Fred Drakea219b412001-10-22 16:57:49 +0000598$MY_PARTIAL_HEADER = '';
Fred Drakef5478632002-05-23 17:59:16 +0000599sub make_head_and_body($$) {
Fred Drake85d14c92000-07-31 17:53:45 +0000600 my($title, $body) = @_;
Fred Drake16816272000-09-16 20:40:44 +0000601 $body = " $body" unless ($body eq '');
Fred Drake85d14c92000-07-31 17:53:45 +0000602 my $DTDcomment = '';
603 my($version, $isolanguage) = ($HTML_VERSION, 'EN');
604 my %isolanguages = ( 'english', 'EN' , 'USenglish', 'EN.US'
605 , 'original', 'EN' , 'german' , 'DE'
606 , 'austrian', 'DE.AT', 'french' , 'FR'
607 , 'spanish', 'ES');
Fred Drakee15956b2000-04-03 04:51:13 +0000608 $isolanguage = $isolanguages{$default_language};
609 $isolanguage = 'EN' unless $isolanguage;
610 $title = &purify($title,1);
611 eval("\$title = ". $default_title ) unless ($title);
612
613 # allow user-modification of the <TITLE> tag; thanks Dan Young
614 if (defined &custom_TITLE_hook) {
615 $title = &custom_TITLE_hook($title, $toc_sec_title);
616 }
617
618 if ($DOCTYPE =~ /\/\/[\w\.]+\s*$/) { # language spec included
619 $DTDcomment = "<!DOCTYPE html PUBLIC \"$DOCTYPE\">\n";
620 } else {
621 $DTDcomment = "<!DOCTYPE html PUBLIC \"$DOCTYPE//"
622 . ($ISO_LANGUAGE ? $ISO_LANGUAGE : $isolanguage) . "\">\n";
623 }
Fred Drakea219b412001-10-22 16:57:49 +0000624 if ($MY_PARTIAL_HEADER eq '') {
625 $STYLESHEET = $FILE.".css" unless $STYLESHEET;
626 $MY_PARTIAL_HEADER = join('',
Fred Drakedd3d6a02002-10-30 17:00:58 +0000627 ($DOCTYPE ? $DTDcomment : ''),
Fred Drake98b25762003-05-02 18:21:22 +0000628 "<html>\n<head>",
629 ($BASE ? "\n<base href=\"$BASE\">" : ''),
630 "\n<link rel=\"STYLESHEET\" href=\"$STYLESHEET\" type='text/css'>",
Fred Drakedd3d6a02002-10-30 17:00:58 +0000631 ($FAVORITES_ICON
Fred Drake98b25762003-05-02 18:21:22 +0000632 ? ("\n<link rel=\"SHORTCUT ICON\" href=\"" . "$FAVORITES_ICON\">")
Fred Drakedd3d6a02002-10-30 17:00:58 +0000633 : ''),
Fred Drake23949002002-10-30 21:51:18 +0000634 ($EXTERNAL_UP_LINK
Fred Drake98b25762003-05-02 18:21:22 +0000635 ? ("\n<link rel='start' href='" . $EXTERNAL_UP_LINK
636 . ($EXTERNAL_UP_TITLE ?
637 "' title='$EXTERNAL_UP_TITLE'>" : "'>"))
Fred Drake23949002002-10-30 21:51:18 +0000638 : ''),
Fred Drake98b25762003-05-02 18:21:22 +0000639 "\n<link rel=\"first\" href=\"$FILE.html\"",
Fred Drake23949002002-10-30 21:51:18 +0000640 ($t_title ? " title='$t_title'" : ''),
Fred Drake98b25762003-05-02 18:21:22 +0000641 '>',
Fred Drakea219b412001-10-22 16:57:49 +0000642 ($HAVE_TABLE_OF_CONTENTS
Fred Drake98b25762003-05-02 18:21:22 +0000643 ? "\n<link rel='contents' href='contents.html' title='Contents'>"
Fred Drakea219b412001-10-22 16:57:49 +0000644 : ''),
645 ($HAVE_GENERAL_INDEX
Fred Drake98b25762003-05-02 18:21:22 +0000646 ? "\n<link rel='index' href='genindex.html' title='Index'>"
Fred Drakea219b412001-10-22 16:57:49 +0000647 : ''),
648 # disable for now -- Mozilla doesn't do well with multiple indexes
649 # ($HAVE_MODULE_INDEX
650 # ? '<link rel="index" href="modindex.html" title="Module Index">'
651 # . "\n"
652 # : ''),
Fred Drake23949002002-10-30 21:51:18 +0000653 ($INFO
654 # XXX We can do this with the Python tools since the About...
655 # page always gets copied to about.html, even when we use the
656 # generated node###.html page names. Won't work with the
657 # rest of the Python doc tools.
Fred Drake98b25762003-05-02 18:21:22 +0000658 ? ("\n<link rel='last' href='about.html'"
659 . " title='About this document...'>"
660 . "\n<link rel='help' href='about.html'"
661 . " title='About this document...'>")
Fred Drake23949002002-10-30 21:51:18 +0000662 : ''),
Fred Drakedd3d6a02002-10-30 17:00:58 +0000663 $more_links_mark,
Fred Drake0e2e6872002-10-30 19:55:23 +0000664 "\n",
Fred Drakedd3d6a02002-10-30 17:00:58 +0000665 ($CHARSET && $HTML_VERSION ge "2.1"
666 ? ('<meta http-equiv="Content-Type" content="text/html; '
667 . "charset=$CHARSET\">\n")
668 : ''),
669 ($AESOP_META_TYPE
670 ? "<meta name='aesop' content='$AESOP_META_TYPE'>\n" : ''));
Fred Drakea219b412001-10-22 16:57:49 +0000671 }
Fred Drake0e2e6872002-10-30 19:55:23 +0000672 if (!$charset && $CHARSET) {
673 $charset = $CHARSET;
674 $charset =~ s/_/\-/go;
675 }
Fred Drakef06b9052003-05-02 18:08:16 +0000676 # Remove section number from the title for use in the
677 # <meta name='description' ...> element in the document head.
678 my $metatitle = "$title";
679 $metatitle =~ s/^\d+(\.\d+)*\s*//;
680
Fred Drakedd3d6a02002-10-30 17:00:58 +0000681 join('',
682 $MY_PARTIAL_HEADER,
Fred Drakef06b9052003-05-02 18:08:16 +0000683 &meta_information($metatitle),
Fred Drakedd3d6a02002-10-30 17:00:58 +0000684 "<title>", $title, "</title>\n</head>\n<body$body>");
Fred Drakee15956b2000-04-03 04:51:13 +0000685}
686
Fred Drakebc7101d1998-03-06 21:18:55 +00006871; # This must be the last line