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;
20 $ICONSERVER = '../icons';
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;
41 # A little painful, but lets us clean up the top level directory a little,
42 # and not be tied to the current directory (as far as I can tell). Testing
43 # an existing definition of $mydir is needed since it cannot be computed when
44 # run under mkhowto with recent versions of LaTeX2HTML, since this file is
45 # not read directly by LaTeX2HTML any more. mkhowto is required to prepend
46 # the required definition at the top of the actual input file.
48 if (!defined $mydir) {
51 ($myname, $mydir, $myext) = fileparse
(__FILE__
, '\..*');
52 chop $mydir; # remove trailing '/'
53 $mydir = getcwd
() . "$dd$mydir"
54 unless $mydir =~ s
|^/|/|;
56 $LATEX2HTMLSTYLES = "$mydir$envkey$LATEX2HTMLSTYLES";
59 ($myrootname, $myrootdir, $myext) = fileparse
($mydir, '\..*');
63 # Hackish way to get the appropriate paper-*/ directory into $TEXINPUTS;
64 # pass in the paper size (a4 or letter) as the environment variable PAPER
65 # to add the right directory. If not given, the current directory is
66 # added instead for use with HOWTO processing.
68 if (defined $ENV{'PAPER'}) {
69 $mytexinputs = "$myrootdir${dd}paper-$ENV{'PAPER'}$envkey";
72 $mytexinputs = getcwd
() . $envkey;
74 $mytexinputs .= "$myrootdir${dd}texinputs";
77 # Change this variable to change the text added in "About this document...";
78 # this should be an absolute pathname to get it right.
80 $ABOUT_FILE = "$myrootdir${dd}html${dd}stdabout.dat";
83 sub custom_driver_hook
{
85 # This adds the directory of the main input file to $TEXINPUTS; it
86 # seems to be sufficiently general that it should be fine for HOWTO
90 my($jobname, $dir, $ext) = fileparse
($file, '\..*');
91 $dir = L2hos
->Make_directory_absolute($dir);
93 $TEXINPUTS = "$dir$envkey$mytexinputs";
94 print "\nAdding $dir to \$TEXINPUTS\n";
100 sub make_nav_sectref
{
101 my($label,$title) = @_;
103 if ($title =~ /\<[aA] /) {
104 $title =~ s/\<[aA] /<a class="sectref" /;
107 $title = "<span class=\"sectref\">$title</span>";
109 return "<b class=\"navlabel\">$label:</b> $title\n";
115 $my_icon_tags{'next'} = 'Next Page';
116 $my_icon_tags{'next_page'} = 'Next Page';
117 $my_icon_tags{'previous'} = 'Previous Page';
118 $my_icon_tags{'previous_page'} = 'Previous Page';
119 $my_icon_tags{'up'} = 'Up One Level';
120 $my_icon_tags{'contents'} = 'Contents';
121 $my_icon_tags{'index'} = 'Index';
122 $my_icon_tags{'modules'} = 'Module Index';
125 $my_icon_names{'previous_page'} = 'previous';
126 $my_icon_names{'next_page'} = 'next';
130 my $text = $my_icon_tags{$name};
131 if ($my_icon_names{$name}) {
132 $name = $my_icon_names{$name};
137 my $iconserver = ($ICONSERVER eq '.') ?
'' : "$ICONSERVER/";
138 return "<img src=\"$iconserver$name.$IMAGE_TYPE\"\n border=\"0\""
139 . " height=\"32\"\n alt=\"$text\" width=\"32\">";
144 if ($s =~ /\<tex2html_([a-z_]+)_visible_mark\>/) {
145 my $r = get_my_icon
($1);
146 $s =~ s/\<tex2html_[a-z_]+_visible_mark\>/$r/;
153 my $BLANK_ICON = get_my_icon
('blank');
154 $NEXT = $NEXT_TITLE ? use_my_icon
("$NEXT") : $BLANK_ICON;
155 $UP = $UP_TITLE ? use_my_icon
("$UP") : $BLANK_ICON;
156 $PREVIOUS = $PREVIOUS_TITLE ? use_my_icon
("$PREVIOUS") : $BLANK_ICON;
157 $CONTENTS = use_my_icon
("$CONTENTS");
158 $INDEX = $INDEX ? use_my_icon
("$INDEX") : $BLANK_ICON;
159 if (!$CUSTOM_BUTTONS) {
160 $CUSTOM_BUTTONS = $BLANK_ICON;
162 $s = ('<table align="center" width="100%" cellpadding="0" cellspacing="2">'
165 . "\n<td>$PREVIOUS</td>"
169 . "\n<td align=\"center\" width=\"100%\">$t_title</td>"
171 . "\n<td>$CONTENTS</td>"
172 . "\n<td>$CUSTOM_BUTTONS</td>" # module index
173 . "\n<td>$INDEX</td>"
174 . "\n</tr></table>\n"
176 . make_nav_sectref
("Previous", $PREVIOUS_TITLE)
177 . make_nav_sectref
("Up", $UP_TITLE)
178 . make_nav_sectref
("Next", $NEXT_TITLE)
180 # remove these; they are unnecessary and cause errors from validation
181 $s =~ s/ NAME="tex2html\d+"\n */ /g;
185 sub add_child_links
{
186 my $toc = add_real_child_links
(@_);
187 $toc =~ s
|\s
*</[aA]>|</a>|g
;
188 $toc =~ s/ NAME=\"tex2html\d+\"\s*href=/ href=/gi;
189 $toc =~ s
|</UL>(\s*<BR>)?|</ul>|gi
;
193 sub get_version_text
{
194 if ($PACKAGE_VERSION ne '' && $t_date) {
195 return ("<span class=\"release-info\">"
196 . "Release $PACKAGE_VERSION$RELEASE_INFO,"
197 . " documentation updated on $t_date.</span>");
199 if ($PACKAGE_VERSION ne '') {
200 return ("<span class=\"release-info\">"
201 . "Release $PACKAGE_VERSION$RELEASE_INFO.</span>");
204 return ("<span class=\"release-info\">Documentation released on "
205 . "$t_date.</span>");
211 sub top_navigation_panel
{
217 sub bot_navigation_panel
{
226 # Returns a pair (iconic link, textual link)
227 my($icon, $current_file, @link) = @_;
228 my($dummy, $file, $title) = split($delim,
229 $section_info{join(' ',@link)});
230 if ($icon =~ /\<tex2html_([_a-z]+)_visible_mark\>/) {
231 my $r = get_my_icon
($1);
232 $icon =~ s/\<tex2html_[_a-z]+_visible_mark\>/$r/;
234 if ($title && ($file ne $current_file)) {
235 $title = purify
($title);
236 $title = get_first_words
($title, $WORDS_IN_NAVIGATION_PANEL_TITLES);
237 return (make_href
($file, $icon), make_href
($file, "$title"))
239 elsif ($icon eq get_my_icon
('up') && $EXTERNAL_UP_LINK) {
240 return (make_href
($EXTERNAL_UP_LINK, $icon),
241 make_href
($EXTERNAL_UP_LINK, "$EXTERNAL_UP_TITLE"))
243 elsif ($icon eq get_my_icon
('previous')
244 && $EXTERNAL_PREV_LINK && $EXTERNAL_PREV_TITLE) {
245 return (make_href
($EXTERNAL_PREV_LINK, $icon),
246 make_href
($EXTERNAL_PREV_LINK, "$EXTERNAL_PREV_TITLE"))
248 elsif ($icon eq get_my_icon
('next')
249 && $EXTERNAL_DOWN_LINK && $EXTERNAL_DOWN_TITLE) {
250 return (make_href
($EXTERNAL_DOWN_LINK, $icon),
251 make_href
($EXTERNAL_DOWN_LINK, "$EXTERNAL_DOWN_TITLE"))
253 return (&inactive_img
($icon), "");
256 sub add_special_link
{
257 my($icon, $file, $current_file) = @_;
258 if ($icon =~ /\<tex2html_([_a-z]+)_visible_mark\>/) {
259 my $r = get_my_icon
($1);
260 $icon =~ s/\<tex2html_[_a-z]+_visible_mark\>/$r/;
262 return (($file && ($file ne $current_file))
263 ? make_href
($file, $icon)
267 # The img_tag() function seems only to be called with the parameter
268 # 'anchor_invisible_mark', which we want to turn into ''. Since
269 # replace_icon_marks() is the only interesting caller, and all it really
270 # does is call img_tag(), we can just define the hook alternative to be
273 sub replace_icons_hook
{}
276 # get rid of that nasty <SPAN CLASS="arabic">...</SPAN>
277 my($ctr, $val, $id, $text) = &read_counter_value
(@_[0]);
278 return ($val ? farabic
($val) : "0") . $text;
283 # this is used to ensure common index key generation and a stable sort
284 my($str,$extra) = @_;
285 sprintf('%s###%s%010d', $str, $extra, ++$global{'max_id'});
289 my($mark,$datafile,$columns,$letters,$prefix) = @_;
290 my $prog = "$myrootdir/tools/buildindex.py";
293 $index = `$prog --columns $columns --letters $datafile`;
296 $index = `$prog --columns $columns $datafile`;
298 if (!s/$mark/$prefix$index/) {
299 print "\nCould not locate index mark: $mark";
304 print "\nBuilding HTML for the index ...";
306 insert_index
($idx_mark, 'index.dat', $INDEX_COLUMNS, 1, '');
310 $idx_module_mark = '<tex2html_idx_module_mark>';
311 $idx_module_title = 'Module Index';
314 print "\nBuilding HTML for the module index ...";
320 foreach $key (keys %Modules) {
321 $key =~ s/<tt>([a-zA-Z0-9._]*)<\/tt>/\
1/;
322 my $plat = "$ModulePlatforms{$key}";
324 if ($plat eq $IGNORE_PLATFORM_ANNOTATION);
327 if ($prevplat ne $plat);
332 open(MODIDXFILE
, '>modindex.dat') || die "\n$!\n";
333 foreach $key (keys %Modules) {
334 # dump the line in the data file; just use a dummy seqno field
336 my $moditem = "$Modules{$key}";
338 $key =~ s/<tt>([a-zA-Z0-9._]*)<\/tt>/\
1/;
339 if ($ModulePlatforms{$key} && !$allthesame) {
340 $plat = (" <em>(<span class=\"platform\">$ModulePlatforms{$key}"
343 print MODIDXFILE
$moditem . $IDXFILE_FIELD_SEP
344 . "<tt class=\"module\">$key</tt>$plat###\n";
348 if ($GLOBAL_MODULE_INDEX) {
349 $prefix = <<MODULE_INDEX_PREFIX;
351 <p> This index only lists modules documented in this manual.
352 The <em class="citetitle"><a href="$GLOBAL_MODULE_INDEX">Global Module
353 Index</a></em> lists all modules that are documented in this set
358 $prefix .= <<PLAT_DISCUSS;
360 <p> Some module names are followed by an annotation indicating what
361 platform they are available on.</p>
365 insert_index($idx_module_mark, 'modindex.dat', $MODULE_INDEX_COLUMNS, 0,
369 # replace both indexes as needed:
371 add_idx() if (/$idx_mark/);
372 process_python_state();
373 if ($MODULE_INDEX_FILE) {
375 open(MYFILE, "<$MODULE_INDEX_FILE");
376 sysread(MYFILE, $_, 1024*1024);
379 open(MYFILE,">$MODULE_INDEX_FILE");
386 # In addition to the standard stuff, add label to allow named node files and
387 # support suppression of the page complete (for HTML Help use).
388 sub do_cmd_tableofcontents {
391 $tocfile = $CURRENT_FILE;
392 my($closures,$reopens) = preserve_open_tags();
393 anchor_label('contents', $CURRENT_FILE, $_); # this is added
394 join('', "<BR>\n\\tableofchildlinks[off]", $closures
395 , make_section_heading($toc_title, 'H2'), $toc_mark
398 # In addition to the standard stuff, add label to allow named node files.
399 sub do_cmd_listoffigures {
402 $loffile = $CURRENT_FILE;
403 my($closures,$reopens) = preserve_open_tags();
404 anchor_label('lof', $CURRENT_FILE, $_); # this is added
405 join('', "<BR>\n", $closures
406 , make_section_heading($lof_title, 'H2'), $lof_mark
409 # In addition to the standard stuff, add label to allow named node files.
410 sub do_cmd_listoftables {
413 $lotfile = $CURRENT_FILE;
414 my($closures,$reopens) = preserve_open_tags();
415 anchor_label('lot', $CURRENT_FILE, $_); # this is added
416 join('', "<BR>\n", $closures
417 , make_section_heading($lot_title, 'H2'), $lot_mark
420 # In addition to the standard stuff, add label to allow named node files.
421 sub do_cmd_textohtmlinfopage {
424 anchor_label("about",$CURRENT_FILE,$_); # this is added
426 my $the_version = ''; # and the rest is
427 if ($t_date) { # mostly ours
428 $the_version = ",\n$t_date";
429 if ($PACKAGE_VERSION) {
430 $the_version .= ", Release $PACKAGE_VERSION$RELEASE_INFO";
434 open(ABOUT, "<$ABOUT_FILE") || die "\n$!\n";
435 sysread(ABOUT, $about, 1024*1024);
440 "<strong>$t_title</strong>$the_version\n",
443 : join('', $close_all, $INFO,"\n", $open_all, $_));
447 # $idx_mark will be replaced with the real index at the end
448 sub do_cmd_textohtmlindex {
451 $idxfile = $CURRENT_FILE;
452 if (%index_labels) { make_index_labels(); }
453 if (($SHORT_INDEX) && (%index_segment)) { make_preindex(); }
454 else { $preindex = ''; }
455 my $heading = make_section_heading($idx_title, 'h2') . $idx_mark;
456 my($pre,$post) = minimize_open_tags($heading);
457 anchor_label('genindex',$CURRENT_FILE,$_); # this is added
458 return "<br>\n" . $pre . $_;
461 $MODULE_INDEX_FILE = '';
463 # $idx_module_mark will be replaced with the real index at the end
464 sub do_cmd_textohtmlmoduleindex {
466 $TITLE = $idx_module_title;
467 anchor_label('modindex', $CURRENT_FILE, $_);
468 $MODULE_INDEX_FILE = "$CURRENT_FILE";
469 $_ = ('<p>' . make_section_heading($idx_module_title, 'h2')
470 . $idx_module_mark . $_);
474 # The bibliography and the index should be treated as separate
475 # sections in their own HTML files. The \bibliography{} command acts
476 # as a sectioning command that has the desired effect. But when the
477 # bibliography is constructed manually using the thebibliography
478 # environment, or when using the theindex environment it is not
479 # possible to use the normal sectioning mechanism. This subroutine
480 # inserts a \bibliography{} or a dummy \textohtmlindex command just
481 # before the appropriate environments to force sectioning.
483 # XXX This *assumes* that if there are two {theindex} environments,
484 # the first is the module index and the second is the standard
485 # index. This is sufficient for the current Python documentation,
486 # but that's about it.
488 sub add_bbl_and_idx_dummy_commands {
489 my $id = $global{'max_id'};
491 if (/[\\]tableofcontents/) {
492 $HAVE_TABLE_OF_CONTENTS = 1;
494 s/([\\]begin\s*$O\d+$C\s*thebibliography)/$bbl_cnt++; $1/eg;
495 s/([\\]begin\s*$O\d+$C\s*thebibliography)/$id++; "\\bibliography$O$id$C$O$id$C $1"/geo;
496 my(@parts) = split(/\\begin\s*$O\d+$C\s*theindex/);
497 if (scalar(@parts) == 3) {
498 # Be careful to re-write the string in place, since $_ is *not*
499 # returned explicity; *** nasty side-effect dependency! ***
500 print "\nadd_bbl_and_idx_dummy_commands ==> adding general index";
501 print "\nadd_bbl_and_idx_dummy_commands ==> adding module index";
502 my $rx = "([\\\\]begin\\s*$O\\d+$C\\s*theindex[\\s\\S]*)"
503 . "([\\\\]begin\\s*$O\\d+$C\\s*theindex)";
504 s/$rx/\\textohtmlmoduleindex \1 \\textohtmlindex \2/o;
505 # Add a button to the navigation areas:
506 $CUSTOM_BUTTONS .= ('<a href="modindex.html" title="Module Index">'
507 . get_my_icon('modules')
509 $HAVE_MODULE_INDEX = 1;
510 $HAVE_GENERAL_INDEX = 1;
512 elsif (scalar(@parts) == 2) {
513 print "\nadd_bbl_and_idx_dummy_commands ==> adding general index";
514 my $rx = "([\\\\]begin\\s*$O\\d+$C\\s*theindex)";
515 s/$rx/\\textohtmlindex \1/o;
516 $HAVE_GENERAL_INDEX = 1;
518 elsif (scalar(@parts) == 1) {
519 print "\nadd_bbl_and_idx_dummy_commands ==> no index found";
520 $CUSTOM_BUTTONS .= get_my_icon('blank');
521 $global{'max_id'} = $id; # not sure why....
522 s/([\\]begin\s*$O\d+$C\s*theindex)/\\textohtmlindex $1/o;
523 s/[\\]printindex/\\textohtmlindex /o;
526 die "\n\nBad number of index environments!\n\n";
528 #----------------------------------------------------------------------
529 lib_add_bbl_and_idx_dummy_commands()
530 if defined(&lib_add_bbl_and_idx_dummy_commands);
533 # The bibliographic references, the appendices, the lists of figures
534 # and tables etc. must appear in the contents table at the same level
535 # as the outermost sectioning command. This subroutine finds what is
536 # the outermost level and sets the above to the same level;
538 sub set_depth_levels {
539 # Sets $outermost_level
541 #RRM: do not alter user-set value for $MAX_SPLIT_DEPTH
542 foreach $level ("part", "chapter", "section", "subsection",
543 "subsubsection", "paragraph") {
544 last if (($outermost_level) = /\\($level)$delimiter_rx/);
546 $level = ($outermost_level ? $section_commands{$outermost_level} :
547 do {$outermost_level = 'section'; 3;});
549 #RRM: but calculate value for $MAX_SPLIT_DEPTH when a $REL_DEPTH was given
550 if ($REL_DEPTH && $MAX_SPLIT_DEPTH) {
551 $MAX_SPLIT_DEPTH = $level + $MAX_SPLIT_DEPTH;
552 } elsif (!($MAX_SPLIT_DEPTH)) { $MAX_SPLIT_DEPTH = 1 };
554 %unnumbered_section_commands = ('tableofcontents' => $level,
555 'listoffigures' => $level,
556 'listoftables' => $level,
557 'bibliography' => $level,
558 'textohtmlindex' => $level,
559 'textohtmlmoduleindex' => $level);
560 $section_headings{'textohtmlmoduleindex'} = 'h1';
562 %section_commands = (%unnumbered_section_commands,
569 # This changes the markup used for {verbatim} environments, and is the
570 # best way I've found that ensures the <dl> goes on the outside of the
573 # Note that this *must* be done in the init file, not the python.perl
574 # style support file. The %declarations must be set before
575 # initialize() is called in the main LaTeX2HTML script (which happens
576 # before style files are loaded).
578 %declarations = ('preform' => '<dl><dd><pre class="verbatim"></pre></dl>',
582 # This is added to get rid of the long comment that follows the
583 # doctype declaration; MSIE5 on NT4 SP4 barfs on it and drops the
584 # content of the page.
585 $MY_PARTIAL_HEADER = '';
586 sub make_head_and_body {
587 my($title, $body) = @_;
588 $body = " $body" unless ($body eq '');
590 my($version, $isolanguage) = ($HTML_VERSION, 'EN');
591 my %isolanguages = ( 'english', 'EN' , 'USenglish', 'EN.US'
592 , 'original', 'EN' , 'german' , 'DE'
593 , 'austrian', 'DE.AT', 'french' , 'FR'
595 $isolanguage = $isolanguages{$default_language};
596 $isolanguage = 'EN' unless $isolanguage;
597 $title = &purify($title,1);
598 eval("\$title = ". $default_title ) unless ($title);
600 # allow user-modification of the <TITLE> tag; thanks Dan Young
601 if (defined &custom_TITLE_hook) {
602 $title = &custom_TITLE_hook($title, $toc_sec_title);
605 if ($DOCTYPE =~ /\/\/[\w\.]+\s*$/) { # language spec included
606 $DTDcomment = "<!DOCTYPE html PUBLIC \"$DOCTYPE\">\n";
608 $DTDcomment = "<!DOCTYPE html PUBLIC \"$DOCTYPE//"
609 . ($ISO_LANGUAGE ? $ISO_LANGUAGE : $isolanguage) . "\">\n";
611 if ($MY_PARTIAL_HEADER eq '') {
612 $STYLESHEET = $FILE.".css" unless $STYLESHEET;
613 $MY_PARTIAL_HEADER = join('',
614 ($CHARSET && $HTML_VERSION ge "2.1"
615 ? ('<meta http-equiv="Content-Type" content="text/html; '
616 . "charset=$charset\">\n")
618 ($BASE ? "<base href=\"$BASE\">\n" : ''),
619 "<link rel=\"STYLESHEET\" href=\"$STYLESHEET\">\n",
620 "<link rel=\"first\" href=\"$FILE.html\">\n",
621 ($HAVE_TABLE_OF_CONTENTS
622 ? ('<link rel="contents" href="contents.html" title="Contents">'
626 ? '<link rel="index" href="genindex.html" title="Index">'
628 # disable for now -- Mozilla doesn't do well with multiple indexes
629 # ($HAVE_MODULE_INDEX
630 # ? '<link rel="index" href="modindex.html" title="Module Index">'
636 if (!$charset && $CHARSET) { $charset = $CHARSET; $charset =~ s/_/\-/go; }
638 join('', ($DOCTYPE ? $DTDcomment : '' )
639 , "<html>\n<head>\n<title>", $title, "</title>\n"
640 , &meta_information($title)
642 , "\n</head>\n<body$body>");
645 1; # This must be the last line