1 # LaTeX2HTML support base for use with Python documentation.
13 $NUMBERED_FOOTNOTES = 1;
15 # Python documentation uses section numbers to support references to match
16 # in the printed and online versions.
18 $SHOW_SECTION_NUMBERS = 1;
23 # Control where the navigation bars should show up:
25 $BOTTOM_NAVIGATION = 1;
29 $CHILDLINE = "\n<p><hr>\n";
32 # default # of columns for the indexes
34 $MODULE_INDEX_COLUMNS = 4;
36 $HAVE_MODULE_INDEX = 0;
37 $HAVE_GENERAL_INDEX = 0;
38 $HAVE_TABLE_OF_CONTENTS = 0;
40 $AESOP_META_TYPE = 'information';
43 # A little painful, but lets us clean up the top level directory a little,
44 # 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.
50 if (!defined $mydir) {
53 ($myname, $mydir, $myext) = fileparse
(__FILE__
, '\..*');
54 chop $mydir; # remove trailing '/'
55 $mydir = getcwd
() . "$dd$mydir"
56 unless $mydir =~ s
|^/|/|;
58 $LATEX2HTMLSTYLES = "$mydir$envkey$LATEX2HTMLSTYLES";
61 ($myrootname, $myrootdir, $myext) = fileparse
($mydir, '\..*');
65 # 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.
70 if (defined $ENV{'PAPER'}) {
71 $mytexinputs = "$myrootdir${dd}paper-$ENV{'PAPER'}$envkey";
74 $mytexinputs = getcwd
() . $envkey;
76 $mytexinputs .= "$myrootdir${dd}texinputs";
79 # Change this variable to change the text added in "About this document...";
80 # this should be an absolute pathname to get it right.
82 $ABOUT_FILE = "$myrootdir${dd}html${dd}stdabout.dat";
85 sub custom_driver_hook
{
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
92 my($jobname, $dir, $ext) = fileparse
($file, '\..*');
93 $dir = L2hos
->Make_directory_absolute($dir);
95 $TEXINPUTS = "$dir$envkey$mytexinputs";
96 print "\nAdding $dir to \$TEXINPUTS\n";
100 $CUSTOM_BUTTONS = '';
102 sub make_nav_sectref
($$) {
103 my($label, $title) = @_;
105 if ($title =~ /\<[aA] /) {
106 $title =~ s/\<[aA] /<a class="sectref" /;
109 $title = "<span class=\"sectref\">$title</span>";
111 return "<b class=\"navlabel\">$label:</b> $title\n";
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';
127 $my_icon_names{'previous_page'} = 'previous';
128 $my_icon_names{'next_page'} = 'next';
132 my $text = $my_icon_tags{$name};
133 if ($my_icon_names{$name}) {
134 $name = $my_icon_names{$name};
139 my $iconserver = ($ICONSERVER eq '.') ?
'' : "$ICONSERVER/";
140 return "<img src='$iconserver$name.$IMAGE_TYPE'\n border='0'"
141 . " height='32' alt='$text' width='32'>";
146 if ($s =~ /\<tex2html_([a-z_]+)_visible_mark\>/) {
147 my $r = get_my_icon
($1);
148 $s =~ s/\<tex2html_[a-z_]+_visible_mark\>/$r/;
153 sub make_nav_panel
() {
155 my $BLANK_ICON = get_my_icon
('blank');
156 $NEXT = $NEXT_TITLE ? use_my_icon
("$NEXT") : $BLANK_ICON;
157 $UP = $UP_TITLE ? use_my_icon
("$UP") : $BLANK_ICON;
158 $PREVIOUS = $PREVIOUS_TITLE ? use_my_icon
("$PREVIOUS") : $BLANK_ICON;
159 $CONTENTS = use_my_icon
("$CONTENTS");
160 $INDEX = $INDEX ? use_my_icon
("$INDEX") : $BLANK_ICON;
161 if (!$CUSTOM_BUTTONS) {
162 $CUSTOM_BUTTONS = $BLANK_ICON;
164 $s = ('<table align="center" width="100%" cellpadding="0" cellspacing="2">'
167 . "\n<td>$PREVIOUS</td>"
171 . "\n<td align=\"center\" width=\"100%\">$t_title</td>"
173 . "\n<td>$CONTENTS</td>"
174 . "\n<td>$CUSTOM_BUTTONS</td>" # module index
175 . "\n<td>$INDEX</td>"
176 . "\n</tr></table>\n"
178 . make_nav_sectref
("Previous", $PREVIOUS_TITLE)
179 . make_nav_sectref
("Up", $UP_TITLE)
180 . make_nav_sectref
("Next", $NEXT_TITLE)
182 # remove these; they are unnecessary and cause errors from validation
183 $s =~ s/ NAME="tex2html\d+"\n */ /g;
187 sub add_child_links
{
188 my $toc = add_real_child_links
(@_);
189 $toc =~ s
|\s
*</[aA]>|</a>|g
;
190 $toc =~ s/ NAME=\"tex2html\d+\"\s*href=/ href=/gi;
191 $toc =~ s
|</UL>(\s*<BR>)?|</ul>|gi
;
195 sub get_version_text
() {
196 if ($PACKAGE_VERSION ne '' && $t_date) {
197 return ("<span class=\"release-info\">"
198 . "Release $PACKAGE_VERSION$RELEASE_INFO,"
199 . " documentation updated on $t_date.</span>");
201 if ($PACKAGE_VERSION ne '') {
202 return ("<span class=\"release-info\">"
203 . "Release $PACKAGE_VERSION$RELEASE_INFO.</span>");
206 return ("<span class=\"release-info\">Documentation released on "
207 . "$t_date.</span>");
213 sub top_navigation_panel
() {
219 sub bot_navigation_panel
() {
228 # Returns a pair (iconic link, textual link)
229 my($icon, $current_file, @link) = @_;
230 my($dummy, $file, $title) = split($delim,
231 $section_info{join(' ',@link)});
232 if ($icon =~ /\<tex2html_([_a-z]+)_visible_mark\>/) {
233 my $r = get_my_icon
($1);
234 $icon =~ s/\<tex2html_[_a-z]+_visible_mark\>/$r/;
236 if ($title && ($file ne $current_file)) {
237 $title = purify
($title);
238 $title = get_first_words
($title, $WORDS_IN_NAVIGATION_PANEL_TITLES);
239 return (make_href
($file, $icon), make_href
($file, "$title"))
241 elsif ($icon eq get_my_icon
('up') && $EXTERNAL_UP_LINK) {
242 return (make_href
($EXTERNAL_UP_LINK, $icon),
243 make_href
($EXTERNAL_UP_LINK, "$EXTERNAL_UP_TITLE"))
245 elsif ($icon eq get_my_icon
('previous')
246 && $EXTERNAL_PREV_LINK && $EXTERNAL_PREV_TITLE) {
247 return (make_href
($EXTERNAL_PREV_LINK, $icon),
248 make_href
($EXTERNAL_PREV_LINK, "$EXTERNAL_PREV_TITLE"))
250 elsif ($icon eq get_my_icon
('next')
251 && $EXTERNAL_DOWN_LINK && $EXTERNAL_DOWN_TITLE) {
252 return (make_href
($EXTERNAL_DOWN_LINK, $icon),
253 make_href
($EXTERNAL_DOWN_LINK, "$EXTERNAL_DOWN_TITLE"))
255 return (&inactive_img
($icon), "");
258 sub add_special_link
($$$) {
259 my($icon, $file, $current_file) = @_;
260 if ($icon =~ /\<tex2html_([_a-z]+)_visible_mark\>/) {
261 my $r = get_my_icon
($1);
262 $icon =~ s/\<tex2html_[_a-z]+_visible_mark\>/$r/;
264 return (($file && ($file ne $current_file))
265 ? make_href
($file, $icon)
269 # The img_tag() function seems only to be called with the parameter
270 # 'anchor_invisible_mark', which we want to turn into ''. Since
271 # replace_icon_marks() is the only interesting caller, and all it really
272 # does is call img_tag(), we can just define the hook alternative to be
275 sub replace_icons_hook
{}
278 # get rid of that nasty <SPAN CLASS="arabic">...</SPAN>
279 my($ctr, $val, $id, $text) = &read_counter_value
($_[0]);
280 return ($val ? farabic
($val) : "0") . $text;
284 sub gen_index_id
($$) {
285 # this is used to ensure common index key generation and a stable sort
286 my($str, $extra) = @_;
287 sprintf('%s###%s%010d', $str, $extra, ++$global{'max_id'});
290 sub insert_index
($$$$$) {
291 my($mark, $datafile, $columns, $letters, $prefix) = @_;
292 my $prog = "$myrootdir/tools/buildindex.py";
295 $index = `$prog --columns $columns --letters $datafile`;
298 $index = `$prog --columns $columns $datafile`;
300 if (!s/$mark/$prefix$index/) {
301 print "\nCould not locate index mark: $mark";
306 print "\nBuilding HTML for the index ...";
308 insert_index
($idx_mark, 'index.dat', $INDEX_COLUMNS, 1, '');
312 $idx_module_mark = '<tex2html_idx_module_mark>';
313 $idx_module_title = 'Module Index';
315 sub add_module_idx
() {
316 print "\nBuilding HTML for the module index ...";
322 foreach $key (keys %Modules) {
323 $key =~ s/<tt>([a-zA-Z0-9._]*)<\/tt>/$1/;
324 my $plat = "$ModulePlatforms{$key}";
326 if ($plat eq $IGNORE_PLATFORM_ANNOTATION);
329 if ($prevplat ne $plat);
334 open(MODIDXFILE
, '>modindex.dat') || die "\n$!\n";
335 foreach $key (keys %Modules) {
336 # dump the line in the data file; just use a dummy seqno field
338 my $moditem = "$Modules{$key}";
340 $key =~ s/<tt>([a-zA-Z0-9._]*)<\/tt>/$1/;
341 if ($ModulePlatforms{$key} && !$allthesame) {
342 $plat = (" <em>(<span class=\"platform\">$ModulePlatforms{$key}"
345 print MODIDXFILE
$moditem . $IDXFILE_FIELD_SEP
346 . "<tt class=\"module\">$key</tt>$plat###\n";
350 if ($GLOBAL_MODULE_INDEX) {
351 $prefix = <<MODULE_INDEX_PREFIX;
353 <p> This index only lists modules documented in this manual.
354 The <em class="citetitle"><a href="$GLOBAL_MODULE_INDEX">Global Module
355 Index</a></em> lists all modules that are documented in this set
360 $prefix .= <<PLAT_DISCUSS;
362 <p> Some module names are followed by an annotation indicating what
363 platform they are available on.</p>
367 insert_index($idx_module_mark, 'modindex.dat', $MODULE_INDEX_COLUMNS, 0,
371 # replace both indexes as needed:
373 add_idx() if (/$idx_mark/);
374 process_python_state();
375 if ($MODULE_INDEX_FILE) {
377 open(MYFILE, "<$MODULE_INDEX_FILE");
378 sysread(MYFILE, $_, 1024*1024);
381 open(MYFILE,">$MODULE_INDEX_FILE");
388 # In addition to the standard stuff, add label to allow named node files and
389 # support suppression of the page complete (for HTML Help use).
390 sub do_cmd_tableofcontents {
393 $tocfile = $CURRENT_FILE;
394 my($closures, $reopens) = preserve_open_tags();
395 anchor_label('contents', $CURRENT_FILE, $_); # this is added
396 join('', "<BR>\n\\tableofchildlinks[off]", $closures
397 , make_section_heading($toc_title, 'H2'), $toc_mark
400 # In addition to the standard stuff, add label to allow named node files.
401 sub do_cmd_listoffigures {
404 $loffile = $CURRENT_FILE;
405 my($closures, $reopens) = preserve_open_tags();
406 anchor_label('lof', $CURRENT_FILE, $_); # this is added
407 join('', "<BR>\n", $closures
408 , make_section_heading($lof_title, 'H2'), $lof_mark
411 # In addition to the standard stuff, add label to allow named node files.
412 sub do_cmd_listoftables {
415 $lotfile = $CURRENT_FILE;
416 my($closures, $reopens) = preserve_open_tags();
417 anchor_label('lot', $CURRENT_FILE, $_); # this is added
418 join('', "<BR>\n", $closures
419 , make_section_heading($lot_title, 'H2'), $lot_mark
422 # In addition to the standard stuff, add label to allow named node files.
423 sub do_cmd_textohtmlinfopage {
426 anchor_label("about",$CURRENT_FILE,$_); # this is added
428 my $the_version = ''; # and the rest is
429 if ($t_date) { # mostly ours
430 $the_version = ",\n$t_date";
431 if ($PACKAGE_VERSION) {
432 $the_version .= ", Release $PACKAGE_VERSION$RELEASE_INFO";
436 open(ABOUT, "<$ABOUT_FILE") || die "\n$!\n";
437 sysread(ABOUT, $about, 1024*1024);
442 "<strong>$t_title</strong>$the_version\n",
445 : join('', $close_all, $INFO,"\n", $open_all, $_));
449 # $idx_mark will be replaced with the real index at the end
450 sub do_cmd_textohtmlindex {
453 $idxfile = $CURRENT_FILE;
454 if (%index_labels) { make_index_labels(); }
455 if (($SHORT_INDEX) && (%index_segment)) { make_preindex(); }
456 else { $preindex = ''; }
457 my $heading = make_section_heading($idx_title, 'h2') . $idx_mark;
458 my($pre, $post) = minimize_open_tags($heading);
459 anchor_label('genindex',$CURRENT_FILE,$_); # this is added
460 return "<br>\n" . $pre . $_;
463 $MODULE_INDEX_FILE = '';
465 # $idx_module_mark will be replaced with the real index at the end
466 sub do_cmd_textohtmlmoduleindex {
468 $TITLE = $idx_module_title;
469 anchor_label('modindex', $CURRENT_FILE, $_);
470 $MODULE_INDEX_FILE = "$CURRENT_FILE";
471 $_ = ('<p>' . make_section_heading($idx_module_title, 'h2')
472 . $idx_module_mark . $_);
476 # The bibliography and the index should be treated as separate
477 # sections in their own HTML files. The \bibliography{} command acts
478 # as a sectioning command that has the desired effect. But when the
479 # bibliography is constructed manually using the thebibliography
480 # environment, or when using the theindex environment it is not
481 # possible to use the normal sectioning mechanism. This subroutine
482 # inserts a \bibliography{} or a dummy \textohtmlindex command just
483 # before the appropriate environments to force sectioning.
485 # XXX This *assumes* that if there are two {theindex} environments,
486 # the first is the module index and the second is the standard
487 # index. This is sufficient for the current Python documentation,
488 # but that's about it.
490 sub add_bbl_and_idx_dummy_commands {
491 my $id = $global{'max_id'};
493 if (/[\\]tableofcontents/) {
494 $HAVE_TABLE_OF_CONTENTS = 1;
496 s/([\\]begin\s*$O\d+$C\s*thebibliography)/$bbl_cnt++; $1/eg;
497 s/([\\]begin\s*$O\d+$C\s*thebibliography)/$id++; "\\bibliography$O$id$C$O$id$C $1"/geo;
498 my(@parts) = split(/\\begin\s*$O\d+$C\s*theindex/);
499 if (scalar(@parts) == 3) {
500 # Be careful to re-write the string in place, since $_ is *not*
501 # returned explicity; *** nasty side-effect dependency! ***
502 print "\nadd_bbl_and_idx_dummy_commands ==> adding general index";
503 print "\nadd_bbl_and_idx_dummy_commands ==> adding module index";
504 my $rx = "([\\\\]begin\\s*$O\\d+$C\\s*theindex[\\s\\S]*)"
505 . "([\\\\]begin\\s*$O\\d+$C\\s*theindex)";
506 s/$rx/\\textohtmlmoduleindex $1 \\textohtmlindex $2/o;
507 # Add a button to the navigation areas:
508 $CUSTOM_BUTTONS .= ('<a href="modindex.html" title="Module Index">'
509 . get_my_icon('modules')
511 $HAVE_MODULE_INDEX = 1;
512 $HAVE_GENERAL_INDEX = 1;
514 elsif (scalar(@parts) == 2) {
515 print "\nadd_bbl_and_idx_dummy_commands ==> adding general index";
516 my $rx = "([\\\\]begin\\s*$O\\d+$C\\s*theindex)";
517 s/$rx/\\textohtmlindex $1/o;
518 $HAVE_GENERAL_INDEX = 1;
520 elsif (scalar(@parts) == 1) {
521 print "\nadd_bbl_and_idx_dummy_commands ==> no index found";
522 $CUSTOM_BUTTONS .= get_my_icon('blank');
523 $global{'max_id'} = $id; # not sure why....
524 s/([\\]begin\s*$O\d+$C\s*theindex)/\\textohtmlindex $1/o;
525 s/[\\]printindex/\\textohtmlindex /o;
528 die "\n\nBad number of index environments!\n\n";
530 #----------------------------------------------------------------------
531 lib_add_bbl_and_idx_dummy_commands()
532 if defined(&lib_add_bbl_and_idx_dummy_commands);
535 # The bibliographic references, the appendices, the lists of figures
536 # and tables etc. must appear in the contents table at the same level
537 # as the outermost sectioning command. This subroutine finds what is
538 # the outermost level and sets the above to the same level;
540 sub set_depth_levels {
541 # Sets $outermost_level
543 #RRM: do not alter user-set value for $MAX_SPLIT_DEPTH
544 foreach $level ("part", "chapter", "section", "subsection",
545 "subsubsection", "paragraph") {
546 last if (($outermost_level) = /\\($level)$delimiter_rx/);
548 $level = ($outermost_level ? $section_commands{$outermost_level} :
549 do {$outermost_level = 'section'; 3;});
551 #RRM: but calculate value for $MAX_SPLIT_DEPTH when a $REL_DEPTH was given
552 if ($REL_DEPTH && $MAX_SPLIT_DEPTH) {
553 $MAX_SPLIT_DEPTH = $level + $MAX_SPLIT_DEPTH;
554 } elsif (!($MAX_SPLIT_DEPTH)) { $MAX_SPLIT_DEPTH = 1 };
556 %unnumbered_section_commands = ('tableofcontents' => $level,
557 'listoffigures' => $level,
558 'listoftables' => $level,
559 'bibliography' => $level,
560 'textohtmlindex' => $level,
561 'textohtmlmoduleindex' => $level);
562 $section_headings{'textohtmlmoduleindex'} = 'h1';
564 %section_commands = (%unnumbered_section_commands,
571 # This changes the markup used for {verbatim} environments, and is the
572 # best way I've found that ensures the <dl> goes on the outside of the
575 # Note that this *must* be done in the init file, not the python.perl
576 # style support file. The %declarations must be set before
577 # initialize() is called in the main LaTeX2HTML script (which happens
578 # before style files are loaded).
580 %declarations = ('preform' => '<div class="verbatim"><pre></pre></div>',
584 # This is added to get rid of the long comment that follows the
585 # doctype declaration; MSIE5 on NT4 SP4 barfs on it and drops the
586 # content of the page.
587 $MY_PARTIAL_HEADER = '';
588 sub make_head_and_body($$) {
589 my($title, $body) = @_;
590 $body = " $body" unless ($body eq '');
592 my($version, $isolanguage) = ($HTML_VERSION, 'EN');
593 my %isolanguages = ( 'english', 'EN' , 'USenglish', 'EN.US'
594 , 'original', 'EN' , 'german' , 'DE'
595 , 'austrian', 'DE.AT', 'french' , 'FR'
597 $isolanguage = $isolanguages{$default_language};
598 $isolanguage = 'EN' unless $isolanguage;
599 $title = &purify($title,1);
600 eval("\$title = ". $default_title ) unless ($title);
602 # allow user-modification of the <TITLE> tag; thanks Dan Young
603 if (defined &custom_TITLE_hook) {
604 $title = &custom_TITLE_hook($title, $toc_sec_title);
607 if ($DOCTYPE =~ /\/\/[\w\.]+\s*$/) { # language spec included
608 $DTDcomment = "<!DOCTYPE html PUBLIC \"$DOCTYPE\">\n";
610 $DTDcomment = "<!DOCTYPE html PUBLIC \"$DOCTYPE//"
611 . ($ISO_LANGUAGE ? $ISO_LANGUAGE : $isolanguage) . "\">\n";
613 if ($MY_PARTIAL_HEADER eq '') {
614 $STYLESHEET = $FILE.".css" unless $STYLESHEET;
615 $MY_PARTIAL_HEADER = join('',
616 ($DOCTYPE ? $DTDcomment : ''),
618 ($BASE ? "<base href=\"$BASE\">\n" : ''),
619 "<link rel=\"STYLESHEET\" href=\"$STYLESHEET\" type='text/css'>\n",
621 ? ('<link rel="SHORTCUT ICON" href="' . "$FAVORITES_ICON\">\n")
624 ? ('<link rel="start" href="' . "$EXTERNAL_UP_LINK\""
625 . ($EXTERNAL_UP_TITLE ? " title='$EXTERNAL_UP_TITLE'" : '')
628 "<link rel=\"first\" href=\"$FILE.html\"",
629 ($t_title ? " title='$t_title'" : ''),
631 ($HAVE_TABLE_OF_CONTENTS
632 ? ('<link rel="contents" href="contents.html" title="Contents">'
633 . ($HAVE_GENERAL_INDEX ? "\n" : ''))
636 ? '<link rel="index" href="genindex.html" title="Index">' . "\n"
638 # disable for now -- Mozilla doesn't do well with multiple indexes
639 # ($HAVE_MODULE_INDEX
640 # ? '<link rel="index" href="modindex.html" title="Module Index">'
644 # XXX We can do this with the Python tools since the About...
645 # page always gets copied to about.html, even when we use the
646 # generated node###.html page names. Won't work with the
647 # rest of the Python doc tools.
648 ? ("<link rel='last' href='about.html'"
649 . " title='About this document...'>\n"
650 . "<link rel='help' href='about.html'"
651 . " title='About this document...'>\n")
655 ($CHARSET && $HTML_VERSION ge "2.1"
656 ? ('<meta http-equiv="Content-Type" content="text/html; '
657 . "charset=$CHARSET\">\n")
660 ? "<meta name='aesop' content='$AESOP_META_TYPE'>\n" : ''));
662 if (!$charset && $CHARSET) {
664 $charset =~ s/_/\-/go;
668 &meta_information($title),
669 "<title>", $title, "</title>\n</head>\n<body$body>");
672 1; # This must be the last line