blob: 0ecb693d80fa9b3feaf20c01d231d7f05db5e489 [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 Drake8b34e7c2003-05-03 02:07:22 +0000144sub unlinkify($) {
145 my $text = "$_[0]";
146 $text =~ s|</[aA]>||;
147 $text =~ s|<a\s+[^>]*>||i;
148 return $text;
149}
150
151sub use_icon($$$) {
152 my($rel,$str,$title) = @_;
153 if ($title) {
154 my $s = "$str";
155 if ($s =~ /\<tex2html_([a-z_]+)_visible_mark\>/) {
156 my $r = get_my_icon($1);
157 $s =~ s/\<tex2html_[a-z_]+_visible_mark\>/$r/;
158 }
159 $s =~ s/<[aA] /<a rel="$rel" title="$title" \n /;
160 return $s;
Fred Draked18722b2001-01-02 22:08:48 +0000161 }
Fred Drake8b34e7c2003-05-03 02:07:22 +0000162 else {
163 return get_my_icon('blank');
164 }
Fred Drake13210ed1998-03-17 06:28:05 +0000165}
166
Fred Drakef5478632002-05-23 17:59:16 +0000167sub make_nav_panel() {
Fred Drake85d14c92000-07-31 17:53:45 +0000168 my $s;
Fred Drake8b34e7c2003-05-03 02:07:22 +0000169 # new iconic rel iconic page title
170 $NEXT = use_icon('next', $NEXT, unlinkify($NEXT_TITLE));
171 $UP = use_icon('parent', $UP, unlinkify($UP_TITLE));
172 $PREVIOUS = use_icon('prev', $PREVIOUS, unlinkify($PREVIOUS_TITLE));
173 $CONTENTS = use_icon('contents', $CONTENTS, 'Table of Contents');
174 $INDEX = use_icon('index', $INDEX, 'Index');
Fred Drake85d14c92000-07-31 17:53:45 +0000175 if (!$CUSTOM_BUTTONS) {
Fred Drake8b34e7c2003-05-03 02:07:22 +0000176 $CUSTOM_BUTTONS = get_my_icon('blank');
Fred Drake85d14c92000-07-31 17:53:45 +0000177 }
178 $s = ('<table align="center" width="100%" cellpadding="0" cellspacing="2">'
179 . "\n<tr>"
180 # left-hand side
Fred Drake85d14c92000-07-31 17:53:45 +0000181 . "\n<td>$PREVIOUS</td>"
Fred Drake4640e132000-07-31 20:13:23 +0000182 . "\n<td>$UP</td>"
183 . "\n<td>$NEXT</td>"
Fred Drake85d14c92000-07-31 17:53:45 +0000184 # title box
Fred Drakef730fc32000-08-31 07:19:07 +0000185 . "\n<td align=\"center\" width=\"100%\">$t_title</td>"
Fred Drake85d14c92000-07-31 17:53:45 +0000186 # right-hand side
187 . "\n<td>$CONTENTS</td>"
188 . "\n<td>$CUSTOM_BUTTONS</td>" # module index
189 . "\n<td>$INDEX</td>"
190 . "\n</tr></table>\n"
191 # textual navigation
Fred Drakebf8ec3e2003-05-02 20:18:01 +0000192 . make_nav_sectref("Previous", "prev", $PREVIOUS_TITLE)
193 . make_nav_sectref("Up", "parent", $UP_TITLE)
194 . make_nav_sectref("Next", "next", $NEXT_TITLE)
Fred Drake4640e132000-07-31 20:13:23 +0000195 );
Fred Drake85d14c92000-07-31 17:53:45 +0000196 # remove these; they are unnecessary and cause errors from validation
197 $s =~ s/ NAME="tex2html\d+"\n */ /g;
198 return $s;
199}
200
Fred Drakefb6499f2001-10-26 14:16:23 +0000201sub add_child_links {
202 my $toc = add_real_child_links(@_);
203 $toc =~ s|\s*</[aA]>|</a>|g;
204 $toc =~ s/ NAME=\"tex2html\d+\"\s*href=/ href=/gi;
205 $toc =~ s|</UL>(\s*<BR>)?|</ul>|gi;
206 return $toc;
207}
208
Fred Drakef5478632002-05-23 17:59:16 +0000209sub get_version_text() {
Fred Drake7497bd32000-10-25 16:18:10 +0000210 if ($PACKAGE_VERSION ne '' && $t_date) {
211 return ("<span class=\"release-info\">"
Fred Drakedce975c2001-06-20 21:31:36 +0000212 . "Release $PACKAGE_VERSION$RELEASE_INFO,"
Fred Drake7497bd32000-10-25 16:18:10 +0000213 . " documentation updated on $t_date.</span>");
214 }
215 if ($PACKAGE_VERSION ne '') {
216 return ("<span class=\"release-info\">"
Fred Drakedce975c2001-06-20 21:31:36 +0000217 . "Release $PACKAGE_VERSION$RELEASE_INFO.</span>");
Fred Drake7497bd32000-10-25 16:18:10 +0000218 }
219 if ($t_date) {
220 return ("<span class=\"release-info\">Documentation released on "
221 . "$t_date.</span>");
222 }
223 return '';
224}
225
Fred Drake85d14c92000-07-31 17:53:45 +0000226
Fred Drakef5478632002-05-23 17:59:16 +0000227sub top_navigation_panel() {
Fred Drake7497bd32000-10-25 16:18:10 +0000228 return "\n"
229 . make_nav_panel()
230 . "<br><hr>\n";
Fred Drakebc7101d1998-03-06 21:18:55 +0000231}
232
Fred Drakef5478632002-05-23 17:59:16 +0000233sub bot_navigation_panel() {
Fred Drake7497bd32000-10-25 16:18:10 +0000234 return "\n<p><hr>\n"
235 . make_nav_panel()
236 . "<hr>\n"
237 . get_version_text()
238 . "\n";
Fred Drake64bdc241998-04-17 02:14:12 +0000239}
240
241sub add_link {
242 # Returns a pair (iconic link, textual link)
243 my($icon, $current_file, @link) = @_;
244 my($dummy, $file, $title) = split($delim,
Fred Drake28e7b4c1998-10-20 18:14:20 +0000245 $section_info{join(' ',@link)});
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 Drake64bdc241998-04-17 02:14:12 +0000250 if ($title && ($file ne $current_file)) {
251 $title = purify($title);
252 $title = get_first_words($title, $WORDS_IN_NAVIGATION_PANEL_TITLES);
253 return (make_href($file, $icon), make_href($file, "$title"))
254 }
Fred Draked18722b2001-01-02 22:08:48 +0000255 elsif ($icon eq get_my_icon('up') && $EXTERNAL_UP_LINK) {
Fred Drake64bdc241998-04-17 02:14:12 +0000256 return (make_href($EXTERNAL_UP_LINK, $icon),
257 make_href($EXTERNAL_UP_LINK, "$EXTERNAL_UP_TITLE"))
258 }
Fred Draked18722b2001-01-02 22:08:48 +0000259 elsif ($icon eq get_my_icon('previous')
Fred Drake64bdc241998-04-17 02:14:12 +0000260 && $EXTERNAL_PREV_LINK && $EXTERNAL_PREV_TITLE) {
261 return (make_href($EXTERNAL_PREV_LINK, $icon),
262 make_href($EXTERNAL_PREV_LINK, "$EXTERNAL_PREV_TITLE"))
263 }
Fred Draked18722b2001-01-02 22:08:48 +0000264 elsif ($icon eq get_my_icon('next')
Fred Drake64bdc241998-04-17 02:14:12 +0000265 && $EXTERNAL_DOWN_LINK && $EXTERNAL_DOWN_TITLE) {
266 return (make_href($EXTERNAL_DOWN_LINK, $icon),
267 make_href($EXTERNAL_DOWN_LINK, "$EXTERNAL_DOWN_TITLE"))
268 }
Fred Drake85d14c92000-07-31 17:53:45 +0000269 return (&inactive_img($icon), "");
Fred Drake64bdc241998-04-17 02:14:12 +0000270}
271
Fred Drakef5478632002-05-23 17:59:16 +0000272sub add_special_link($$$) {
Fred Drake64bdc241998-04-17 02:14:12 +0000273 my($icon, $file, $current_file) = @_;
Fred Draked18722b2001-01-02 22:08:48 +0000274 if ($icon =~ /\<tex2html_([_a-z]+)_visible_mark\>/) {
275 my $r = get_my_icon($1);
276 $icon =~ s/\<tex2html_[_a-z]+_visible_mark\>/$r/;
277 }
Fred Drake85d14c92000-07-31 17:53:45 +0000278 return (($file && ($file ne $current_file))
279 ? make_href($file, $icon)
280 : undef)
Fred Drake64bdc241998-04-17 02:14:12 +0000281}
282
Fred Drake85d14c92000-07-31 17:53:45 +0000283# The img_tag() function seems only to be called with the parameter
284# 'anchor_invisible_mark', which we want to turn into ''. Since
285# replace_icon_marks() is the only interesting caller, and all it really
286# does is call img_tag(), we can just define the hook alternative to be
287# a no-op instead.
288#
289sub replace_icons_hook {}
Fred Drakebc7101d1998-03-06 21:18:55 +0000290
Fred Drake50cdd971999-02-19 23:04:59 +0000291sub do_cmd_arabic {
292 # get rid of that nasty <SPAN CLASS="arabic">...</SPAN>
Fred Drake73c5b6602002-10-24 16:36:05 +0000293 my($ctr, $val, $id, $text) = &read_counter_value($_[0]);
Fred Drake85d14c92000-07-31 17:53:45 +0000294 return ($val ? farabic($val) : "0") . $text;
Fred Drake50cdd971999-02-19 23:04:59 +0000295}
296
297
Fred Drakef5478632002-05-23 17:59:16 +0000298sub gen_index_id($$) {
Fred Drakebc7101d1998-03-06 21:18:55 +0000299 # this is used to ensure common index key generation and a stable sort
Fred Drakef5478632002-05-23 17:59:16 +0000300 my($str, $extra) = @_;
Fred Drake64bdc241998-04-17 02:14:12 +0000301 sprintf('%s###%s%010d', $str, $extra, ++$global{'max_id'});
Fred Drakebc7101d1998-03-06 21:18:55 +0000302}
303
Fred Drakef5478632002-05-23 17:59:16 +0000304sub insert_index($$$$$) {
305 my($mark, $datafile, $columns, $letters, $prefix) = @_;
Fred Drake4d10b431998-08-07 20:51:58 +0000306 my $prog = "$myrootdir/tools/buildindex.py";
307 my $index;
308 if ($letters) {
309 $index = `$prog --columns $columns --letters $datafile`;
310 }
311 else {
312 $index = `$prog --columns $columns $datafile`;
313 }
Fred Drakec5681732000-09-12 20:13:04 +0000314 if (!s/$mark/$prefix$index/) {
315 print "\nCould not locate index mark: $mark";
316 }
Fred Drake64bdc241998-04-17 02:14:12 +0000317}
318
Fred Drakef5478632002-05-23 17:59:16 +0000319sub add_idx() {
Fred Drake9bbdce51999-01-19 16:30:10 +0000320 print "\nBuilding HTML for the index ...";
Fred Drake235e6b11998-03-27 05:19:43 +0000321 close(IDXFILE);
Fred Drake2383f6d1999-03-02 16:00:37 +0000322 insert_index($idx_mark, 'index.dat', $INDEX_COLUMNS, 1, '');
Fred Drake13210ed1998-03-17 06:28:05 +0000323}
Fred Drakebc7101d1998-03-06 21:18:55 +0000324
325
326$idx_module_mark = '<tex2html_idx_module_mark>';
327$idx_module_title = 'Module Index';
328
Fred Drakef5478632002-05-23 17:59:16 +0000329sub add_module_idx() {
Fred Drake9bbdce51999-01-19 16:30:10 +0000330 print "\nBuilding HTML for the module index ...";
Fred Drake235e6b11998-03-27 05:19:43 +0000331 my $key;
Fred Drake2383f6d1999-03-02 16:00:37 +0000332 my $first = 1;
333 my $prevplat = '';
334 my $allthesame = 1;
335 my $prefix = '';
336 foreach $key (keys %Modules) {
Fred Drake73c5b6602002-10-24 16:36:05 +0000337 $key =~ s/<tt>([a-zA-Z0-9._]*)<\/tt>/$1/;
Fred Drake2383f6d1999-03-02 16:00:37 +0000338 my $plat = "$ModulePlatforms{$key}";
339 $plat = ''
Fred Drake62cc3601999-03-04 18:41:17 +0000340 if ($plat eq $IGNORE_PLATFORM_ANNOTATION);
Fred Drake2383f6d1999-03-02 16:00:37 +0000341 if (!$first) {
342 $allthesame = 0
343 if ($prevplat ne $plat);
344 }
345 else { $first = 0; }
346 $prevplat = $plat;
347 }
Fred Drake64bdc241998-04-17 02:14:12 +0000348 open(MODIDXFILE, '>modindex.dat') || die "\n$!\n";
Fred Drake235e6b11998-03-27 05:19:43 +0000349 foreach $key (keys %Modules) {
350 # dump the line in the data file; just use a dummy seqno field
Fred Drake2383f6d1999-03-02 16:00:37 +0000351 my $nkey = $1;
352 my $moditem = "$Modules{$key}";
353 my $plat = '';
Fred Drake73c5b6602002-10-24 16:36:05 +0000354 $key =~ s/<tt>([a-zA-Z0-9._]*)<\/tt>/$1/;
Fred Drake2383f6d1999-03-02 16:00:37 +0000355 if ($ModulePlatforms{$key} && !$allthesame) {
Fred Drakedce975c2001-06-20 21:31:36 +0000356 $plat = (" <em>(<span class=\"platform\">$ModulePlatforms{$key}"
Fred Drakebb584d31999-03-25 22:18:30 +0000357 . '</span>)</em>');
Fred Drake2383f6d1999-03-02 16:00:37 +0000358 }
Fred Drakee15956b2000-04-03 04:51:13 +0000359 print MODIDXFILE $moditem . $IDXFILE_FIELD_SEP
Fred Drakedce975c2001-06-20 21:31:36 +0000360 . "<tt class=\"module\">$key</tt>$plat###\n";
Fred Drakebc7101d1998-03-06 21:18:55 +0000361 }
Fred Drake235e6b11998-03-27 05:19:43 +0000362 close(MODIDXFILE);
Fred Drake42181db2001-01-09 22:02:10 +0000363
364 if ($GLOBAL_MODULE_INDEX) {
365 $prefix = <<MODULE_INDEX_PREFIX;
366
367<p> This index only lists modules documented in this manual.
368 The <em class="citetitle"><a href="$GLOBAL_MODULE_INDEX">Global Module
369 Index</a></em> lists all modules that are documented in this set
370 of manuals.</p>
371MODULE_INDEX_PREFIX
372 }
Fred Drake2383f6d1999-03-02 16:00:37 +0000373 if (!$allthesame) {
Fred Draked18722b2001-01-02 22:08:48 +0000374 $prefix .= <<PLAT_DISCUSS;
Fred Drake2383f6d1999-03-02 16:00:37 +0000375
376<p> Some module names are followed by an annotation indicating what
377platform they are available on.</p>
378
379PLAT_DISCUSS
380 }
381 insert_index($idx_module_mark, 'modindex.dat', $MODULE_INDEX_COLUMNS, 0,
382 $prefix);
Fred Drakebc7101d1998-03-06 21:18:55 +0000383}
384
Fred Drake235e6b11998-03-27 05:19:43 +0000385# replace both indexes as needed:
Fred Drake85d14c92000-07-31 17:53:45 +0000386sub add_idx_hook {
Fred Drakeb3a3ed81998-07-24 22:17:34 +0000387 add_idx() if (/$idx_mark/);
Fred Drake2383f6d1999-03-02 16:00:37 +0000388 process_python_state();
Fred Drakec5681732000-09-12 20:13:04 +0000389 if ($MODULE_INDEX_FILE) {
390 local ($_);
391 open(MYFILE, "<$MODULE_INDEX_FILE");
392 sysread(MYFILE, $_, 1024*1024);
393 close(MYFILE);
394 add_module_idx();
395 open(MYFILE,">$MODULE_INDEX_FILE");
396 print MYFILE $_;
397 close(MYFILE);
398 }
Fred Drake235e6b11998-03-27 05:19:43 +0000399}
Fred Drakebc7101d1998-03-06 21:18:55 +0000400
Fred Drakebc7101d1998-03-06 21:18:55 +0000401
Fred Drake191439a1999-09-22 19:50:51 +0000402# In addition to the standard stuff, add label to allow named node files and
403# support suppression of the page complete (for HTML Help use).
Fred Drakebc7101d1998-03-06 21:18:55 +0000404sub do_cmd_tableofcontents {
405 local($_) = @_;
406 $TITLE = $toc_title;
407 $tocfile = $CURRENT_FILE;
Fred Drakef5478632002-05-23 17:59:16 +0000408 my($closures, $reopens) = preserve_open_tags();
Fred Drake64bdc241998-04-17 02:14:12 +0000409 anchor_label('contents', $CURRENT_FILE, $_); # this is added
Fred Drakebeb27bf1999-02-16 17:22:32 +0000410 join('', "<BR>\n\\tableofchildlinks[off]", $closures
Fred Drake64bdc241998-04-17 02:14:12 +0000411 , make_section_heading($toc_title, 'H2'), $toc_mark
Fred Drakebc7101d1998-03-06 21:18:55 +0000412 , $reopens, $_);
413}
414# In addition to the standard stuff, add label to allow named node files.
415sub do_cmd_listoffigures {
416 local($_) = @_;
417 $TITLE = $lof_title;
418 $loffile = $CURRENT_FILE;
Fred Drakef5478632002-05-23 17:59:16 +0000419 my($closures, $reopens) = preserve_open_tags();
Fred Drake64bdc241998-04-17 02:14:12 +0000420 anchor_label('lof', $CURRENT_FILE, $_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000421 join('', "<BR>\n", $closures
Fred Drake64bdc241998-04-17 02:14:12 +0000422 , make_section_heading($lof_title, 'H2'), $lof_mark
Fred Drakebc7101d1998-03-06 21:18:55 +0000423 , $reopens, $_);
424}
425# In addition to the standard stuff, add label to allow named node files.
426sub do_cmd_listoftables {
427 local($_) = @_;
428 $TITLE = $lot_title;
429 $lotfile = $CURRENT_FILE;
Fred Drakef5478632002-05-23 17:59:16 +0000430 my($closures, $reopens) = preserve_open_tags();
Fred Drake64bdc241998-04-17 02:14:12 +0000431 anchor_label('lot', $CURRENT_FILE, $_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000432 join('', "<BR>\n", $closures
Fred Drake64bdc241998-04-17 02:14:12 +0000433 , make_section_heading($lot_title, 'H2'), $lot_mark
Fred Drakebc7101d1998-03-06 21:18:55 +0000434 , $reopens, $_);
435}
436# In addition to the standard stuff, add label to allow named node files.
437sub do_cmd_textohtmlinfopage {
438 local($_) = @_;
439 if ($INFO) { #
Fred Drake64bdc241998-04-17 02:14:12 +0000440 anchor_label("about",$CURRENT_FILE,$_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000441 } #
Fred Drake15796f71998-11-30 19:25:47 +0000442 my $the_version = ''; # and the rest is
443 if ($t_date) { # mostly ours
444 $the_version = ",\n$t_date";
Fred Drake7497bd32000-10-25 16:18:10 +0000445 if ($PACKAGE_VERSION) {
Fred Drakedce975c2001-06-20 21:31:36 +0000446 $the_version .= ", Release $PACKAGE_VERSION$RELEASE_INFO";
Fred Drake15796f71998-11-30 19:25:47 +0000447 }
448 }
Fred Drake9443dc32001-08-10 20:12:09 +0000449 my $about;
450 open(ABOUT, "<$ABOUT_FILE") || die "\n$!\n";
451 sysread(ABOUT, $about, 1024*1024);
452 close(ABOUT);
Fred Drake15796f71998-11-30 19:25:47 +0000453 $_ = (($INFO == 1)
Fred Drakeb35f2b71999-09-23 16:53:09 +0000454 ? join('',
455 $close_all,
456 "<strong>$t_title</strong>$the_version\n",
Fred Drake9443dc32001-08-10 20:12:09 +0000457 $about,
Fred Drakeb35f2b71999-09-23 16:53:09 +0000458 $open_all, $_)
459 : join('', $close_all, $INFO,"\n", $open_all, $_));
Fred Drake15796f71998-11-30 19:25:47 +0000460 $_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000461}
462
463# $idx_mark will be replaced with the real index at the end
464sub do_cmd_textohtmlindex {
465 local($_) = @_;
466 $TITLE = $idx_title;
467 $idxfile = $CURRENT_FILE;
Fred Drake235e6b11998-03-27 05:19:43 +0000468 if (%index_labels) { make_index_labels(); }
469 if (($SHORT_INDEX) && (%index_segment)) { make_preindex(); }
Fred Drakebc7101d1998-03-06 21:18:55 +0000470 else { $preindex = ''; }
Fred Drake235e6b11998-03-27 05:19:43 +0000471 my $heading = make_section_heading($idx_title, 'h2') . $idx_mark;
Fred Drakef5478632002-05-23 17:59:16 +0000472 my($pre, $post) = minimize_open_tags($heading);
Fred Drake235e6b11998-03-27 05:19:43 +0000473 anchor_label('genindex',$CURRENT_FILE,$_); # this is added
Fred Drakec5681732000-09-12 20:13:04 +0000474 return "<br>\n" . $pre . $_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000475}
476
Fred Drakec5681732000-09-12 20:13:04 +0000477$MODULE_INDEX_FILE = '';
478
Fred Drakebc7101d1998-03-06 21:18:55 +0000479# $idx_module_mark will be replaced with the real index at the end
480sub do_cmd_textohtmlmoduleindex {
481 local($_) = @_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000482 $TITLE = $idx_module_title;
Fred Drakec5681732000-09-12 20:13:04 +0000483 anchor_label('modindex', $CURRENT_FILE, $_);
484 $MODULE_INDEX_FILE = "$CURRENT_FILE";
485 $_ = ('<p>' . make_section_heading($idx_module_title, 'h2')
486 . $idx_module_mark . $_);
487 return $_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000488}
489
Fred Drakec5681732000-09-12 20:13:04 +0000490# The bibliography and the index should be treated as separate
491# sections in their own HTML files. The \bibliography{} command acts
492# as a sectioning command that has the desired effect. But when the
493# bibliography is constructed manually using the thebibliography
494# environment, or when using the theindex environment it is not
495# possible to use the normal sectioning mechanism. This subroutine
496# inserts a \bibliography{} or a dummy \textohtmlindex command just
497# before the appropriate environments to force sectioning.
Fred Drakebc7101d1998-03-06 21:18:55 +0000498
Fred Drakec5681732000-09-12 20:13:04 +0000499# XXX This *assumes* that if there are two {theindex} environments,
500# the first is the module index and the second is the standard
501# index. This is sufficient for the current Python documentation,
502# but that's about it.
Fred Drakebc7101d1998-03-06 21:18:55 +0000503
504sub add_bbl_and_idx_dummy_commands {
Fred Drake11916921998-04-02 22:30:57 +0000505 my $id = $global{'max_id'};
Fred Drakebc7101d1998-03-06 21:18:55 +0000506
Fred Drakea219b412001-10-22 16:57:49 +0000507 if (/[\\]tableofcontents/) {
508 $HAVE_TABLE_OF_CONTENTS = 1;
509 }
Fred Drakebc7101d1998-03-06 21:18:55 +0000510 s/([\\]begin\s*$O\d+$C\s*thebibliography)/$bbl_cnt++; $1/eg;
Fred Drake191439a1999-09-22 19:50:51 +0000511 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 +0000512 my(@parts) = split(/\\begin\s*$O\d+$C\s*theindex/);
513 if (scalar(@parts) == 3) {
514 # Be careful to re-write the string in place, since $_ is *not*
515 # returned explicity; *** nasty side-effect dependency! ***
Fred Drakebb7775a2001-12-04 17:03:54 +0000516 print "\nadd_bbl_and_idx_dummy_commands ==> adding general index";
Fred Drake85d14c92000-07-31 17:53:45 +0000517 print "\nadd_bbl_and_idx_dummy_commands ==> adding module index";
518 my $rx = "([\\\\]begin\\s*$O\\d+$C\\s*theindex[\\s\\S]*)"
519 . "([\\\\]begin\\s*$O\\d+$C\\s*theindex)";
Fred Drake73c5b6602002-10-24 16:36:05 +0000520 s/$rx/\\textohtmlmoduleindex $1 \\textohtmlindex $2/o;
Fred Drake85d14c92000-07-31 17:53:45 +0000521 # Add a button to the navigation areas:
Fred Drakeaaa23852000-09-14 22:20:41 +0000522 $CUSTOM_BUTTONS .= ('<a href="modindex.html" title="Module Index">'
Fred Draked18722b2001-01-02 22:08:48 +0000523 . get_my_icon('modules')
Fred Drakeaaa23852000-09-14 22:20:41 +0000524 . '</a>');
Fred Drakea219b412001-10-22 16:57:49 +0000525 $HAVE_MODULE_INDEX = 1;
526 $HAVE_GENERAL_INDEX = 1;
527 }
528 elsif (scalar(@parts) == 2) {
Fred Drakebb7775a2001-12-04 17:03:54 +0000529 print "\nadd_bbl_and_idx_dummy_commands ==> adding general index";
530 my $rx = "([\\\\]begin\\s*$O\\d+$C\\s*theindex)";
Fred Drake73c5b6602002-10-24 16:36:05 +0000531 s/$rx/\\textohtmlindex $1/o;
Fred Drakea219b412001-10-22 16:57:49 +0000532 $HAVE_GENERAL_INDEX = 1;
Fred Drake11916921998-04-02 22:30:57 +0000533 }
Fred Drakebb7775a2001-12-04 17:03:54 +0000534 elsif (scalar(@parts) == 1) {
535 print "\nadd_bbl_and_idx_dummy_commands ==> no index found";
Fred Draked18722b2001-01-02 22:08:48 +0000536 $CUSTOM_BUTTONS .= get_my_icon('blank');
Fred Drake85d14c92000-07-31 17:53:45 +0000537 $global{'max_id'} = $id; # not sure why....
538 s/([\\]begin\s*$O\d+$C\s*theindex)/\\textohtmlindex $1/o;
Fred Drake191439a1999-09-22 19:50:51 +0000539 s/[\\]printindex/\\textohtmlindex /o;
Fred Drakebb7775a2001-12-04 17:03:54 +0000540 }
541 else {
542 die "\n\nBad number of index environments!\n\n";
543 }
Fred Drake11916921998-04-02 22:30:57 +0000544 #----------------------------------------------------------------------
Fred Drake64bdc241998-04-17 02:14:12 +0000545 lib_add_bbl_and_idx_dummy_commands()
Fred Drake11916921998-04-02 22:30:57 +0000546 if defined(&lib_add_bbl_and_idx_dummy_commands);
Fred Drakebc7101d1998-03-06 21:18:55 +0000547}
548
Fred Drakec5681732000-09-12 20:13:04 +0000549# The bibliographic references, the appendices, the lists of figures
550# and tables etc. must appear in the contents table at the same level
551# as the outermost sectioning command. This subroutine finds what is
552# the outermost level and sets the above to the same level;
Fred Drakebc7101d1998-03-06 21:18:55 +0000553
Fred Drake13210ed1998-03-17 06:28:05 +0000554sub set_depth_levels {
555 # Sets $outermost_level
Fred Drake11916921998-04-02 22:30:57 +0000556 my $level;
Fred Drake13210ed1998-03-17 06:28:05 +0000557 #RRM: do not alter user-set value for $MAX_SPLIT_DEPTH
558 foreach $level ("part", "chapter", "section", "subsection",
559 "subsubsection", "paragraph") {
560 last if (($outermost_level) = /\\($level)$delimiter_rx/);
561 }
562 $level = ($outermost_level ? $section_commands{$outermost_level} :
563 do {$outermost_level = 'section'; 3;});
Fred Drakebc7101d1998-03-06 21:18:55 +0000564
Fred Drake13210ed1998-03-17 06:28:05 +0000565 #RRM: but calculate value for $MAX_SPLIT_DEPTH when a $REL_DEPTH was given
566 if ($REL_DEPTH && $MAX_SPLIT_DEPTH) {
567 $MAX_SPLIT_DEPTH = $level + $MAX_SPLIT_DEPTH;
568 } elsif (!($MAX_SPLIT_DEPTH)) { $MAX_SPLIT_DEPTH = 1 };
Fred Drakebc7101d1998-03-06 21:18:55 +0000569
Fred Drake64bdc241998-04-17 02:14:12 +0000570 %unnumbered_section_commands = ('tableofcontents' => $level,
571 'listoffigures' => $level,
572 'listoftables' => $level,
573 'bibliography' => $level,
574 'textohtmlindex' => $level,
575 'textohtmlmoduleindex' => $level);
576 $section_headings{'textohtmlmoduleindex'} = 'h1';
Fred Drakebc7101d1998-03-06 21:18:55 +0000577
Fred Drake64bdc241998-04-17 02:14:12 +0000578 %section_commands = (%unnumbered_section_commands,
579 %section_commands);
Fred Drake11916921998-04-02 22:30:57 +0000580
581 make_sections_rx();
Fred Drake13210ed1998-03-17 06:28:05 +0000582}
Fred Drakebc7101d1998-03-06 21:18:55 +0000583
584
Fred Drake1072e461998-04-12 02:16:34 +0000585# This changes the markup used for {verbatim} environments, and is the
Fred Drake95474f91999-02-09 18:45:50 +0000586# best way I've found that ensures the <dl> goes on the outside of the
Fred Drake1072e461998-04-12 02:16:34 +0000587# <pre>...</pre>.
588#
589# Note that this *must* be done in the init file, not the python.perl
Fred Drakec5681732000-09-12 20:13:04 +0000590# style support file. The %declarations must be set before
591# initialize() is called in the main LaTeX2HTML script (which happens
592# before style files are loaded).
Fred Drake1072e461998-04-12 02:16:34 +0000593#
Fred Drake8a5e6792002-04-15 18:41:31 +0000594%declarations = ('preform' => '<div class="verbatim"><pre></pre></div>',
Fred Drake1072e461998-04-12 02:16:34 +0000595 %declarations);
596
Fred Drakee15956b2000-04-03 04:51:13 +0000597
Fred Drakebf8ec3e2003-05-02 20:18:01 +0000598# This is used to map the link rel attributes LaTeX2HTML uses to those
599# currently recommended by the W3C.
600sub custom_REL_hook {
601 my($rel,$junk) = @_;
602 return 'parent' if $rel eq 'up';
603 return 'prev' if $rel eq 'previous';
604 return $rel;
605}
606
Fred Drakec5681732000-09-12 20:13:04 +0000607# This is added to get rid of the long comment that follows the
608# doctype declaration; MSIE5 on NT4 SP4 barfs on it and drops the
609# content of the page.
Fred Drakea219b412001-10-22 16:57:49 +0000610$MY_PARTIAL_HEADER = '';
Fred Drakef5478632002-05-23 17:59:16 +0000611sub make_head_and_body($$) {
Fred Drake85d14c92000-07-31 17:53:45 +0000612 my($title, $body) = @_;
Fred Drake16816272000-09-16 20:40:44 +0000613 $body = " $body" unless ($body eq '');
Fred Drake85d14c92000-07-31 17:53:45 +0000614 my $DTDcomment = '';
615 my($version, $isolanguage) = ($HTML_VERSION, 'EN');
616 my %isolanguages = ( 'english', 'EN' , 'USenglish', 'EN.US'
617 , 'original', 'EN' , 'german' , 'DE'
618 , 'austrian', 'DE.AT', 'french' , 'FR'
619 , 'spanish', 'ES');
Fred Drakee15956b2000-04-03 04:51:13 +0000620 $isolanguage = $isolanguages{$default_language};
621 $isolanguage = 'EN' unless $isolanguage;
622 $title = &purify($title,1);
623 eval("\$title = ". $default_title ) unless ($title);
624
625 # allow user-modification of the <TITLE> tag; thanks Dan Young
626 if (defined &custom_TITLE_hook) {
627 $title = &custom_TITLE_hook($title, $toc_sec_title);
628 }
629
630 if ($DOCTYPE =~ /\/\/[\w\.]+\s*$/) { # language spec included
631 $DTDcomment = "<!DOCTYPE html PUBLIC \"$DOCTYPE\">\n";
632 } else {
633 $DTDcomment = "<!DOCTYPE html PUBLIC \"$DOCTYPE//"
634 . ($ISO_LANGUAGE ? $ISO_LANGUAGE : $isolanguage) . "\">\n";
635 }
Fred Drakea219b412001-10-22 16:57:49 +0000636 if ($MY_PARTIAL_HEADER eq '') {
637 $STYLESHEET = $FILE.".css" unless $STYLESHEET;
638 $MY_PARTIAL_HEADER = join('',
Fred Drakedd3d6a02002-10-30 17:00:58 +0000639 ($DOCTYPE ? $DTDcomment : ''),
Fred Drake98b25762003-05-02 18:21:22 +0000640 "<html>\n<head>",
641 ($BASE ? "\n<base href=\"$BASE\">" : ''),
642 "\n<link rel=\"STYLESHEET\" href=\"$STYLESHEET\" type='text/css'>",
Fred Drakedd3d6a02002-10-30 17:00:58 +0000643 ($FAVORITES_ICON
Fred Drake98b25762003-05-02 18:21:22 +0000644 ? ("\n<link rel=\"SHORTCUT ICON\" href=\"" . "$FAVORITES_ICON\">")
Fred Drakedd3d6a02002-10-30 17:00:58 +0000645 : ''),
Fred Drake23949002002-10-30 21:51:18 +0000646 ($EXTERNAL_UP_LINK
Fred Drake98b25762003-05-02 18:21:22 +0000647 ? ("\n<link rel='start' href='" . $EXTERNAL_UP_LINK
648 . ($EXTERNAL_UP_TITLE ?
649 "' title='$EXTERNAL_UP_TITLE'>" : "'>"))
Fred Drake23949002002-10-30 21:51:18 +0000650 : ''),
Fred Drake98b25762003-05-02 18:21:22 +0000651 "\n<link rel=\"first\" href=\"$FILE.html\"",
Fred Drake23949002002-10-30 21:51:18 +0000652 ($t_title ? " title='$t_title'" : ''),
Fred Drake98b25762003-05-02 18:21:22 +0000653 '>',
Fred Drakea219b412001-10-22 16:57:49 +0000654 ($HAVE_TABLE_OF_CONTENTS
Fred Drake98b25762003-05-02 18:21:22 +0000655 ? "\n<link rel='contents' href='contents.html' title='Contents'>"
Fred Drakea219b412001-10-22 16:57:49 +0000656 : ''),
657 ($HAVE_GENERAL_INDEX
Fred Drake98b25762003-05-02 18:21:22 +0000658 ? "\n<link rel='index' href='genindex.html' title='Index'>"
Fred Drakea219b412001-10-22 16:57:49 +0000659 : ''),
660 # disable for now -- Mozilla doesn't do well with multiple indexes
661 # ($HAVE_MODULE_INDEX
662 # ? '<link rel="index" href="modindex.html" title="Module Index">'
663 # . "\n"
664 # : ''),
Fred Drake23949002002-10-30 21:51:18 +0000665 ($INFO
666 # XXX We can do this with the Python tools since the About...
667 # page always gets copied to about.html, even when we use the
668 # generated node###.html page names. Won't work with the
669 # rest of the Python doc tools.
Fred Drake98b25762003-05-02 18:21:22 +0000670 ? ("\n<link rel='last' href='about.html'"
671 . " title='About this document...'>"
672 . "\n<link rel='help' href='about.html'"
673 . " title='About this document...'>")
Fred Drake23949002002-10-30 21:51:18 +0000674 : ''),
Fred Drakedd3d6a02002-10-30 17:00:58 +0000675 $more_links_mark,
Fred Drake0e2e6872002-10-30 19:55:23 +0000676 "\n",
Fred Drakedd3d6a02002-10-30 17:00:58 +0000677 ($CHARSET && $HTML_VERSION ge "2.1"
678 ? ('<meta http-equiv="Content-Type" content="text/html; '
679 . "charset=$CHARSET\">\n")
680 : ''),
681 ($AESOP_META_TYPE
682 ? "<meta name='aesop' content='$AESOP_META_TYPE'>\n" : ''));
Fred Drakea219b412001-10-22 16:57:49 +0000683 }
Fred Drake0e2e6872002-10-30 19:55:23 +0000684 if (!$charset && $CHARSET) {
685 $charset = $CHARSET;
686 $charset =~ s/_/\-/go;
687 }
Fred Drakef06b9052003-05-02 18:08:16 +0000688 # Remove section number from the title for use in the
689 # <meta name='description' ...> element in the document head.
690 my $metatitle = "$title";
691 $metatitle =~ s/^\d+(\.\d+)*\s*//;
692
Fred Drakedd3d6a02002-10-30 17:00:58 +0000693 join('',
694 $MY_PARTIAL_HEADER,
Fred Drakef06b9052003-05-02 18:08:16 +0000695 &meta_information($metatitle),
Fred Drakedd3d6a02002-10-30 17:00:58 +0000696 "<title>", $title, "</title>\n</head>\n<body$body>");
Fred Drakee15956b2000-04-03 04:51:13 +0000697}
698
Fred Drakebc7101d1998-03-06 21:18:55 +00006991; # This must be the last line