Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 1 | #LaTeX2HTML Version 96.1 : dot.latex2html-init -*- perl -*- |
| 2 | # |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 3 | # Significantly revised by Fred L. Drake, Jr. <fdrake@acm.org> for use |
| 4 | # with the Python documentation. |
| 5 | # |
| 6 | # New name to avoid distributing "dot" files with the Python documentation. |
| 7 | # |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 8 | |
| 9 | $INFO = 1; # 0 = do not make a "About this document..." section |
| 10 | $MAX_LINK_DEPTH = 3; |
| 11 | |
| 12 | $NUMBERED_FOOTNOTES = 1; |
| 13 | |
| 14 | # Python documentation uses section numbers to support references to match |
| 15 | # in the printed and online versions. |
| 16 | # |
| 17 | $SHOW_SECTION_NUMBERS = 1; |
| 18 | |
| 19 | $ICONSERVER = '../icons'; |
| 20 | |
| 21 | $CHILDLINE = "\n<p><hr>\n"; |
| 22 | $VERBOSITY = 0; |
| 23 | |
Fred Drake | db34a1e | 1998-03-10 23:02:57 +0000 | [diff] [blame] | 24 | # Locate a file that's been "require"d. Assumes that the file name of interest |
| 25 | # is unique within the set of loaded files, after directory names have been |
| 26 | # stripped. Only the directory is returned. |
| 27 | # |
| 28 | sub find_my_file{ |
Fred Drake | 1191692 | 1998-04-02 22:30:57 +0000 | [diff] [blame] | 29 | my($myfile,$key,$tmp,$mydir) = (@_[0], '', '', ''); |
Fred Drake | db34a1e | 1998-03-10 23:02:57 +0000 | [diff] [blame] | 30 | foreach $key (keys %INC) { |
| 31 | $tmp = "$key"; |
| 32 | $tmp =~ s|^.*/||o; |
| 33 | if ($tmp eq $myfile) { |
Fred Drake | db34a1e | 1998-03-10 23:02:57 +0000 | [diff] [blame] | 34 | $mydir = $INC{$key}; |
| 35 | } |
| 36 | } |
| 37 | $mydir =~ s|/[^/]*$||; |
| 38 | $mydir; |
| 39 | } |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 40 | |
Fred Drake | c9f2c14 | 1998-03-11 12:08:21 +0000 | [diff] [blame] | 41 | |
Fred Drake | db34a1e | 1998-03-10 23:02:57 +0000 | [diff] [blame] | 42 | # A little painful, but lets us clean up the top level directory a little, |
| 43 | # and not be tied to the current directory (as far as I can tell). |
| 44 | # |
Fred Drake | c9f2c14 | 1998-03-11 12:08:21 +0000 | [diff] [blame] | 45 | use Cwd; |
| 46 | use File::Basename; |
| 47 | ($myname, $mydir, $myext) = fileparse(__FILE__, '\..*'); |
| 48 | chop $mydir; # remove trailing '/' |
| 49 | $mydir = getcwd() . "$dd$mydir" |
| 50 | unless $mydir =~ s|^/|/|; |
Fred Drake | db34a1e | 1998-03-10 23:02:57 +0000 | [diff] [blame] | 51 | $LATEX2HTMLSTYLES = "$mydir$envkey$LATEX2HTMLSTYLES"; |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 52 | |
Fred Drake | 235e6b1 | 1998-03-27 05:19:43 +0000 | [diff] [blame] | 53 | ($myrootname, $myrootdir, $myext) = fileparse($mydir, '\..*'); |
| 54 | chop $myrootdir; |
| 55 | |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 56 | |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 57 | sub make_nav_panel{ |
| 58 | ($NEXT_TITLE ? "$NEXT\n" : '') |
| 59 | . ($UP_TITLE ? "$UP\n" : '') |
| 60 | . ($PREVIOUS_TITLE ? "$PREVIOUS\n" : '') |
| 61 | . "$CONTENTS\n$INDEX" |
| 62 | # . " $CUSTOM_BUTTONS" |
| 63 | . "<br>\n" |
| 64 | . ($NEXT_TITLE ? "<b> Next:</b> $NEXT_TITLE\n" : '') |
| 65 | . ($UP_TITLE ? "<b>Up:</b> $UP_TITLE\n" : '') |
| 66 | . ($PREVIOUS_TITLE ? "<b>Previous:</b> $PREVIOUS_TITLE\n" : ''); |
| 67 | } |
| 68 | |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 69 | sub top_navigation_panel { |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 70 | "<div class=navigation>\n" |
| 71 | . &make_nav_panel |
| 72 | . "<br><hr><p></div>" |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | sub bot_navigation_panel { |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 76 | "<div class=navigation><hr>" |
| 77 | . &make_nav_panel |
| 78 | . "</div>" |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 82 | sub gen_index_id { |
| 83 | # this is used to ensure common index key generation and a stable sort |
Fred Drake | 235e6b1 | 1998-03-27 05:19:43 +0000 | [diff] [blame] | 84 | my($str,$extra) = @_; |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 85 | sprintf("%s###%s%010d", $str, $extra, ++$global{'max_id'}); |
| 86 | } |
| 87 | |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 88 | sub make_index_entry { |
Fred Drake | 1191692 | 1998-04-02 22:30:57 +0000 | [diff] [blame] | 89 | my($br_id,$str) = @_; |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 90 | # If TITLE is not yet available (i.e the \index command is in the title of the |
| 91 | # current section), use $ref_before. |
| 92 | $TITLE = $ref_before unless $TITLE; |
| 93 | # Save the reference |
| 94 | $str = gen_index_id($str, ''); |
| 95 | $index{$str} .= &make_half_href("$CURRENT_FILE#$br_id"); |
| 96 | "<a name=\"$br_id\">$anchor_invisible_mark<\/a>"; |
| 97 | } |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 98 | |
Fred Drake | 235e6b1 | 1998-03-27 05:19:43 +0000 | [diff] [blame] | 99 | # use this instead with the buildindex.py tool |
| 100 | sub add_idx{ |
Fred Drake | 5a52519 | 1998-04-02 22:39:05 +0000 | [diff] [blame^] | 101 | print "\nDoing the index ..."; |
Fred Drake | 235e6b1 | 1998-03-27 05:19:43 +0000 | [diff] [blame] | 102 | close(IDXFILE); |
| 103 | my $index = `$myrootdir/tools/buildindex.py index.dat`; |
| 104 | s/$idx_mark/$index/; |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 105 | } |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 106 | |
| 107 | |
| 108 | $idx_module_mark = '<tex2html_idx_module_mark>'; |
| 109 | $idx_module_title = 'Module Index'; |
| 110 | |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 111 | sub add_module_idx{ |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 112 | print "\nDoing the module index ..."; |
Fred Drake | 235e6b1 | 1998-03-27 05:19:43 +0000 | [diff] [blame] | 113 | my $key; |
| 114 | my $index = "<p>"; |
| 115 | open(MODIDXFILE, ">modindex.dat") || die "\n$!\n"; |
| 116 | foreach $key (keys %Modules) { |
| 117 | # dump the line in the data file; just use a dummy seqno field |
| 118 | print MODIDXFILE "$Modules{$key}\0$key###\n"; |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 119 | } |
Fred Drake | 235e6b1 | 1998-03-27 05:19:43 +0000 | [diff] [blame] | 120 | close(MODIDXFILE); |
| 121 | $index = `$myrootdir/tools/buildindex.py modindex.dat`; |
| 122 | s/$idx_module_mark/$index<p>/; |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Fred Drake | 235e6b1 | 1998-03-27 05:19:43 +0000 | [diff] [blame] | 125 | # replace both indexes as needed: |
| 126 | sub add_idx_hook{ |
| 127 | &add_idx if (/$idx_mark/); |
| 128 | &add_module_idx if (/$idx_module_mark/); |
| 129 | } |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 130 | |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 131 | |
| 132 | # In addition to the standard stuff, add label to allow named node files. |
| 133 | sub do_cmd_tableofcontents { |
| 134 | local($_) = @_; |
| 135 | $TITLE = $toc_title; |
| 136 | $tocfile = $CURRENT_FILE; |
Fred Drake | 1191692 | 1998-04-02 22:30:57 +0000 | [diff] [blame] | 137 | my($closures,$reopens) = &preserve_open_tags(); |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 138 | &anchor_label("contents",$CURRENT_FILE,$_); # this is added |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 139 | join('', "<BR>\n", $closures |
| 140 | , &make_section_heading($toc_title, "H2"), $toc_mark |
| 141 | , $reopens, $_); |
| 142 | } |
| 143 | # In addition to the standard stuff, add label to allow named node files. |
| 144 | sub do_cmd_listoffigures { |
| 145 | local($_) = @_; |
| 146 | $TITLE = $lof_title; |
| 147 | $loffile = $CURRENT_FILE; |
Fred Drake | 1191692 | 1998-04-02 22:30:57 +0000 | [diff] [blame] | 148 | my($closures,$reopens) = &preserve_open_tags(); |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 149 | &anchor_label("lof",$CURRENT_FILE,$_); # this is added |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 150 | join('', "<BR>\n", $closures |
| 151 | , &make_section_heading($lof_title, "H2"), $lof_mark |
| 152 | , $reopens, $_); |
| 153 | } |
| 154 | # In addition to the standard stuff, add label to allow named node files. |
| 155 | sub do_cmd_listoftables { |
| 156 | local($_) = @_; |
| 157 | $TITLE = $lot_title; |
| 158 | $lotfile = $CURRENT_FILE; |
Fred Drake | 1191692 | 1998-04-02 22:30:57 +0000 | [diff] [blame] | 159 | my($closures,$reopens) = &preserve_open_tags(); |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 160 | &anchor_label("lot",$CURRENT_FILE,$_); # this is added |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 161 | join('', "<BR>\n", $closures |
| 162 | , &make_section_heading($lot_title, "H2"), $lot_mark |
| 163 | , $reopens, $_); |
| 164 | } |
| 165 | # In addition to the standard stuff, add label to allow named node files. |
| 166 | sub do_cmd_textohtmlinfopage { |
| 167 | local($_) = @_; |
| 168 | if ($INFO) { # |
| 169 | &anchor_label("about",$CURRENT_FILE,$_); # this is added |
| 170 | } # |
| 171 | ( ($INFO == 1) |
| 172 | ? join('', $close_all |
| 173 | , "<STRONG>$t_title</STRONG><P>\nThis document was generated using the\n" |
| 174 | , "<A HREF=\"$TEX2HTMLADDRESS\"><STRONG>LaTeX</STRONG>2<tt>HTML</tt></A>" |
| 175 | , " translator Version $TEX2HTMLVERSION\n" |
| 176 | , "<P>Copyright © 1993, 1994, 1995, 1996, 1997,\n" |
| 177 | , "<A HREF=\"$AUTHORADDRESS\">Nikos Drakos</A>, \n" |
| 178 | , "Computer Based Learning Unit, University of Leeds.\n" |
| 179 | , "<P>The command line arguments were: <BR>\n " |
| 180 | , "<STRONG>latex2html</STRONG> <tt>$argv</tt>.\n" |
| 181 | , "<P>The translation was initiated by $address_data[0] on $address_data[1]" |
| 182 | , $open_all, $_) |
| 183 | : join('', $close_all, $INFO,"\n", $open_all, $_)) |
| 184 | } |
| 185 | |
| 186 | # $idx_mark will be replaced with the real index at the end |
| 187 | sub do_cmd_textohtmlindex { |
| 188 | local($_) = @_; |
| 189 | $TITLE = $idx_title; |
| 190 | $idxfile = $CURRENT_FILE; |
Fred Drake | 235e6b1 | 1998-03-27 05:19:43 +0000 | [diff] [blame] | 191 | if (%index_labels) { make_index_labels(); } |
| 192 | if (($SHORT_INDEX) && (%index_segment)) { make_preindex(); } |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 193 | else { $preindex = ''; } |
Fred Drake | 235e6b1 | 1998-03-27 05:19:43 +0000 | [diff] [blame] | 194 | my $heading = make_section_heading($idx_title, 'h2') . $idx_mark; |
Fred Drake | 1191692 | 1998-04-02 22:30:57 +0000 | [diff] [blame] | 195 | my($pre,$post) = minimize_open_tags($heading); |
Fred Drake | 235e6b1 | 1998-03-27 05:19:43 +0000 | [diff] [blame] | 196 | anchor_label('genindex',$CURRENT_FILE,$_); # this is added |
| 197 | '<br>\n' . $pre . $_; |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | # $idx_module_mark will be replaced with the real index at the end |
| 201 | sub do_cmd_textohtmlmoduleindex { |
| 202 | local($_) = @_; |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 203 | $TITLE = $idx_module_title; |
| 204 | &anchor_label("modindex",$CURRENT_FILE,$_); |
Fred Drake | 235e6b1 | 1998-03-27 05:19:43 +0000 | [diff] [blame] | 205 | '<p>' . make_section_heading($idx_module_title, "h2") |
| 206 | . $idx_module_mark . $_; |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | # The bibliography and the index should be treated as separate sections |
| 210 | # in their own HTML files. The \bibliography{} command acts as a sectioning command |
| 211 | # that has the desired effect. But when the bibliography is constructed |
| 212 | # manually using the thebibliography environment, or when using the |
| 213 | # theindex environment it is not possible to use the normal sectioning |
| 214 | # mechanism. This subroutine inserts a \bibliography{} or a dummy |
| 215 | # \textohtmlindex command just before the appropriate environments |
| 216 | # to force sectioning. |
| 217 | |
| 218 | # XXX This *assumes* that if there are two {theindex} environments, the |
| 219 | # first is the module index and the second is the standard index. This |
| 220 | # is sufficient for the current Python documentation, but that's about |
| 221 | # it. |
| 222 | |
| 223 | sub add_bbl_and_idx_dummy_commands { |
Fred Drake | 1191692 | 1998-04-02 22:30:57 +0000 | [diff] [blame] | 224 | my $id = $global{'max_id'}; |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 225 | |
| 226 | s/([\\]begin\s*$O\d+$C\s*thebibliography)/$bbl_cnt++; $1/eg; |
| 227 | s/([\\]begin\s*$O\d+$C\s*thebibliography)/$id++; "\\bibliography$O$id$C$O$id$C $1"/geo |
| 228 | #if ($bbl_cnt == 1) |
| 229 | ; |
| 230 | #} |
Fred Drake | 1191692 | 1998-04-02 22:30:57 +0000 | [diff] [blame] | 231 | #---------------------------------------------------------------------- |
| 232 | # (FLD) This was added |
| 233 | my(@parts) = split(/\\begin\s*$O\d+$C\s*theindex/); |
| 234 | if (scalar(@parts) == 3) { |
| 235 | # Be careful to re-write the string in place, since $_ is *not* |
| 236 | # returned explicity; *** nasty side-effect dependency! *** |
| 237 | print "\nadd_bbl_and_idx_dummy_commands ==> adding module index"; |
| 238 | my $rx = "([\\\\]begin\\s*$O\\d+$C\\s*theindex[\\s\\S]*)" |
| 239 | . "([\\\\]begin\\s*$O\\d+$C\\s*theindex)"; |
| 240 | s/$rx/\\textohtmlmoduleindex \1 \\textohtmlindex \2/o; |
| 241 | } |
| 242 | else { |
| 243 | $global{'max_id'} = $id; # not sure why.... |
| 244 | s/([\\]begin\s*$O\d+$C\s*theindex)/\\textohtmlindex $1/o; |
| 245 | s/[\\]printindex/\\textohtmlindex /o; |
| 246 | } |
| 247 | #---------------------------------------------------------------------- |
| 248 | &lib_add_bbl_and_idx_dummy_commands() |
| 249 | if defined(&lib_add_bbl_and_idx_dummy_commands); |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | # The bibliographic references, the appendices, the lists of figures and tables |
| 253 | # etc. must appear in the contents table at the same level as the outermost |
| 254 | # sectioning command. This subroutine finds what is the outermost level and |
| 255 | # sets the above to the same level; |
| 256 | |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 257 | sub set_depth_levels { |
| 258 | # Sets $outermost_level |
Fred Drake | 1191692 | 1998-04-02 22:30:57 +0000 | [diff] [blame] | 259 | my $level; |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 260 | #RRM: do not alter user-set value for $MAX_SPLIT_DEPTH |
| 261 | foreach $level ("part", "chapter", "section", "subsection", |
| 262 | "subsubsection", "paragraph") { |
| 263 | last if (($outermost_level) = /\\($level)$delimiter_rx/); |
| 264 | } |
| 265 | $level = ($outermost_level ? $section_commands{$outermost_level} : |
| 266 | do {$outermost_level = 'section'; 3;}); |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 267 | |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 268 | #RRM: but calculate value for $MAX_SPLIT_DEPTH when a $REL_DEPTH was given |
| 269 | if ($REL_DEPTH && $MAX_SPLIT_DEPTH) { |
| 270 | $MAX_SPLIT_DEPTH = $level + $MAX_SPLIT_DEPTH; |
| 271 | } elsif (!($MAX_SPLIT_DEPTH)) { $MAX_SPLIT_DEPTH = 1 }; |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 272 | |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 273 | %unnumbered_section_commands = ( |
| 274 | 'tableofcontents', $level |
| 275 | , 'listoffigures', $level |
| 276 | , 'listoftables', $level |
| 277 | , 'bibliography', $level |
| 278 | , 'textohtmlindex', $level |
| 279 | , 'textohtmlmoduleindex', $level |
| 280 | ); |
Fred Drake | 1191692 | 1998-04-02 22:30:57 +0000 | [diff] [blame] | 281 | $section_headings{'textohtmlmoduleindex'} = "h1"; |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 282 | |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 283 | %section_commands = ( |
| 284 | %unnumbered_section_commands |
| 285 | , %section_commands |
| 286 | ); |
Fred Drake | 1191692 | 1998-04-02 22:30:57 +0000 | [diff] [blame] | 287 | |
| 288 | make_sections_rx(); |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 289 | } |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 290 | |
| 291 | |
| 292 | # Fix from Ross Moore for ']' in \item[...]; this can be removed once the next |
Fred Drake | 235e6b1 | 1998-03-27 05:19:43 +0000 | [diff] [blame] | 293 | # patch to LaTeX2HTML is released and tested ... if the patch gets included. |
| 294 | # Be very careful to keep this around, just in case things break again! |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 295 | # |
| 296 | sub protect_useritems { |
| 297 | local(*_) = @_; |
Fred Drake | 1191692 | 1998-04-02 22:30:57 +0000 | [diff] [blame] | 298 | local($preitems,$thisitem); |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 299 | while (/\\item\s*\[/) { |
Fred Drake | 1191692 | 1998-04-02 22:30:57 +0000 | [diff] [blame] | 300 | $preitems .= $`; |
| 301 | $_ = $'; |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 302 | $thisitem = $&.'<<'.++$global{'max_id'}.'>>'; |
| 303 | s/^(((($O|$OP)\d+($C|$CP)).*\3|<[^<>]*>|[^\]<]+)*)\]/$thisitem.=$1;''/e; |
Fred Drake | 1191692 | 1998-04-02 22:30:57 +0000 | [diff] [blame] | 304 | $preitems .= $thisitem . '<<' . $global{'max_id'} . '>>]'; |
| 305 | s/^]//; |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 306 | } |
| 307 | $_ = $preitems . $_; |
| 308 | } |
| 309 | |
| 310 | 1; # This must be the last line |