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{ |
| 29 | local($myfile,$key,$tmp,$mydir) = (@_[0], '', '', ''); |
| 30 | foreach $key (keys %INC) { |
| 31 | $tmp = "$key"; |
| 32 | $tmp =~ s|^.*/||o; |
| 33 | if ($tmp eq $myfile) { |
| 34 | #print "\nfound $tmp: $key --> ", $INC{$key}, "\n"; |
| 35 | $mydir = $INC{$key}; |
| 36 | } |
| 37 | } |
| 38 | $mydir =~ s|/[^/]*$||; |
| 39 | $mydir; |
| 40 | } |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 41 | |
Fred Drake | c9f2c14 | 1998-03-11 12:08:21 +0000 | [diff] [blame] | 42 | |
Fred Drake | db34a1e | 1998-03-10 23:02:57 +0000 | [diff] [blame] | 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). |
| 45 | # |
Fred Drake | c9f2c14 | 1998-03-11 12:08:21 +0000 | [diff] [blame] | 46 | use Cwd; |
| 47 | use File::Basename; |
| 48 | ($myname, $mydir, $myext) = fileparse(__FILE__, '\..*'); |
| 49 | chop $mydir; # remove trailing '/' |
| 50 | $mydir = getcwd() . "$dd$mydir" |
| 51 | unless $mydir =~ s|^/|/|; |
Fred Drake | db34a1e | 1998-03-10 23:02:57 +0000 | [diff] [blame] | 52 | $LATEX2HTMLSTYLES = "$mydir$envkey$LATEX2HTMLSTYLES"; |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 53 | |
| 54 | |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 55 | sub make_nav_panel{ |
| 56 | ($NEXT_TITLE ? "$NEXT\n" : '') |
| 57 | . ($UP_TITLE ? "$UP\n" : '') |
| 58 | . ($PREVIOUS_TITLE ? "$PREVIOUS\n" : '') |
| 59 | . "$CONTENTS\n$INDEX" |
| 60 | # . " $CUSTOM_BUTTONS" |
| 61 | . "<br>\n" |
| 62 | . ($NEXT_TITLE ? "<b> Next:</b> $NEXT_TITLE\n" : '') |
| 63 | . ($UP_TITLE ? "<b>Up:</b> $UP_TITLE\n" : '') |
| 64 | . ($PREVIOUS_TITLE ? "<b>Previous:</b> $PREVIOUS_TITLE\n" : ''); |
| 65 | } |
| 66 | |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 67 | sub top_navigation_panel { |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 68 | "<div class=navigation>\n" |
| 69 | . &make_nav_panel |
| 70 | . "<br><hr><p></div>" |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | sub bot_navigation_panel { |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 74 | "<div class=navigation><hr>" |
| 75 | . &make_nav_panel |
| 76 | . "</div>" |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 80 | sub gen_index_id { |
| 81 | # this is used to ensure common index key generation and a stable sort |
| 82 | local($str,$extra) = @_; |
| 83 | sprintf("%s###%s%010d", $str, $extra, ++$global{'max_id'}); |
| 84 | } |
| 85 | |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 86 | sub make_index_entry { |
| 87 | local($br_id,$str) = @_; |
| 88 | # If TITLE is not yet available (i.e the \index command is in the title of the |
| 89 | # current section), use $ref_before. |
| 90 | $TITLE = $ref_before unless $TITLE; |
| 91 | # Save the reference |
| 92 | $str = gen_index_id($str, ''); |
| 93 | $index{$str} .= &make_half_href("$CURRENT_FILE#$br_id"); |
| 94 | "<a name=\"$br_id\">$anchor_invisible_mark<\/a>"; |
| 95 | } |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 96 | |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 97 | sub add_idx { |
| 98 | print "\nDoing the index ..."; |
| 99 | local($key, $str, @keys, $index, $level, $count, @previous, @current); |
| 100 | @keys = keys %index; |
| 101 | @keys = sort keysort @keys; |
| 102 | $level = 0; |
| 103 | foreach $key (@keys) { |
| 104 | @current = split(/!/, $key); |
| 105 | $count = 0; |
| 106 | while ($current[$count] eq $previous[$count]) { |
| 107 | $count++; |
| 108 | } |
| 109 | while ($count > $level) { |
| 110 | $index .= "<dl compact>\n"; |
| 111 | $level++; |
| 112 | } |
| 113 | while ($count < $level) { |
| 114 | $index .= "</dl>\n"; |
| 115 | $level--; |
| 116 | } |
| 117 | foreach $term (@current[$count .. $#current-1]) { |
| 118 | # need to "step in" a little |
| 119 | $index .= "<dt>" . $term . "\n<dl compact>\n"; |
| 120 | $level++; |
| 121 | } |
| 122 | $str = $current[$#current]; |
| 123 | $str =~ s/\#\#\#\d+$//o; # Remove the unique id's |
| 124 | $str =~ s/\#\#\#[DR]EF\d+$//o; # Remove the unique id's |
| 125 | if (&index_key_eq(join('',@current), join('',@previous))) { |
| 126 | $index .= ",\n$index{$key}" . $cross_ref_visible_mark . "</a>"; } |
| 127 | else { |
| 128 | $index .= "\n<dt>$index{$key}" . $str . "</a>"; } |
| 129 | @previous = @current; |
| 130 | } |
| 131 | while ($count < $level) { |
| 132 | $index .= "</dl>\n"; |
| 133 | $level--; |
| 134 | } |
| 135 | s/$idx_mark/<dl compact>$index<\/dl>/o; |
| 136 | } |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 137 | |
| 138 | |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 139 | sub index_key_eq{ |
| 140 | local($a,$b) = @_; |
| 141 | $a = &clean_key($a); |
| 142 | $a =~ s/\#\#\#\d+$//o; # Remove the unique id's |
| 143 | $a =~ s/\#\#\#[dr]ef\d+$//o; # Remove the unique id's |
| 144 | $b = &clean_key($b); |
| 145 | $b =~ s/\#\#\#\d+$//o; # Remove the unique id's |
| 146 | $b =~ s/\#\#\#[dr]ef\d+$//o; # Remove the unique id's |
| 147 | $a eq $b; |
| 148 | } |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 149 | |
| 150 | # need to remove leading <...> |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 151 | sub clean_key{ |
| 152 | local ($_) = @_; |
| 153 | tr/A-Z/a-z/; |
| 154 | s/\s//; |
| 155 | s/^<[a-z][-._a-z0-9]*>//; # Remove leading <gi> (no attributes) |
| 156 | $_; |
| 157 | } |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 158 | |
| 159 | |
| 160 | $idx_module_mark = '<tex2html_idx_module_mark>'; |
| 161 | $idx_module_title = 'Module Index'; |
| 162 | |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 163 | sub add_module_idx{ |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 164 | print "\nDoing the module index ..."; |
| 165 | local($key, @keys, $index); |
| 166 | $index = "<p>"; |
| 167 | @keys = keys %Modules; |
| 168 | @keys = sort keysort @keys; |
| 169 | foreach $key (@keys) { |
| 170 | $index .= "$Modules{$key}$key</a><br>\n"; |
| 171 | } |
| 172 | s/$idx_module_mark/$index<p>/o; |
| 173 | } |
| 174 | |
| 175 | |
| 176 | # sub remove_general_markers { |
| 177 | # s/$lof_mark/<UL>$figure_captions<\/UL>/o; |
| 178 | # s/$lot_mark/<UL>$table_captions<\/UL>/o; |
| 179 | # &replace_citations if /$bbl_mark/; |
| 180 | # &add_toc if (/$toc_mark/); |
| 181 | # &add_idx if (/$idx_mark/); |
| 182 | # &add_module_idx if (/$idx_module_mark/); |
| 183 | # &replace_cross_references if /$cross_ref_mark/; |
| 184 | # &replace_external_references if /$external_ref_mark/; |
| 185 | # &replace_cite_references if /$cite_mark/; |
| 186 | # if (defined &replace_user_references) { |
| 187 | # &replace_user_references if /$user_ref_mark/; |
| 188 | # } |
| 189 | # } |
| 190 | |
| 191 | # In addition to the standard stuff, add label to allow named node files. |
| 192 | sub do_cmd_tableofcontents { |
| 193 | local($_) = @_; |
| 194 | $TITLE = $toc_title; |
| 195 | $tocfile = $CURRENT_FILE; |
| 196 | local($closures,$reopens) = &preserve_open_tags(); |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 197 | &anchor_label("contents",$CURRENT_FILE,$_); # this is added |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 198 | join('', "<BR>\n", $closures |
| 199 | , &make_section_heading($toc_title, "H2"), $toc_mark |
| 200 | , $reopens, $_); |
| 201 | } |
| 202 | # In addition to the standard stuff, add label to allow named node files. |
| 203 | sub do_cmd_listoffigures { |
| 204 | local($_) = @_; |
| 205 | $TITLE = $lof_title; |
| 206 | $loffile = $CURRENT_FILE; |
| 207 | local($closures,$reopens) = &preserve_open_tags(); |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 208 | &anchor_label("lof",$CURRENT_FILE,$_); # this is added |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 209 | join('', "<BR>\n", $closures |
| 210 | , &make_section_heading($lof_title, "H2"), $lof_mark |
| 211 | , $reopens, $_); |
| 212 | } |
| 213 | # In addition to the standard stuff, add label to allow named node files. |
| 214 | sub do_cmd_listoftables { |
| 215 | local($_) = @_; |
| 216 | $TITLE = $lot_title; |
| 217 | $lotfile = $CURRENT_FILE; |
| 218 | local($closures,$reopens) = &preserve_open_tags(); |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 219 | &anchor_label("lot",$CURRENT_FILE,$_); # this is added |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 220 | join('', "<BR>\n", $closures |
| 221 | , &make_section_heading($lot_title, "H2"), $lot_mark |
| 222 | , $reopens, $_); |
| 223 | } |
| 224 | # In addition to the standard stuff, add label to allow named node files. |
| 225 | sub do_cmd_textohtmlinfopage { |
| 226 | local($_) = @_; |
| 227 | if ($INFO) { # |
| 228 | &anchor_label("about",$CURRENT_FILE,$_); # this is added |
| 229 | } # |
| 230 | ( ($INFO == 1) |
| 231 | ? join('', $close_all |
| 232 | , "<STRONG>$t_title</STRONG><P>\nThis document was generated using the\n" |
| 233 | , "<A HREF=\"$TEX2HTMLADDRESS\"><STRONG>LaTeX</STRONG>2<tt>HTML</tt></A>" |
| 234 | , " translator Version $TEX2HTMLVERSION\n" |
| 235 | , "<P>Copyright © 1993, 1994, 1995, 1996, 1997,\n" |
| 236 | , "<A HREF=\"$AUTHORADDRESS\">Nikos Drakos</A>, \n" |
| 237 | , "Computer Based Learning Unit, University of Leeds.\n" |
| 238 | , "<P>The command line arguments were: <BR>\n " |
| 239 | , "<STRONG>latex2html</STRONG> <tt>$argv</tt>.\n" |
| 240 | , "<P>The translation was initiated by $address_data[0] on $address_data[1]" |
| 241 | , $open_all, $_) |
| 242 | : join('', $close_all, $INFO,"\n", $open_all, $_)) |
| 243 | } |
| 244 | |
| 245 | # $idx_mark will be replaced with the real index at the end |
| 246 | sub do_cmd_textohtmlindex { |
| 247 | local($_) = @_; |
| 248 | $TITLE = $idx_title; |
| 249 | $idxfile = $CURRENT_FILE; |
| 250 | if (%index_labels) { &make_index_labels(); } |
| 251 | if (($SHORT_INDEX) && (%index_segment)) { &make_preindex(); } |
| 252 | else { $preindex = ''; } |
| 253 | local($heading) = join('',&make_section_heading($idx_title, "H2"), |
| 254 | $idx_mark); |
| 255 | local($pre,$post) = &minimize_open_tags($heading); |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 256 | &anchor_label("genindex",$CURRENT_FILE,$_); # this is added |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 257 | join('',"<BR>\n" , $pre, $_); |
| 258 | } |
| 259 | |
| 260 | # $idx_module_mark will be replaced with the real index at the end |
| 261 | sub do_cmd_textohtmlmoduleindex { |
| 262 | local($_) = @_; |
| 263 | local($key) = q/modindex/; |
| 264 | $TITLE = $idx_module_title; |
| 265 | &anchor_label("modindex",$CURRENT_FILE,$_); |
| 266 | join('', '<p>' , &make_section_heading($idx_module_title, "h2"), |
| 267 | $idx_module_mark, $_); |
| 268 | } |
| 269 | |
| 270 | # The bibliography and the index should be treated as separate sections |
| 271 | # in their own HTML files. The \bibliography{} command acts as a sectioning command |
| 272 | # that has the desired effect. But when the bibliography is constructed |
| 273 | # manually using the thebibliography environment, or when using the |
| 274 | # theindex environment it is not possible to use the normal sectioning |
| 275 | # mechanism. This subroutine inserts a \bibliography{} or a dummy |
| 276 | # \textohtmlindex command just before the appropriate environments |
| 277 | # to force sectioning. |
| 278 | |
| 279 | # XXX This *assumes* that if there are two {theindex} environments, the |
| 280 | # first is the module index and the second is the standard index. This |
| 281 | # is sufficient for the current Python documentation, but that's about |
| 282 | # it. |
| 283 | |
| 284 | sub add_bbl_and_idx_dummy_commands { |
| 285 | local($id) = $global{'max_id'}; |
| 286 | |
| 287 | $section_commands{'textohtmlmoduleindex'} = 2; |
| 288 | |
| 289 | s/([\\]begin\s*$O\d+$C\s*thebibliography)/$bbl_cnt++; $1/eg; |
| 290 | s/([\\]begin\s*$O\d+$C\s*thebibliography)/$id++; "\\bibliography$O$id$C$O$id$C $1"/geo |
| 291 | #if ($bbl_cnt == 1) |
| 292 | ; |
| 293 | #} |
| 294 | #----------------------------------------------------------------------# |
| 295 | # (FLD) This was added # |
| 296 | local(@parts) = split(/\\begin\s*$O\d+$C\s*theindex/); # |
| 297 | if (scalar(@parts) == 3) { # |
| 298 | print "\n&add_bbl_and_idx_dummy_commands ==> adding module index"; # |
| 299 | s/([\\]begin\s*$O\d+$C\s*theindex)/\\textohtmlmoduleindex $1/o; # |
| 300 | } # |
| 301 | #----------------------------------------------------------------------# |
| 302 | $global{'max_id'} = $id; |
| 303 | s/([\\]begin\s*$O\d+$C\s*theindex)/\\textohtmlindex $1/o; |
| 304 | s/[\\]printindex/\\textohtmlindex /o; |
| 305 | &lib_add_bbl_and_idx_dummy_commands() if defined(&lib_add_bbl_and_idx_dummy_commands); |
| 306 | } |
| 307 | |
| 308 | # The bibliographic references, the appendices, the lists of figures and tables |
| 309 | # etc. must appear in the contents table at the same level as the outermost |
| 310 | # sectioning command. This subroutine finds what is the outermost level and |
| 311 | # sets the above to the same level; |
| 312 | |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 313 | #%section_commands = ('textohtmlmoduleindex', 1, %section_commands); |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 314 | |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 315 | sub set_depth_levels { |
| 316 | # Sets $outermost_level |
| 317 | local($level); |
| 318 | #RRM: do not alter user-set value for $MAX_SPLIT_DEPTH |
| 319 | foreach $level ("part", "chapter", "section", "subsection", |
| 320 | "subsubsection", "paragraph") { |
| 321 | last if (($outermost_level) = /\\($level)$delimiter_rx/); |
| 322 | } |
| 323 | $level = ($outermost_level ? $section_commands{$outermost_level} : |
| 324 | do {$outermost_level = 'section'; 3;}); |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 325 | |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 326 | #RRM: but calculate value for $MAX_SPLIT_DEPTH when a $REL_DEPTH was given |
| 327 | if ($REL_DEPTH && $MAX_SPLIT_DEPTH) { |
| 328 | $MAX_SPLIT_DEPTH = $level + $MAX_SPLIT_DEPTH; |
| 329 | } elsif (!($MAX_SPLIT_DEPTH)) { $MAX_SPLIT_DEPTH = 1 }; |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 330 | |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 331 | %unnumbered_section_commands = ( |
| 332 | 'tableofcontents', $level |
| 333 | , 'listoffigures', $level |
| 334 | , 'listoftables', $level |
| 335 | , 'bibliography', $level |
| 336 | , 'textohtmlindex', $level |
| 337 | , 'textohtmlmoduleindex', $level |
| 338 | ); |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 339 | |
Fred Drake | 13210ed | 1998-03-17 06:28:05 +0000 | [diff] [blame] | 340 | %section_commands = ( |
| 341 | %unnumbered_section_commands |
| 342 | , %section_commands |
| 343 | ); |
| 344 | } |
Fred Drake | bc7101d | 1998-03-06 21:18:55 +0000 | [diff] [blame] | 345 | |
| 346 | |
| 347 | # Fix from Ross Moore for ']' in \item[...]; this can be removed once the next |
| 348 | # patch to LaTeX2HTML is released and tested. |
| 349 | # |
| 350 | sub protect_useritems { |
| 351 | local(*_) = @_; |
| 352 | local($preitems, $thisitem); |
| 353 | while (/\\item\s*\[/) { |
| 354 | $preitems .= $`; $_ = $'; |
| 355 | $thisitem = $&.'<<'.++$global{'max_id'}.'>>'; |
| 356 | s/^(((($O|$OP)\d+($C|$CP)).*\3|<[^<>]*>|[^\]<]+)*)\]/$thisitem.=$1;''/e; |
| 357 | $preitems .= $thisitem.'<<'.$global{'max_id'}.'>>]'; s/^]//; |
| 358 | } |
| 359 | $_ = $preitems . $_; |
| 360 | } |
| 361 | |
| 362 | 1; # This must be the last line |