Bug #1627575: Added _open() method to FileHandler which can be used to reopen files...
[python.git] / Doc / perl / l2hinit.perl
blob7c5d1230d47c066793865cd88ced16855d29af72
1 # LaTeX2HTML support base for use with Python documentation.
3 package main;
5 use L2hos;
7 $HTML_VERSION = 4.01;
8 $LOWER_CASE_TAGS = 1;
9 $NO_FRENCH_QUOTES = 1;
11 # '' in \code{...} is still converted, so we can't use this yet.
12 #$USE_CURLY_QUOTES = 1;
14 # Force Unicode support to be loaded; request UTF-8 output.
15 do_require_extension('unicode');
16 do_require_extension('utf8');
17 $HTML_OPTIONS = 'utf8';
19 $MAX_LINK_DEPTH = 2;
20 $ADDRESS = '';
22 $NO_FOOTNODE = 1;
23 $NUMBERED_FOOTNOTES = 1;
25 # Python documentation uses section numbers to support references to match
26 # in the printed and online versions.
28 $SHOW_SECTION_NUMBERS = 1;
30 $ICONSERVER = '.';
31 $IMAGE_TYPE = 'gif';
33 # Control where the navigation bars should show up:
34 $TOP_NAVIGATION = 1;
35 $BOTTOM_NAVIGATION = 1;
36 $AUTO_NAVIGATION = 0;
38 $BODYTEXT = '';
39 $CHILDLINE = "\n<p><br /></p><hr class='online-navigation' />\n";
40 $VERBOSITY = 0;
42 # default # of columns for the indexes
43 $INDEX_COLUMNS = 2;
44 $MODULE_INDEX_COLUMNS = 4;
46 $HAVE_MODULE_INDEX = 0;
47 $HAVE_GENERAL_INDEX = 0;
48 $HAVE_TABLE_OF_CONTENTS = 0;
50 $AESOP_META_TYPE = 'information';
53 # A little painful, but lets us clean up the top level directory a little,
54 # and not be tied to the current directory (as far as I can tell). Testing
55 # an existing definition of $mydir is needed since it cannot be computed when
56 # run under mkhowto with recent versions of LaTeX2HTML, since this file is
57 # not read directly by LaTeX2HTML any more. mkhowto is required to prepend
58 # the required definition at the top of the actual input file.
60 if (!defined $mydir) {
61 use Cwd;
62 use File::Basename;
63 ($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
64 chop $mydir; # remove trailing '/'
65 $mydir = getcwd() . "$dd$mydir"
66 unless $mydir =~ s|^/|/|;
68 $LATEX2HTMLSTYLES = "$mydir$envkey$LATEX2HTMLSTYLES";
69 push (@INC, $mydir);
71 ($myrootname, $myrootdir, $myext) = fileparse($mydir, '\..*');
72 chop $myrootdir;
75 # Hackish way to get the appropriate paper-*/ directory into $TEXINPUTS;
76 # pass in the paper size (a4 or letter) as the environment variable PAPER
77 # to add the right directory. If not given, the current directory is
78 # added instead for use with HOWTO processing.
80 if (defined $ENV{'PAPER'}) {
81 $mytexinputs = "$myrootdir${dd}paper-$ENV{'PAPER'}$envkey";
83 else {
84 $mytexinputs = getcwd() . $envkey;
86 $mytexinputs .= "$myrootdir${dd}texinputs";
89 # Change this variable to change the text added in "About this document...";
90 # this should be an absolute pathname to get it right.
92 $ABOUT_FILE = "$myrootdir${dd}html${dd}stdabout.dat";
95 sub custom_driver_hook {
97 # This adds the directory of the main input file to $TEXINPUTS; it
98 # seems to be sufficiently general that it should be fine for HOWTO
99 # processing.
101 # XXX This still isn't quite right; we should actually be inserting
102 # $mytexinputs just before any empty entry in TEXINPUTS is one
103 # exists instead of just concatenating the pieces like we do here.
105 my $file = $_[0];
106 my($jobname, $dir, $ext) = fileparse($file, '\..*');
107 $dir = L2hos->Make_directory_absolute($dir);
108 $dir =~ s/$dd$//;
109 $TEXINPUTS = "$dir$envkey$mytexinputs";
110 # Push everything into $TEXINPUTS since LaTeX2HTML doesn't pick
111 # this up on its own; we clear $ENV{'TEXINPUTS'} so the value set
112 # for this by the main LaTeX2HTML script doesn't contain duplicate
113 # directories.
114 if ($ENV{'TEXINPUTS'}) {
115 $TEXINPUTS .= "$envkey$ENV{'TEXINPUTS'}";
116 $ENV{'TEXINPUTS'} = undef;
118 print "\nSetting \$TEXINPUTS to $TEXINPUTS\n";
120 # Not sure why we need to deal with this both here and at the top,
121 # but this is needed to actually make it work.
122 do_require_extension('utf8');
123 $charset = $utf8_str;
124 $CHARSET = $utf8_str;
125 $USE_UTF = 1;
129 # $CUSTOM_BUTTONS is only used for the module index link.
130 $CUSTOM_BUTTONS = '';
132 sub make_nav_sectref($$$) {
133 my($label, $linktype, $title) = @_;
134 if ($title) {
135 if ($title =~ /\<[aA] /) {
136 $title =~ s/\<[aA] /<a class="sectref" rel="$linktype" /;
137 $title =~ s/ HREF=/ href=/;
139 else {
140 $title = "<span class=\"sectref\">$title</span>";
142 return "<b class=\"navlabel\">$label:</b>\n$title\n";
144 return '';
147 @my_icon_tags = ();
148 $my_icon_tags{'next'} = 'Next Page';
149 $my_icon_tags{'next_page'} = 'Next Page';
150 $my_icon_tags{'previous'} = 'Previous Page';
151 $my_icon_tags{'previous_page'} = 'Previous Page';
152 $my_icon_tags{'up'} = 'Up One Level';
153 $my_icon_tags{'contents'} = 'Contents';
154 $my_icon_tags{'index'} = 'Index';
155 $my_icon_tags{'modules'} = 'Module Index';
157 @my_icon_names = ();
158 $my_icon_names{'previous_page'} = 'previous';
159 $my_icon_names{'next_page'} = 'next';
161 sub get_my_icon($) {
162 my $name = $_[0];
163 my $text = $my_icon_tags{$name};
164 if ($my_icon_names{$name}) {
165 $name = $my_icon_names{$name};
167 if ($text eq '') {
168 $name = 'blank';
170 my $iconserver = ($ICONSERVER eq '.') ? '' : "$ICONSERVER/";
171 return "<img src='$iconserver$name.$IMAGE_TYPE'\n border='0'"
172 . " height='32' alt='$text' width='32' />";
175 sub unlinkify($) {
176 my $text = "$_[0]";
177 $text =~ s|</[aA]>||;
178 $text =~ s|<a\s+[^>]*>||i;
179 return $text;
182 sub use_icon($$$) {
183 my($rel,$str,$title) = @_;
184 if ($str) {
185 my $s = "$str";
186 if ($s =~ /\<tex2html_([a-z_]+)_visible_mark\>/) {
187 my $r = get_my_icon($1);
188 $s =~ s/\<tex2html_[a-z_]+_visible_mark\>/$r/;
190 $s =~ s/<[aA] /<a rel="$rel" title="$title"\n /;
191 $s =~ s/ HREF=/ href=/;
192 return $s;
194 else {
195 return get_my_icon('blank');
199 sub make_nav_panel() {
200 my $s;
201 # new iconic rel iconic page title
202 my $next = use_icon('next', $NEXT, unlinkify($NEXT_TITLE));
203 my $up = use_icon('parent', $UP, unlinkify($UP_TITLE));
204 my $previous = use_icon('prev', $PREVIOUS, unlinkify($PREVIOUS_TITLE));
205 my $contents = use_icon('contents', $CONTENTS, 'Table of Contents');
206 my $index = use_icon('index', $INDEX, 'Index');
207 if (!$CUSTOM_BUTTONS) {
208 $CUSTOM_BUTTONS = get_my_icon('blank');
210 $s = ('<table align="center" width="100%" cellpadding="0" cellspacing="2">'
211 . "\n<tr>"
212 # left-hand side
213 . "\n<td class='online-navigation'>$previous</td>"
214 . "\n<td class='online-navigation'>$up</td>"
215 . "\n<td class='online-navigation'>$next</td>"
216 # title box
217 . "\n<td align=\"center\" width=\"100%\">$t_title</td>"
218 # right-hand side
219 . "\n<td class='online-navigation'>$contents</td>"
220 # module index
221 . "\n<td class='online-navigation'>$CUSTOM_BUTTONS</td>"
222 . "\n<td class='online-navigation'>$index</td>"
223 . "\n</tr></table>\n"
224 # textual navigation
225 . "<div class='online-navigation'>\n"
226 . make_nav_sectref("Previous", "prev", $PREVIOUS_TITLE)
227 . make_nav_sectref("Up", "parent", $UP_TITLE)
228 . make_nav_sectref("Next", "next", $NEXT_TITLE)
229 . "</div>\n"
231 # remove these; they are unnecessary and cause errors from validation
232 $s =~ s/ NAME="tex2html\d+"\n */ /g;
233 return $s;
236 sub add_child_links {
237 my $toc = add_real_child_links(@_);
238 $toc =~ s|\s*</[aA]>|</a>|g;
239 $toc =~ s/ NAME=\"tex2html\d+\"\s*href=/ href=/gi;
240 $toc =~ s|</UL>(\s*<BR( /)?>)?|</ul>|gi;
241 if ($toc =~ / NAME=["']CHILD_LINKS["']/) {
242 return "<div class='online-navigation'>\n$toc</div>\n";
244 return $toc;
247 sub get_version_text() {
248 if ($PACKAGE_VERSION ne '' && $t_date) {
249 return ("<span class=\"release-info\">"
250 . "Release $PACKAGE_VERSION$RELEASE_INFO,"
251 . " documentation updated on $t_date.</span>");
253 if ($PACKAGE_VERSION ne '') {
254 return ("<span class=\"release-info\">"
255 . "Release $PACKAGE_VERSION$RELEASE_INFO.</span>");
257 if ($t_date) {
258 return ("<span class=\"release-info\">Documentation released on "
259 . "$t_date.</span>");
261 return '';
265 sub top_navigation_panel() {
266 return "\n<div id='top-navigation-panel' xml:id='top-navigation-panel'>\n"
267 . make_nav_panel()
268 . "<hr /></div>\n";
271 sub bot_navigation_panel() {
272 return "\n<div class='online-navigation'>\n"
273 . "<p></p><hr />\n"
274 . make_nav_panel()
275 . "</div>\n"
276 . "<hr />\n"
277 . get_version_text()
278 . "\n";
281 sub add_link {
282 # Returns a pair (iconic link, textual link)
283 my($icon, $current_file, @link) = @_;
284 my($dummy, $file, $title) = split($delim,
285 $section_info{join(' ',@link)});
286 if ($icon =~ /\<tex2html_([_a-z]+)_visible_mark\>/) {
287 my $r = get_my_icon($1);
288 $icon =~ s/\<tex2html_[_a-z]+_visible_mark\>/$r/;
290 if ($title && ($file ne $current_file)) {
291 $title = purify($title);
292 $title = get_first_words($title, $WORDS_IN_NAVIGATION_PANEL_TITLES);
293 return (make_href($file, $icon), make_href($file, "$title"))
295 elsif ($icon eq get_my_icon('up') && $EXTERNAL_UP_LINK) {
296 return (make_href($EXTERNAL_UP_LINK, $icon),
297 make_href($EXTERNAL_UP_LINK, "$EXTERNAL_UP_TITLE"))
299 elsif ($icon eq get_my_icon('previous')
300 && $EXTERNAL_PREV_LINK && $EXTERNAL_PREV_TITLE) {
301 return (make_href($EXTERNAL_PREV_LINK, $icon),
302 make_href($EXTERNAL_PREV_LINK, "$EXTERNAL_PREV_TITLE"))
304 elsif ($icon eq get_my_icon('next')
305 && $EXTERNAL_DOWN_LINK && $EXTERNAL_DOWN_TITLE) {
306 return (make_href($EXTERNAL_DOWN_LINK, $icon),
307 make_href($EXTERNAL_DOWN_LINK, "$EXTERNAL_DOWN_TITLE"))
309 return (&inactive_img($icon), "");
312 sub add_special_link($$$) {
313 my($icon, $file, $current_file) = @_;
314 if ($icon =~ /\<tex2html_([_a-z]+)_visible_mark\>/) {
315 my $r = get_my_icon($1);
316 $icon =~ s/\<tex2html_[_a-z]+_visible_mark\>/$r/;
318 return (($file && ($file ne $current_file))
319 ? make_href($file, $icon)
320 : undef)
323 # The img_tag() function seems only to be called with the parameter
324 # 'anchor_invisible_mark', which we want to turn into ''. Since
325 # replace_icon_marks() is the only interesting caller, and all it really
326 # does is call img_tag(), we can just define the hook alternative to be
327 # a no-op instead.
329 sub replace_icons_hook {}
331 sub do_cmd_arabic {
332 # get rid of that nasty <SPAN CLASS="arabic">...</SPAN>
333 my($ctr, $val, $id, $text) = &read_counter_value($_[0]);
334 return ($val ? farabic($val) : "0") . $text;
338 sub gen_index_id($$) {
339 # this is used to ensure common index key generation and a stable sort
340 my($str, $extra) = @_;
341 sprintf('%s###%s%010d', $str, $extra, ++$global{'max_id'});
344 sub insert_index($$$$$) {
345 my($mark, $datafile, $columns, $letters, $prefix) = @_;
346 my $prog = "$myrootdir/tools/buildindex.py";
347 my $index;
348 if ($letters) {
349 $index = `$prog --columns $columns --letters $datafile`;
351 else {
352 $index = `$prog --columns $columns $datafile`;
354 if (!s/$mark/$prefix$index/) {
355 print "\nCould not locate index mark: $mark";
359 sub add_idx() {
360 print "\nBuilding HTML for the index ...";
361 close(IDXFILE);
362 insert_index($idx_mark, 'index.dat', $INDEX_COLUMNS, 1, '');
366 $idx_module_mark = '<tex2html_idx_module_mark>';
367 $idx_module_title = 'Module Index';
369 sub add_module_idx() {
370 print "\nBuilding HTML for the module index ...";
371 my $key;
372 my $first = 1;
373 my $prevplat = '';
374 my $allthesame = 1;
375 my $prefix = '';
376 foreach $key (keys %Modules) {
377 $key =~ s/<tt>([a-zA-Z0-9._]*)<\/tt>/$1/;
378 my $plat = "$ModulePlatforms{$key}";
379 $plat = ''
380 if ($plat eq $IGNORE_PLATFORM_ANNOTATION);
381 if (!$first) {
382 $allthesame = 0
383 if ($prevplat ne $plat);
385 else { $first = 0; }
386 $prevplat = $plat;
388 open(MODIDXFILE, '>modindex.dat') || die "\n$!\n";
389 foreach $key (keys %Modules) {
390 # dump the line in the data file; just use a dummy seqno field
391 my $nkey = $1;
392 my $moditem = "$Modules{$key}";
393 my $plat = '';
394 $key =~ s/<tt>([a-zA-Z0-9._]*)<\/tt>/$1/;
395 if ($ModulePlatforms{$key} && !$allthesame) {
396 $plat = (" <em>(<span class=\"platform\">$ModulePlatforms{$key}"
397 . '</span>)</em>');
399 print MODIDXFILE $moditem . $IDXFILE_FIELD_SEP
400 . "<tt class=\"module\">$key</tt>$plat###\n";
402 close(MODIDXFILE);
404 if ($GLOBAL_MODULE_INDEX) {
405 $prefix = <<MODULE_INDEX_PREFIX;
407 <p> This index only lists modules documented in this manual.
408 The <em class="citetitle"><a href="$GLOBAL_MODULE_INDEX">Global Module
409 Index</a></em> lists all modules that are documented in this set
410 of manuals.</p>
411 MODULE_INDEX_PREFIX
413 if (!$allthesame) {
414 $prefix .= <<PLAT_DISCUSS;
416 <p> Some module names are followed by an annotation indicating what
417 platform they are available on.</p>
419 PLAT_DISCUSS
421 insert_index($idx_module_mark, 'modindex.dat', $MODULE_INDEX_COLUMNS, 0,
422 $prefix);
425 # replace both indexes as needed:
426 sub add_idx_hook {
427 add_idx() if (/$idx_mark/);
428 process_python_state();
429 if ($MODULE_INDEX_FILE) {
430 local ($_);
431 open(MYFILE, "<$MODULE_INDEX_FILE");
432 sysread(MYFILE, $_, 1024*1024);
433 close(MYFILE);
434 add_module_idx();
435 open(MYFILE,">$MODULE_INDEX_FILE");
436 print MYFILE $_;
437 close(MYFILE);
442 # In addition to the standard stuff, add label to allow named node files and
443 # support suppression of the page complete (for HTML Help use).
444 $MY_CONTENTS_PAGE = '';
445 sub do_cmd_tableofcontents {
446 local($_) = @_;
447 $TITLE = $toc_title;
448 $tocfile = $CURRENT_FILE;
449 my($closures, $reopens) = preserve_open_tags();
450 anchor_label('contents', $CURRENT_FILE, $_); # this is added
451 $MY_CONTENTS_PAGE = "$CURRENT_FILE";
452 join('', "\\tableofchildlinks[off]", $closures
453 , make_section_heading($toc_title, 'h2'), $toc_mark
454 , $reopens, $_);
456 # In addition to the standard stuff, add label to allow named node files.
457 sub do_cmd_listoffigures {
458 local($_) = @_;
459 $TITLE = $lof_title;
460 $loffile = $CURRENT_FILE;
461 my($closures, $reopens) = preserve_open_tags();
462 anchor_label('lof', $CURRENT_FILE, $_); # this is added
463 join('', "<br />\n", $closures
464 , make_section_heading($lof_title, 'h2'), $lof_mark
465 , $reopens, $_);
467 # In addition to the standard stuff, add label to allow named node files.
468 sub do_cmd_listoftables {
469 local($_) = @_;
470 $TITLE = $lot_title;
471 $lotfile = $CURRENT_FILE;
472 my($closures, $reopens) = preserve_open_tags();
473 anchor_label('lot', $CURRENT_FILE, $_); # this is added
474 join('', "<br />\n", $closures
475 , make_section_heading($lot_title, 'h2'), $lot_mark
476 , $reopens, $_);
478 # In addition to the standard stuff, add label to allow named node files.
479 sub do_cmd_textohtmlinfopage {
480 local($_) = @_;
481 if ($INFO) { #
482 anchor_label("about",$CURRENT_FILE,$_); # this is added
484 my $the_version = ''; # and the rest is
485 if ($t_date) { # mostly ours
486 $the_version = ",\n$t_date";
487 if ($PACKAGE_VERSION) {
488 $the_version .= ", Release $PACKAGE_VERSION$RELEASE_INFO";
491 my $about;
492 open(ABOUT, "<$ABOUT_FILE") || die "\n$!\n";
493 sysread(ABOUT, $about, 1024*1024);
494 close(ABOUT);
495 $_ = (($INFO == 1)
496 ? join('',
497 $close_all,
498 "<strong>$t_title</strong>$the_version\n",
499 $about,
500 $open_all, $_)
501 : join('', $close_all, $INFO,"\n", $open_all, $_));
505 $GENERAL_INDEX_FILE = '';
506 $MODULE_INDEX_FILE = '';
508 # $idx_mark will be replaced with the real index at the end
509 sub do_cmd_textohtmlindex {
510 local($_) = @_;
511 $TITLE = $idx_title;
512 $idxfile = $CURRENT_FILE;
513 $GENERAL_INDEX_FILE = "$CURRENT_FILE";
514 if (%index_labels) { make_index_labels(); }
515 if (($SHORT_INDEX) && (%index_segment)) { make_preindex(); }
516 else { $preindex = ''; }
517 my $heading = make_section_heading($idx_title, 'h2') . $idx_mark;
518 my($pre, $post) = minimize_open_tags($heading);
519 anchor_label('genindex',$CURRENT_FILE,$_); # this is added
520 return "<br />\n" . $pre . $_;
523 # $idx_module_mark will be replaced with the real index at the end
524 sub do_cmd_textohtmlmoduleindex {
525 local($_) = @_;
526 $TITLE = $idx_module_title;
527 anchor_label('modindex', $CURRENT_FILE, $_);
528 $MODULE_INDEX_FILE = "$CURRENT_FILE";
529 $_ = ('<p></p>' . make_section_heading($idx_module_title, 'h2')
530 . $idx_module_mark . $_);
531 return $_;
534 # The bibliography and the index should be treated as separate
535 # sections in their own HTML files. The \bibliography{} command acts
536 # as a sectioning command that has the desired effect. But when the
537 # bibliography is constructed manually using the thebibliography
538 # environment, or when using the theindex environment it is not
539 # possible to use the normal sectioning mechanism. This subroutine
540 # inserts a \bibliography{} or a dummy \textohtmlindex command just
541 # before the appropriate environments to force sectioning.
543 # XXX This *assumes* that if there are two {theindex} environments,
544 # the first is the module index and the second is the standard
545 # index. This is sufficient for the current Python documentation,
546 # but that's about it.
548 sub add_bbl_and_idx_dummy_commands {
549 my $id = $global{'max_id'};
551 if (/[\\]tableofcontents/) {
552 $HAVE_TABLE_OF_CONTENTS = 1;
554 s/([\\]begin\s*$O\d+$C\s*thebibliography)/$bbl_cnt++; $1/eg;
555 s/([\\]begin\s*$O\d+$C\s*thebibliography)/$id++; "\\bibliography$O$id$C$O$id$C $1"/geo;
556 my(@parts) = split(/\\begin\s*$O\d+$C\s*theindex/);
557 if (scalar(@parts) == 3) {
558 # Be careful to re-write the string in place, since $_ is *not*
559 # returned explicity; *** nasty side-effect dependency! ***
560 print "\nadd_bbl_and_idx_dummy_commands ==> adding general index";
561 print "\nadd_bbl_and_idx_dummy_commands ==> adding module index";
562 my $rx = "([\\\\]begin\\s*$O\\d+$C\\s*theindex[\\s\\S]*)"
563 . "([\\\\]begin\\s*$O\\d+$C\\s*theindex)";
564 s/$rx/\\textohtmlmoduleindex $1 \\textohtmlindex $2/o;
565 # Add a button to the navigation areas:
566 $CUSTOM_BUTTONS .= ('<a href="modindex.html" title="Module Index">'
567 . get_my_icon('modules')
568 . '</a>');
569 $HAVE_MODULE_INDEX = 1;
570 $HAVE_GENERAL_INDEX = 1;
572 elsif (scalar(@parts) == 2) {
573 print "\nadd_bbl_and_idx_dummy_commands ==> adding general index";
574 my $rx = "([\\\\]begin\\s*$O\\d+$C\\s*theindex)";
575 s/$rx/\\textohtmlindex $1/o;
576 $HAVE_GENERAL_INDEX = 1;
578 elsif (scalar(@parts) == 1) {
579 print "\nadd_bbl_and_idx_dummy_commands ==> no index found";
580 $CUSTOM_BUTTONS .= get_my_icon('blank');
581 $global{'max_id'} = $id; # not sure why....
582 s/([\\]begin\s*$O\d+$C\s*theindex)/\\textohtmlindex $1/o;
583 s/[\\]printindex/\\textohtmlindex /o;
585 else {
586 die "\n\nBad number of index environments!\n\n";
588 #----------------------------------------------------------------------
589 lib_add_bbl_and_idx_dummy_commands()
590 if defined(&lib_add_bbl_and_idx_dummy_commands);
593 # The bibliographic references, the appendices, the lists of figures
594 # and tables etc. must appear in the contents table at the same level
595 # as the outermost sectioning command. This subroutine finds what is
596 # the outermost level and sets the above to the same level;
598 sub set_depth_levels {
599 # Sets $outermost_level
600 my $level;
601 #RRM: do not alter user-set value for $MAX_SPLIT_DEPTH
602 foreach $level ("part", "chapter", "section", "subsection",
603 "subsubsection", "paragraph") {
604 last if (($outermost_level) = /\\($level)$delimiter_rx/);
606 $level = ($outermost_level ? $section_commands{$outermost_level} :
607 do {$outermost_level = 'section'; 3;});
609 #RRM: but calculate value for $MAX_SPLIT_DEPTH when a $REL_DEPTH was given
610 if ($REL_DEPTH && $MAX_SPLIT_DEPTH) {
611 $MAX_SPLIT_DEPTH = $level + $MAX_SPLIT_DEPTH;
612 } elsif (!($MAX_SPLIT_DEPTH)) { $MAX_SPLIT_DEPTH = 1 };
614 %unnumbered_section_commands = ('tableofcontents' => $level,
615 'listoffigures' => $level,
616 'listoftables' => $level,
617 'bibliography' => $level,
618 'textohtmlindex' => $level,
619 'textohtmlmoduleindex' => $level);
620 $section_headings{'textohtmlmoduleindex'} = 'h1';
622 %section_commands = (%unnumbered_section_commands,
623 %section_commands);
625 make_sections_rx();
629 # This changes the markup used for {verbatim} environments, and is the
630 # best way I've found that ensures the <dl> goes on the outside of the
631 # <pre>...</pre>.
633 # Note that this *must* be done in the init file, not the python.perl
634 # style support file. The %declarations must be set before
635 # initialize() is called in the main LaTeX2HTML script (which happens
636 # before style files are loaded).
638 %declarations = ('preform' => '<div class="verbatim"><pre></pre></div>',
639 %declarations);
642 # This is a modified version of what's provided by LaTeX2HTML; see the
643 # comment on the middle stanza for an explanation of why we keep our
644 # own version.
646 # This routine must be called once on the text only,
647 # else it will "eat up" sensitive constructs.
648 sub text_cleanup {
649 # MRO: replaced $* with /m
650 s/(\s*\n){3,}/\n\n/gom; # Replace consecutive blank lines with one
651 s/<(\/?)P>\s*(\w)/<$1P>\n$2/gom; # clean up paragraph starts and ends
652 s/$O\d+$C//go; # Get rid of bracket id's
653 s/$OP\d+$CP//go; # Get rid of processed bracket id's
654 s/(<!)?--?(>)?/(length($1) || length($2)) ? "$1--$2" : "-"/ge;
655 # Spacing commands
656 s/\\( |$)/ /go;
657 #JKR: There should be no more comments in the source now.
658 #s/([^\\]?)%/$1/go; # Remove the comment character
659 # Cannot treat \, as a command because , is a delimiter ...
660 s/\\,/ /go;
661 # Replace tilde's with non-breaking spaces
662 s/ *~/&nbsp;/g;
664 # This is why we have this copy of this routine; the following
665 # isn't so desirable as the author/maintainers of LaTeX2HTML seem
666 # to think. It's not commented out in the main script, so we have
667 # to override the whole thing. In particular, we don't want empty
668 # table cells to disappear.
670 ### DANGEROUS ?? ###
671 # remove redundant (not <P></P>) empty tags, incl. with attributes
672 #s/\n?<([^PD >][^>]*)>\s*<\/\1>//g;
673 #s/\n?<([^PD >][^>]*)>\s*<\/\1>//g;
674 # remove redundant empty tags (not </P><P> or <TD> or <TH>)
675 #s/<\/(TT|[^PTH][A-Z]+)><\1>//g;
676 #s/<([^PD ]+)(\s[^>]*)?>\n*<\/\1>//g;
678 #JCL(jcl-hex)
679 # Replace ^^ special chars (according to p.47 of the TeX book)
680 # Useful when coming from the .aux file (german umlauts, etc.)
681 s/\^\^([^0-9a-f])/chr((64+ord($1))&127)/ge;
682 s/\^\^([0-9a-f][0-9a-f])/chr(hex($1))/ge;
685 # This is used to map the link rel attributes LaTeX2HTML uses to those
686 # currently recommended by the W3C.
687 sub custom_REL_hook {
688 my($rel,$junk) = @_;
689 return 'parent' if $rel eq 'up';
690 return 'prev' if $rel eq 'previous';
691 return $rel;
694 # This is added to get rid of the long comment that follows the
695 # doctype declaration; MSIE5 on NT4 SP4 barfs on it and drops the
696 # content of the page.
697 $MY_PARTIAL_HEADER = '';
698 sub make_head_and_body($$) {
699 my($title, $body) = @_;
700 $body = " $body" unless ($body eq '');
701 my $DTDcomment = '';
702 my($version, $isolanguage) = ($HTML_VERSION, 'EN');
703 my %isolanguages = ( 'english', 'EN' , 'USenglish', 'EN.US'
704 , 'original', 'EN' , 'german' , 'DE'
705 , 'austrian', 'DE.AT', 'french' , 'FR'
706 , 'spanish', 'ES');
707 $isolanguage = $isolanguages{$default_language};
708 $isolanguage = 'EN' unless $isolanguage;
709 $title = &purify($title,1);
710 eval("\$title = ". $default_title ) unless ($title);
712 # allow user-modification of the <title> tag; thanks Dan Young
713 if (defined &custom_TITLE_hook) {
714 $title = &custom_TITLE_hook($title, $toc_sec_title);
717 if ($DOCTYPE =~ /\/\/[\w\.]+\s*$/) { # language spec included
718 $DTDcomment = "<!DOCTYPE html PUBLIC \"$DOCTYPE\">\n";
719 } else {
720 $DTDcomment = "<!DOCTYPE html PUBLIC \"$DOCTYPE//"
721 . ($ISO_LANGUAGE ? $ISO_LANGUAGE : $isolanguage) . "\">\n";
723 if ($MY_PARTIAL_HEADER eq '') {
724 my $favicon = '';
725 if ($FAVORITES_ICON) {
726 my($myname, $mydir, $myext) = fileparse($FAVORITES_ICON, '\..*');
727 my $favtype = '';
728 if ($myext eq '.gif' || $myext eq '.png') {
729 $myext =~ s/^[.]//;
730 $favtype = " type=\"image/$myext\"";
732 $favicon = (
733 "\n<link rel=\"SHORTCUT ICON\" href=\"$FAVORITES_ICON\""
734 . "$favtype />");
736 $STYLESHEET = $FILE.".css" unless $STYLESHEET;
737 $MY_PARTIAL_HEADER = join('',
738 ($DOCTYPE ? $DTDcomment : ''),
739 "<html>\n<head>",
740 ($BASE ? "\n<base href=\"$BASE\" />" : ''),
741 "\n<link rel=\"STYLESHEET\" href=\"$STYLESHEET\" type='text/css'",
742 " />",
743 $favicon,
744 ($EXTERNAL_UP_LINK
745 ? ("\n<link rel='start' href='" . $EXTERNAL_UP_LINK
746 . ($EXTERNAL_UP_TITLE ?
747 "' title='$EXTERNAL_UP_TITLE' />" : "' />"))
748 : ''),
749 "\n<link rel=\"first\" href=\"$FILE.html\"",
750 ($t_title ? " title='$t_title'" : ''),
751 ' />',
752 ($HAVE_TABLE_OF_CONTENTS
753 ? ("\n<link rel='contents' href='$MY_CONTENTS_PAGE'"
754 . ' title="Contents" />')
755 : ''),
756 ($HAVE_GENERAL_INDEX
757 ? ("\n<link rel='index' href='$GENERAL_INDEX_FILE'"
758 . " title='Index' />")
759 : ''),
760 # disable for now -- Mozilla doesn't do well with multiple indexes
761 # ($HAVE_MODULE_INDEX
762 # ? ("<link rel="index" href='$MODULE_INDEX_FILE'"
763 # . " title='Module Index' />\n")
764 # : ''),
765 ($INFO
766 # XXX We can do this with the Python tools since the About...
767 # page always gets copied to about.html, even when we use the
768 # generated node###.html page names. Won't work with the
769 # rest of the Python doc tools.
770 ? ("\n<link rel='last' href='about.html'"
771 . " title='About this document...' />"
772 . "\n<link rel='help' href='about.html'"
773 . " title='About this document...' />")
774 : ''),
775 $more_links_mark,
776 "\n",
777 ($CHARSET && $HTML_VERSION ge "2.1"
778 ? ('<meta http-equiv="Content-Type" content="text/html; '
779 . "charset=$CHARSET\" />\n")
780 : ''),
781 ($AESOP_META_TYPE
782 ? "<meta name='aesop' content='$AESOP_META_TYPE' />\n" : ''));
784 if (!$charset && $CHARSET) {
785 $charset = $CHARSET;
786 $charset =~ s/_/\-/go;
788 join('',
789 $MY_PARTIAL_HEADER,
790 "<title>", $title, "</title>\n</head>\n<body$body>");
793 sub replace_morelinks {
794 $more_links =~ s/ REL=/ rel=/g;
795 $more_links =~ s/ HREF=/ href=/g;
796 $more_links =~ s/<LINK /<link /g;
797 $more_links =~ s/">/" \/>/g;
798 $_ =~ s/$more_links_mark/$more_links/e;
801 1; # This must be the last line