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;
37 # A little painful, but lets us clean up the top level directory a little,
38 # and not be tied to the current directory (as far as I can tell). Testing
39 # an existing definition of $mydir is needed since it cannot be computed when
40 # run under mkhowto with recent versions of LaTeX2HTML, since this file is
41 # not read directly by LaTeX2HTML any more. mkhowto is required to prepend
42 # the required definition at the top of the actual input file.
44 if (!defined $mydir) {
47 ($myname, $mydir, $myext) = fileparse
(__FILE__
, '\..*');
48 chop $mydir; # remove trailing '/'
49 $mydir = getcwd
() . "$dd$mydir"
50 unless $mydir =~ s
|^/|/|;
52 $LATEX2HTMLSTYLES = "$mydir$envkey$LATEX2HTMLSTYLES";
55 ($myrootname, $myrootdir, $myext) = fileparse
($mydir, '\..*');
59 # Hackish way to get the appropriate paper-*/ directory into $TEXINPUTS;
60 # pass in the paper size (a4 or letter) as the environment variable PAPER
61 # to add the right directory. If not given, the current directory is
62 # added instead for use with HOWTO processing.
64 if (defined $ENV{'PAPER'}) {
65 $mytexinputs = "$myrootdir${dd}paper-$ENV{'PAPER'}$envkey";
68 $mytexinputs = getcwd
() . $envkey;
70 $mytexinputs .= "$myrootdir${dd}texinputs";
73 # Change this variable to change the text added in "About this document...";
74 # this should be an absolute pathname to get it right.
76 $ABOUT_FILE = "$myrootdir${dd}html${dd}stdabout.dat";
79 sub custom_driver_hook
{
81 # This adds the directory of the main input file to $TEXINPUTS; it
82 # seems to be sufficiently general that it should be fine for HOWTO
86 my($jobname, $dir, $ext) = fileparse
($file, '\..*');
87 $dir = L2hos
->Make_directory_absolute($dir);
89 $TEXINPUTS = "$dir$envkey$mytexinputs";
90 print "\nAdding $dir to \$TEXINPUTS\n";
96 sub make_nav_sectref
{
97 my($label,$title) = @_;
99 if ($title =~ /\<[aA] /) {
100 $title =~ s/\<[aA] /<a class="sectref" /;
103 $title = "<span class=\"sectref\">$title</span>";
105 return "<b class=\"navlabel\">$label:</b> $title\n";
111 $my_icon_tags{'next'} = 'Next Page';
112 $my_icon_tags{'next_page'} = 'Next Page';
113 $my_icon_tags{'previous'} = 'Previous Page';
114 $my_icon_tags{'previous_page'} = 'Previous Page';
115 $my_icon_tags{'up'} = 'Up One Level';
116 $my_icon_tags{'contents'} = 'Contents';
117 $my_icon_tags{'index'} = 'Index';
118 $my_icon_tags{'modules'} = 'Module Index';
121 $my_icon_names{'previous_page'} = 'previous';
122 $my_icon_names{'next_page'} = 'next';
126 my $text = $my_icon_tags{$name};
127 if ($my_icon_names{$name}) {
128 $name = $my_icon_names{$name};
133 my $iconserver = ($ICONSERVER eq '.') ?
'' : "$ICONSERVER/";
134 return "<img src=\"$iconserver$name.$IMAGE_TYPE\"\n border=\"0\""
135 . " height=\"32\"\n alt=\"$text\" width=\"32\">";
140 if ($s =~ /\<tex2html_([a-z_]+)_visible_mark\>/) {
141 my $r = get_my_icon
($1);
142 $s =~ s/\<tex2html_[a-z_]+_visible_mark\>/$r/;
149 my $BLANK_ICON = get_my_icon
('blank');
150 $NEXT = $NEXT_TITLE ? use_my_icon
("$NEXT") : $BLANK_ICON;
151 $UP = $UP_TITLE ? use_my_icon
("$UP") : $BLANK_ICON;
152 $PREVIOUS = $PREVIOUS_TITLE ? use_my_icon
("$PREVIOUS") : $BLANK_ICON;
153 $CONTENTS = use_my_icon
("$CONTENTS");
154 $INDEX = $INDEX ? use_my_icon
("$INDEX") : $BLANK_ICON;
155 if (!$CUSTOM_BUTTONS) {
156 $CUSTOM_BUTTONS = $BLANK_ICON;
158 $s = ('<table align="center" width="100%" cellpadding="0" cellspacing="2">'
161 . "\n<td>$PREVIOUS</td>"
165 . "\n<td align=\"center\" width=\"100%\">$t_title</td>"
167 . "\n<td>$CONTENTS</td>"
168 . "\n<td>$CUSTOM_BUTTONS</td>" # module index
169 . "\n<td>$INDEX</td>"
170 . "\n</tr></table>\n"
172 . make_nav_sectref
("Previous", $PREVIOUS_TITLE)
173 . make_nav_sectref
("Up", $UP_TITLE)
174 . make_nav_sectref
("Next", $NEXT_TITLE)
176 # remove these; they are unnecessary and cause errors from validation
177 $s =~ s/ NAME="tex2html\d+"\n */ /g;
181 sub get_version_text
{
182 if ($PACKAGE_VERSION ne '' && $t_date) {
183 return ("<span class=\"release-info\">"
184 . "Release $PACKAGE_VERSION$RELEASE_INFO,"
185 . " documentation updated on $t_date.</span>");
187 if ($PACKAGE_VERSION ne '') {
188 return ("<span class=\"release-info\">"
189 . "Release $PACKAGE_VERSION$RELEASE_INFO.</span>");
192 return ("<span class=\"release-info\">Documentation released on "
193 . "$t_date.</span>");
199 sub top_navigation_panel
{
205 sub bot_navigation_panel
{
214 # Returns a pair (iconic link, textual link)
215 my($icon, $current_file, @link) = @_;
216 my($dummy, $file, $title) = split($delim,
217 $section_info{join(' ',@link)});
218 if ($icon =~ /\<tex2html_([_a-z]+)_visible_mark\>/) {
219 my $r = get_my_icon
($1);
220 $icon =~ s/\<tex2html_[_a-z]+_visible_mark\>/$r/;
222 if ($title && ($file ne $current_file)) {
223 $title = purify
($title);
224 $title = get_first_words
($title, $WORDS_IN_NAVIGATION_PANEL_TITLES);
225 return (make_href
($file, $icon), make_href
($file, "$title"))
227 elsif ($icon eq get_my_icon
('up') && $EXTERNAL_UP_LINK) {
228 return (make_href
($EXTERNAL_UP_LINK, $icon),
229 make_href
($EXTERNAL_UP_LINK, "$EXTERNAL_UP_TITLE"))
231 elsif ($icon eq get_my_icon
('previous')
232 && $EXTERNAL_PREV_LINK && $EXTERNAL_PREV_TITLE) {
233 return (make_href
($EXTERNAL_PREV_LINK, $icon),
234 make_href
($EXTERNAL_PREV_LINK, "$EXTERNAL_PREV_TITLE"))
236 elsif ($icon eq get_my_icon
('next')
237 && $EXTERNAL_DOWN_LINK && $EXTERNAL_DOWN_TITLE) {
238 return (make_href
($EXTERNAL_DOWN_LINK, $icon),
239 make_href
($EXTERNAL_DOWN_LINK, "$EXTERNAL_DOWN_TITLE"))
241 return (&inactive_img
($icon), "");
244 sub add_special_link
{
245 my($icon, $file, $current_file) = @_;
246 if ($icon =~ /\<tex2html_([_a-z]+)_visible_mark\>/) {
247 my $r = get_my_icon
($1);
248 $icon =~ s/\<tex2html_[_a-z]+_visible_mark\>/$r/;
250 return (($file && ($file ne $current_file))
251 ? make_href
($file, $icon)
255 # The img_tag() function seems only to be called with the parameter
256 # 'anchor_invisible_mark', which we want to turn into ''. Since
257 # replace_icon_marks() is the only interesting caller, and all it really
258 # does is call img_tag(), we can just define the hook alternative to be
261 sub replace_icons_hook
{}
264 # get rid of that nasty <SPAN CLASS="arabic">...</SPAN>
265 my($ctr, $val, $id, $text) = &read_counter_value
(@_[0]);
266 return ($val ? farabic
($val) : "0") . $text;
271 # this is used to ensure common index key generation and a stable sort
272 my($str,$extra) = @_;
273 sprintf('%s###%s%010d', $str, $extra, ++$global{'max_id'});
277 my($mark,$datafile,$columns,$letters,$prefix) = @_;
278 my $prog = "$myrootdir/tools/buildindex.py";
281 $index = `$prog --columns $columns --letters $datafile`;
284 $index = `$prog --columns $columns $datafile`;
286 if (!s/$mark/$prefix$index/) {
287 print "\nCould not locate index mark: $mark";
292 print "\nBuilding HTML for the index ...";
294 insert_index
($idx_mark, 'index.dat', $INDEX_COLUMNS, 1, '');
298 $idx_module_mark = '<tex2html_idx_module_mark>';
299 $idx_module_title = 'Module Index';
302 print "\nBuilding HTML for the module index ...";
308 foreach $key (keys %Modules) {
309 $key =~ s/<tt>([a-zA-Z0-9._]*)<\/tt>/\
1/;
310 my $plat = "$ModulePlatforms{$key}";
312 if ($plat eq $IGNORE_PLATFORM_ANNOTATION);
315 if ($prevplat ne $plat);
320 open(MODIDXFILE
, '>modindex.dat') || die "\n$!\n";
321 foreach $key (keys %Modules) {
322 # dump the line in the data file; just use a dummy seqno field
324 my $moditem = "$Modules{$key}";
326 $key =~ s/<tt>([a-zA-Z0-9._]*)<\/tt>/\
1/;
327 if ($ModulePlatforms{$key} && !$allthesame) {
328 $plat = (" <em>(<span class=\"platform\">$ModulePlatforms{$key}"
331 print MODIDXFILE
$moditem . $IDXFILE_FIELD_SEP
332 . "<tt class=\"module\">$key</tt>$plat###\n";
336 if ($GLOBAL_MODULE_INDEX) {
337 $prefix = <<MODULE_INDEX_PREFIX;
339 <p> This index only lists modules documented in this manual.
340 The <em class="citetitle"><a href="$GLOBAL_MODULE_INDEX">Global Module
341 Index</a></em> lists all modules that are documented in this set
346 $prefix .= <<PLAT_DISCUSS;
348 <p> Some module names are followed by an annotation indicating what
349 platform they are available on.</p>
353 insert_index($idx_module_mark, 'modindex.dat', $MODULE_INDEX_COLUMNS, 0,
357 # replace both indexes as needed:
359 add_idx() if (/$idx_mark/);
360 process_python_state();
361 if ($MODULE_INDEX_FILE) {
363 open(MYFILE, "<$MODULE_INDEX_FILE");
364 sysread(MYFILE, $_, 1024*1024);
367 open(MYFILE,">$MODULE_INDEX_FILE");
374 # In addition to the standard stuff, add label to allow named node files and
375 # support suppression of the page complete (for HTML Help use).
376 sub do_cmd_tableofcontents {
379 $tocfile = $CURRENT_FILE;
380 my($closures,$reopens) = preserve_open_tags();
381 anchor_label('contents', $CURRENT_FILE, $_); # this is added
382 join('', "<BR>\n\\tableofchildlinks[off]", $closures
383 , make_section_heading($toc_title, 'H2'), $toc_mark
386 # In addition to the standard stuff, add label to allow named node files.
387 sub do_cmd_listoffigures {
390 $loffile = $CURRENT_FILE;
391 my($closures,$reopens) = preserve_open_tags();
392 anchor_label('lof', $CURRENT_FILE, $_); # this is added
393 join('', "<BR>\n", $closures
394 , make_section_heading($lof_title, 'H2'), $lof_mark
397 # In addition to the standard stuff, add label to allow named node files.
398 sub do_cmd_listoftables {
401 $lotfile = $CURRENT_FILE;
402 my($closures,$reopens) = preserve_open_tags();
403 anchor_label('lot', $CURRENT_FILE, $_); # this is added
404 join('', "<BR>\n", $closures
405 , make_section_heading($lot_title, 'H2'), $lot_mark
408 # In addition to the standard stuff, add label to allow named node files.
409 sub do_cmd_textohtmlinfopage {
412 anchor_label("about",$CURRENT_FILE,$_); # this is added
414 my $the_version = ''; # and the rest is
415 if ($t_date) { # mostly ours
416 $the_version = ",\n$t_date";
417 if ($PACKAGE_VERSION) {
418 $the_version .= ", Release $PACKAGE_VERSION$RELEASE_INFO";
424 "<strong>$t_title</strong>$the_version\n",
427 : join('', $close_all, $INFO,"\n", $open_all, $_));
431 # $idx_mark will be replaced with the real index at the end
432 sub do_cmd_textohtmlindex {
435 $idxfile = $CURRENT_FILE;
436 if (%index_labels) { make_index_labels(); }
437 if (($SHORT_INDEX) && (%index_segment)) { make_preindex(); }
438 else { $preindex = ''; }
439 my $heading = make_section_heading($idx_title, 'h2') . $idx_mark;
440 my($pre,$post) = minimize_open_tags($heading);
441 anchor_label('genindex',$CURRENT_FILE,$_); # this is added
442 return "<br>\n" . $pre . $_;
445 $MODULE_INDEX_FILE = '';
447 # $idx_module_mark will be replaced with the real index at the end
448 sub do_cmd_textohtmlmoduleindex {
450 $TITLE = $idx_module_title;
451 anchor_label('modindex', $CURRENT_FILE, $_);
452 $MODULE_INDEX_FILE = "$CURRENT_FILE";
453 $_ = ('<p>' . make_section_heading($idx_module_title, 'h2')
454 . $idx_module_mark . $_);
458 # The bibliography and the index should be treated as separate
459 # sections in their own HTML files. The \bibliography{} command acts
460 # as a sectioning command that has the desired effect. But when the
461 # bibliography is constructed manually using the thebibliography
462 # environment, or when using the theindex environment it is not
463 # possible to use the normal sectioning mechanism. This subroutine
464 # inserts a \bibliography{} or a dummy \textohtmlindex command just
465 # before the appropriate environments to force sectioning.
467 # XXX This *assumes* that if there are two {theindex} environments,
468 # the first is the module index and the second is the standard
469 # index. This is sufficient for the current Python documentation,
470 # but that's about it.
472 sub add_bbl_and_idx_dummy_commands {
473 my $id = $global{'max_id'};
475 s/([\\]begin\s*$O\d+$C\s*thebibliography)/$bbl_cnt++; $1/eg;
476 s/([\\]begin\s*$O\d+$C\s*thebibliography)/$id++; "\\bibliography$O$id$C$O$id$C $1"/geo;
477 my(@parts) = split(/\\begin\s*$O\d+$C\s*theindex/);
478 if (scalar(@parts) == 3) {
479 # Be careful to re-write the string in place, since $_ is *not*
480 # returned explicity; *** nasty side-effect dependency! ***
481 print "\nadd_bbl_and_idx_dummy_commands ==> adding module index";
482 my $rx = "([\\\\]begin\\s*$O\\d+$C\\s*theindex[\\s\\S]*)"
483 . "([\\\\]begin\\s*$O\\d+$C\\s*theindex)";
484 s/$rx/\\textohtmlmoduleindex \1 \\textohtmlindex \2/o;
485 # Add a button to the navigation areas:
486 $CUSTOM_BUTTONS .= ('<a href="modindex.html" title="Module Index">'
487 . get_my_icon('modules')
491 $CUSTOM_BUTTONS .= get_my_icon('blank');
492 $global{'max_id'} = $id; # not sure why....
493 s/([\\]begin\s*$O\d+$C\s*theindex)/\\textohtmlindex $1/o;
494 s/[\\]printindex/\\textohtmlindex /o;
496 #----------------------------------------------------------------------
497 lib_add_bbl_and_idx_dummy_commands()
498 if defined(&lib_add_bbl_and_idx_dummy_commands);
501 # The bibliographic references, the appendices, the lists of figures
502 # and tables etc. must appear in the contents table at the same level
503 # as the outermost sectioning command. This subroutine finds what is
504 # the outermost level and sets the above to the same level;
506 sub set_depth_levels {
507 # Sets $outermost_level
509 #RRM: do not alter user-set value for $MAX_SPLIT_DEPTH
510 foreach $level ("part", "chapter", "section", "subsection",
511 "subsubsection", "paragraph") {
512 last if (($outermost_level) = /\\($level)$delimiter_rx/);
514 $level = ($outermost_level ? $section_commands{$outermost_level} :
515 do {$outermost_level = 'section'; 3;});
517 #RRM: but calculate value for $MAX_SPLIT_DEPTH when a $REL_DEPTH was given
518 if ($REL_DEPTH && $MAX_SPLIT_DEPTH) {
519 $MAX_SPLIT_DEPTH = $level + $MAX_SPLIT_DEPTH;
520 } elsif (!($MAX_SPLIT_DEPTH)) { $MAX_SPLIT_DEPTH = 1 };
522 %unnumbered_section_commands = ('tableofcontents' => $level,
523 'listoffigures' => $level,
524 'listoftables' => $level,
525 'bibliography' => $level,
526 'textohtmlindex' => $level,
527 'textohtmlmoduleindex' => $level);
528 $section_headings{'textohtmlmoduleindex'} = 'h1';
530 %section_commands = (%unnumbered_section_commands,
537 # This changes the markup used for {verbatim} environments, and is the
538 # best way I've found that ensures the <dl> goes on the outside of the
541 # Note that this *must* be done in the init file, not the python.perl
542 # style support file. The %declarations must be set before
543 # initialize() is called in the main LaTeX2HTML script (which happens
544 # before style files are loaded).
546 %declarations = ('preform' => '<dl><dd><pre class="verbatim"></pre></dl>',
550 # This is added to get rid of the long comment that follows the
551 # doctype declaration; MSIE5 on NT4 SP4 barfs on it and drops the
552 # content of the page.
553 sub make_head_and_body {
554 my($title, $body) = @_;
555 $body = " $body" unless ($body eq '');
557 my($version, $isolanguage) = ($HTML_VERSION, 'EN');
558 my %isolanguages = ( 'english', 'EN' , 'USenglish', 'EN.US'
559 , 'original', 'EN' , 'german' , 'DE'
560 , 'austrian', 'DE.AT', 'french' , 'FR'
562 $isolanguage = $isolanguages{$default_language};
563 $isolanguage = 'EN' unless $isolanguage;
564 $title = &purify($title,1);
565 eval("\$title = ". $default_title ) unless ($title);
567 # allow user-modification of the <TITLE> tag; thanks Dan Young
568 if (defined &custom_TITLE_hook) {
569 $title = &custom_TITLE_hook($title, $toc_sec_title);
572 if ($DOCTYPE =~ /\/\/[\w\.]+\s*$/) { # language spec included
573 $DTDcomment = "<!DOCTYPE html PUBLIC \"$DOCTYPE\">\n";
575 $DTDcomment = "<!DOCTYPE html PUBLIC \"$DOCTYPE//"
576 . ($ISO_LANGUAGE ? $ISO_LANGUAGE : $isolanguage) . "\">\n";
579 $STYLESHEET = $FILE.".css" unless $STYLESHEET;
580 if (!$charset && $CHARSET) { $charset = $CHARSET; $charset =~ s/_/\-/go; }
582 join('', ($DOCTYPE ? $DTDcomment : '' )
583 ,"<html>\n<head>\n<title>", $title, "</title>\n"
584 , &meta_information($title)
585 , ($CHARSET && $HTML_VERSION ge "2.1" ?
586 "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=$charset\">\n"
588 , ($BASE ? "<base href=\"$BASE\">\n" : "" )
589 , "<link rel=\"STYLESHEET\" href=\"$STYLESHEET\">"
591 , "\n</head>\n<body$body>");
594 1; # This must be the last line