Fred Drake | a5a3cdc | 1997-12-08 20:58:13 +0000 | [diff] [blame] | 1 | #LaTeX2HTML Version 96.1 : dot.latex2html-init -*- perl -*- |
Fred Drake | 784c6d3 | 1996-11-11 20:46:44 +0000 | [diff] [blame] | 2 | # |
| 3 | |
Fred Drake | d569242 | 1997-12-11 21:46:07 +0000 | [diff] [blame] | 4 | $INFO = 1; # 0 = do not make a "About this document..." section |
Fred Drake | 784c6d3 | 1996-11-11 20:46:44 +0000 | [diff] [blame] | 5 | $MAX_LINK_DEPTH = 3; |
| 6 | |
| 7 | # Python documentation uses section numbers to support references to match |
| 8 | # in the printed and online versions. |
| 9 | # |
| 10 | $SHOW_SECTION_NUMBERS = 1; |
| 11 | |
| 12 | $HTML_VERSION = '3.0'; |
| 13 | $ICONSERVER = '../icons'; |
| 14 | |
| 15 | # This replacement adds the "BORDER=0" attribute to the generated icon |
| 16 | # markup. This is done for no better reason than that it looks better. |
| 17 | # |
| 18 | sub img_tag { |
| 19 | local($icon) = @_; |
| 20 | ( ($icon =~ /(gif)/) ? |
| 21 | do { |
| 22 | $icon =~ /(up|next|previous|next_page|previous_page|change_begin|change_end|change_delete|contents|index)/; |
Fred Drake | 616b23b | 1997-12-18 14:16:46 +0000 | [diff] [blame] | 23 | join('','<img ',$iconsizes{$1},' align=bottom alt="',$1, |
| 24 | '" src="',$ICONSERVER,"/$icon",'" border=0>') |
Fred Drake | 784c6d3 | 1996-11-11 20:46:44 +0000 | [diff] [blame] | 25 | } : |
| 26 | $icon); |
| 27 | } |
| 28 | |
Fred Drake | dce22ad | 1996-12-06 14:50:58 +0000 | [diff] [blame] | 29 | # This replacement for process_command() is needed to add the case for |
Fred Drake | 784c6d3 | 1996-11-11 20:46:44 +0000 | [diff] [blame] | 30 | # "\,"; it is unfortunate we need to do it this way. |
| 31 | # |
| 32 | sub process_command { |
| 33 | local ($cmd_rx, *ref_contents) = @_; |
| 34 | local($ref_before, $cmd, $after); |
| 35 | local($cmd_sub, $cmd_msub, $cmd_trans, $mathentity); |
| 36 | local (@open_font_tags,@open_size_tags); |
| 37 | $ref_contents = &convert_iso_latin_chars($ref_contents); |
| 38 | for (;;) { # Do NOT use the o option |
| 39 | last unless ($ref_contents =~ /$cmd_rx/ ); |
| 40 | ($ref_before, $cmd, $after) = ($`, $1, "$2$'"); |
| 41 | print("."); |
| 42 | # $after =~ s/^[ ]+/ /o; Collapse all spaces that follow a command |
| 43 | if ($cmd =~ /[a-zA-Z]$/) { # Eat redundant spaces that follow a command |
| 44 | $after =~ s/^[ \t]+//o; } |
| 45 | else { |
| 46 | $after =~ s/^[ \t]+/ /o; } |
| 47 | if ( $cmd = &normalize($cmd) ) { |
| 48 | ($cmd_sub, $cmd_msub, $cmd_trans, $mathentity) = |
| 49 | ("do_cmd_$cmd", "do_math_cmd_$cmd", |
| 50 | $declarations{$cmd}, $mathentities{$cmd}); |
| 51 | if (defined &$cmd_sub) { |
| 52 | # $ref_before may also be modified ... |
| 53 | if ($cmd =~ /$sizechange_rx/o) { |
| 54 | $after = &$cmd_sub($after, @open_size_tags); |
| 55 | } else { |
| 56 | $after = &$cmd_sub($after, @open_font_tags); |
| 57 | }; |
| 58 | } |
| 59 | elsif (defined &$cmd_msub) { |
| 60 | # $ref_before may also be modified ... |
| 61 | $after = &$cmd_msub($after, @open_font_tags); |
| 62 | if ( !$math_mode ) { |
Fred Drake | d569242 | 1997-12-11 21:46:07 +0000 | [diff] [blame] | 63 | $after = "<math>" . $after . "</math>"; |
Fred Drake | 784c6d3 | 1996-11-11 20:46:44 +0000 | [diff] [blame] | 64 | ++$commands_outside_math{$cmd}; |
| 65 | }; |
| 66 | } |
| 67 | elsif ($cmd_trans) { # One to one transform |
| 68 | $cmd_trans =~ m|</.*$|; |
| 69 | $after = $` . $after . $&; |
| 70 | push(@open_font_tags, $cmd) if ($cmd =~ /$fontchange_rx/o); |
| 71 | push(@open_size_tags, $cmd) if ($cmd =~ /$sizechange_rx/o);} |
| 72 | elsif ($mathentity) { |
| 73 | if ( $math_mode ) { |
| 74 | $after = "&$mathentity;" . $after; |
| 75 | } else { |
Fred Drake | d569242 | 1997-12-11 21:46:07 +0000 | [diff] [blame] | 76 | $after = "<math>&$mathentity;</math>" . $after; |
Fred Drake | 784c6d3 | 1996-11-11 20:46:44 +0000 | [diff] [blame] | 77 | ++$commands_outside_math{$cmd}; |
| 78 | }; } |
| 79 | # Here's the hack: |
| 80 | elsif ($cmd == ',' && ! $AUX_FILE) { |
| 81 | $ref_before = $ref_before . ","; |
| 82 | } |
| 83 | elsif ($ignore{$cmd}) { # Ignored command |
| 84 | print "."} |
| 85 | elsif ($cmd =~ /^the(.+)$/) { # Counter |
| 86 | $counter = $1; |
| 87 | $after = &do_cmd_thecounter($after);} |
| 88 | else { |
| 89 | # Do not add if reading an auxiliary file |
| 90 | ++$unknown_commands{$cmd} unless $AUX_FILE; |
| 91 | } |
| 92 | } |
| 93 | $ref_contents = join('', $ref_before, $after); |
| 94 | } |
| 95 | $ref_contents; |
| 96 | } |
| 97 | |
Fred Drake | f2d7e55 | 1997-12-03 19:44:27 +0000 | [diff] [blame] | 98 | sub top_navigation_panel { |
| 99 | |
| 100 | # Now add a few buttons with a space between them |
Fred Drake | 616b23b | 1997-12-18 14:16:46 +0000 | [diff] [blame] | 101 | "<div class=navigation>\n" . |
Fred Drake | f2d7e55 | 1997-12-03 19:44:27 +0000 | [diff] [blame] | 102 | "$NEXT $UP $PREVIOUS $CONTENTS $INDEX $CUSTOM_BUTTONS" . |
Fred Drake | d569242 | 1997-12-11 21:46:07 +0000 | [diff] [blame] | 103 | |
Fred Drake | 60a3d27 | 1998-01-09 14:39:41 +0000 | [diff] [blame] | 104 | "<br>\n" . # Line break |
Fred Drake | d569242 | 1997-12-11 21:46:07 +0000 | [diff] [blame] | 105 | |
Fred Drake | f2d7e55 | 1997-12-03 19:44:27 +0000 | [diff] [blame] | 106 | # If ``next'' section exists, add its title to the navigation panel |
Fred Drake | 616b23b | 1997-12-18 14:16:46 +0000 | [diff] [blame] | 107 | ($NEXT_TITLE ? "<b> Next:</b> $NEXT_TITLE\n" : undef) . |
Fred Drake | d569242 | 1997-12-11 21:46:07 +0000 | [diff] [blame] | 108 | |
Fred Drake | f2d7e55 | 1997-12-03 19:44:27 +0000 | [diff] [blame] | 109 | # Similarly with the ``up'' title ... |
Fred Drake | 616b23b | 1997-12-18 14:16:46 +0000 | [diff] [blame] | 110 | ($UP_TITLE ? "<b>Up:</b> $UP_TITLE\n" : undef) . |
Fred Drake | d569242 | 1997-12-11 21:46:07 +0000 | [diff] [blame] | 111 | |
Fred Drake | f2d7e55 | 1997-12-03 19:44:27 +0000 | [diff] [blame] | 112 | # ... and the ``previous'' title |
Fred Drake | 616b23b | 1997-12-18 14:16:46 +0000 | [diff] [blame] | 113 | ($PREVIOUS_TITLE ? "<b> Previous:</b> $PREVIOUS_TITLE\n" : undef) . |
Fred Drake | d569242 | 1997-12-11 21:46:07 +0000 | [diff] [blame] | 114 | |
| 115 | # Line Break, horizontal rule (3-d dividing line) and new paragraph |
Fred Drake | 616b23b | 1997-12-18 14:16:46 +0000 | [diff] [blame] | 116 | "<br><hr><p></div>\n" |
Fred Drake | f2d7e55 | 1997-12-03 19:44:27 +0000 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | sub bot_navigation_panel { |
| 120 | |
| 121 | # Start with a horizontal rule (3-d dividing line) |
Fred Drake | d569242 | 1997-12-11 21:46:07 +0000 | [diff] [blame] | 122 | "\n<div class=navigation><hr>". |
Fred Drake | f2d7e55 | 1997-12-03 19:44:27 +0000 | [diff] [blame] | 123 | |
| 124 | # Now add a few buttons with a space between them |
| 125 | "$NEXT $UP $PREVIOUS $CONTENTS $INDEX $CUSTOM_BUTTONS" . |
| 126 | |
Fred Drake | d569242 | 1997-12-11 21:46:07 +0000 | [diff] [blame] | 127 | "<br>\n" . # Line break |
Fred Drake | f2d7e55 | 1997-12-03 19:44:27 +0000 | [diff] [blame] | 128 | |
| 129 | # If ``next'' section exists, add its title to the navigation panel |
Fred Drake | d569242 | 1997-12-11 21:46:07 +0000 | [diff] [blame] | 130 | ($NEXT_TITLE ? "<b> Next:</b> $NEXT_TITLE\n" : undef) . |
| 131 | |
Fred Drake | f2d7e55 | 1997-12-03 19:44:27 +0000 | [diff] [blame] | 132 | # Similarly with the ``up'' title ... |
Fred Drake | d569242 | 1997-12-11 21:46:07 +0000 | [diff] [blame] | 133 | ($UP_TITLE ? "<b>Up:</b> $UP_TITLE\n" : undef) . |
| 134 | |
Fred Drake | f2d7e55 | 1997-12-03 19:44:27 +0000 | [diff] [blame] | 135 | # ... and the ``previous'' title |
Fred Drake | d569242 | 1997-12-11 21:46:07 +0000 | [diff] [blame] | 136 | ($PREVIOUS_TITLE ? "<b> Previous:</b> $PREVIOUS_TITLE\n" : undef) . |
| 137 | |
| 138 | "</div>\n" |
Fred Drake | f2d7e55 | 1997-12-03 19:44:27 +0000 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | |
Fred Drake | 819b789 | 1997-12-17 03:08:27 +0000 | [diff] [blame] | 142 | sub gen_index_id { |
| 143 | # this is used to ensure common index key generation and a stable sort |
| 144 | local($str,$extra) = @_; |
| 145 | sprintf("%s###%s%010d", $str, $extra, ++$global{'max_id'}); |
| 146 | } |
| 147 | |
| 148 | sub make_index_entry { |
Fred Drake | f2d7e55 | 1997-12-03 19:44:27 +0000 | [diff] [blame] | 149 | local($br_id,$str) = @_; |
Fred Drake | 819b789 | 1997-12-17 03:08:27 +0000 | [diff] [blame] | 150 | # If TITLE is not yet available (i.e the \index command is in the title of the |
| 151 | # current section), use $ref_before. |
Fred Drake | f2d7e55 | 1997-12-03 19:44:27 +0000 | [diff] [blame] | 152 | $TITLE = $ref_before unless $TITLE; |
| 153 | # Save the reference |
Fred Drake | 819b789 | 1997-12-17 03:08:27 +0000 | [diff] [blame] | 154 | $str = gen_index_id($str, ''); |
| 155 | $index{$str} .= &make_half_href("$CURRENT_FILE#$br_id"); |
| 156 | "<a name=\"$br_id\">$anchor_invisible_mark<\/a>"; |
Fred Drake | f2d7e55 | 1997-12-03 19:44:27 +0000 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | sub add_idx { |
| 160 | print "\nDoing the index ..."; |
Fred Drake | 819b789 | 1997-12-17 03:08:27 +0000 | [diff] [blame] | 161 | local($key, $str, @keys, $index, $level, $count, @previous, @current); |
Fred Drake | f2d7e55 | 1997-12-03 19:44:27 +0000 | [diff] [blame] | 162 | @keys = keys %index; |
| 163 | @keys = sort keysort @keys; |
| 164 | $level = 0; |
| 165 | foreach $key (@keys) { |
| 166 | @current = split(/!/, $key); |
| 167 | $count = 0; |
| 168 | while ($current[$count] eq $previous[$count]) { |
| 169 | $count++; |
| 170 | } |
| 171 | while ($count > $level) { |
| 172 | $index .= "<dl compact>\n"; |
| 173 | $level++; |
Fred Drake | d569242 | 1997-12-11 21:46:07 +0000 | [diff] [blame] | 174 | } |
Fred Drake | f2d7e55 | 1997-12-03 19:44:27 +0000 | [diff] [blame] | 175 | while ($count < $level) { |
| 176 | $index .= "</dl>\n"; |
| 177 | $level--; |
Fred Drake | d569242 | 1997-12-11 21:46:07 +0000 | [diff] [blame] | 178 | } |
Fred Drake | f2d7e55 | 1997-12-03 19:44:27 +0000 | [diff] [blame] | 179 | foreach $term (@current[$count .. $#current-1]) { |
| 180 | # need to "step in" a little |
| 181 | $index .= "<dt>" . $term . "\n<dl compact>\n"; |
| 182 | $level++; |
| 183 | } |
| 184 | $str = $current[$#current]; |
Fred Drake | 819b789 | 1997-12-17 03:08:27 +0000 | [diff] [blame] | 185 | $str =~ s/\#\#\#\d+$//o; # Remove the unique id's |
| 186 | $str =~ s/\#\#\#[DR]EF\d+$//o; # Remove the unique id's |
| 187 | if (&index_key_eq(join('',@current), join('',@previous))) { |
| 188 | $index .= ",\n$index{$key}" . $cross_ref_visible_mark . "</a>"; } |
| 189 | else { |
| 190 | $index .= "\n<dt>$index{$key}" . $str . "</a>"; } |
Fred Drake | f2d7e55 | 1997-12-03 19:44:27 +0000 | [diff] [blame] | 191 | @previous = @current; |
| 192 | } |
| 193 | while ($count < $level) { |
| 194 | $index .= "</dl>\n"; |
| 195 | $level--; |
Fred Drake | d569242 | 1997-12-11 21:46:07 +0000 | [diff] [blame] | 196 | } |
Fred Drake | f2d7e55 | 1997-12-03 19:44:27 +0000 | [diff] [blame] | 197 | s/$idx_mark/<dl compact>$index<\/dl>/o; |
| 198 | } |
| 199 | |
| 200 | |
Fred Drake | 819b789 | 1997-12-17 03:08:27 +0000 | [diff] [blame] | 201 | sub index_key_eq { |
| 202 | local($a,$b) = @_; |
| 203 | $a = &clean_key($a); |
| 204 | $a =~ s/\#\#\#\d+$//o; # Remove the unique id's |
| 205 | $a =~ s/\#\#\#[dr]ef\d+$//o; # Remove the unique id's |
| 206 | $b = &clean_key($b); |
| 207 | $b =~ s/\#\#\#\d+$//o; # Remove the unique id's |
| 208 | $b =~ s/\#\#\#[dr]ef\d+$//o; # Remove the unique id's |
| 209 | $a eq $b; |
| 210 | } |
| 211 | |
Fred Drake | a5a3cdc | 1997-12-08 20:58:13 +0000 | [diff] [blame] | 212 | # need to remove leading <...> |
| 213 | sub clean_key { |
| 214 | local ($_) = @_; |
| 215 | tr/A-Z/a-z/; |
| 216 | s/\s//; |
Fred Drake | a5a3cdc | 1997-12-08 20:58:13 +0000 | [diff] [blame] | 217 | s/^<[a-z][-._a-z0-9]*>//; # Remove leading <gi> |
| 218 | $_ |
| 219 | } |
| 220 | |
| 221 | |
Fred Drake | 9b6f1d2 | 1998-01-13 04:03:02 +0000 | [diff] [blame] | 222 | $idx_module_mark = '<tex2html_idx_module_mark>'; |
| 223 | $idx_module_title = 'Module Index'; |
| 224 | $idxmodulefile = ''; |
| 225 | |
| 226 | sub add_module_idx { |
| 227 | print "\nDoing the module index ..."; |
| 228 | local($key, @keys, $index); |
| 229 | $index = "<p>"; |
| 230 | @keys = keys %Modules; |
| 231 | @keys = sort keysort @keys; |
| 232 | foreach $key (@keys) { |
| 233 | $index .= "$Modules{$key}$key</a><br>\n" |
| 234 | } |
| 235 | s/$idx_module_mark/$index<p>/o; |
| 236 | } |
| 237 | |
| 238 | |
| 239 | sub remove_general_markers { |
| 240 | s/$lof_mark/<UL>$figure_captions<\/UL>/o; |
| 241 | s/$lot_mark/<UL>$table_captions<\/UL>/o; |
| 242 | &replace_citations if /$bbl_mark/; |
| 243 | &add_toc if (/$toc_mark/); |
| 244 | &add_idx if (/$idx_mark/); |
| 245 | &add_module_idx if (/$idx_module_mark/); |
| 246 | &replace_cross_references if /$cross_ref_mark/; |
| 247 | &replace_external_references if /$external_ref_mark/; |
| 248 | &replace_cite_references if /$cite_mark/; |
| 249 | if (defined &replace_user_references) { |
| 250 | &replace_user_references if /$user_ref_mark/; |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | |
| 255 | # $idx_mark will be replaced with the real index at the end |
| 256 | sub do_cmd_textohtmlmoduleindex { |
| 257 | local($_) = @_; |
| 258 | $TITLE = $idx_module_title; |
| 259 | $idxmodulefile = $CURRENT_FILE; |
| 260 | join('', '<p>' , &make_section_heading($idx_module_title, "h2"), |
| 261 | $idx_module_mark, $_); |
| 262 | } |
| 263 | |
| 264 | # The bibliography and the index should be treated as separate sections |
| 265 | # in their own HTML files. The \bibliography{} command acts as a sectioning command |
| 266 | # that has the desired effect. But when the bibliography is constructed |
| 267 | # manually using the thebibliography environment, or when using the |
| 268 | # theindex environment it is not possible to use the normal sectioning |
| 269 | # mechanism. This subroutine inserts a \bibliography{} or a dummy |
| 270 | # \textohtmlindex command just before the appropriate environments |
| 271 | # to force sectioning. |
| 272 | |
| 273 | # XXX This *assumes* that if there are two {theindex} environments, the |
| 274 | # first is the module index and the second is the standard index. This |
| 275 | # is sufficient for the current Python documentation, but that's about |
| 276 | # it. |
| 277 | |
| 278 | sub add_bbl_and_idx_dummy_commands { |
| 279 | local($id); |
| 280 | s/([\\]begin\s*$O\d+$C\s*thebibliography)/$bbl_cnt++; $1/eg; |
| 281 | #print STDERR "\nthebibliography: $bbl_cnt\n"; |
| 282 | #if ($bbl_cnt == 1) { |
| 283 | s/([\\]begin\s*$O\d+$C\s*thebibliography)/do { $id = ++$global{'max_id'}; "\\bibliography$O$id$C$O$id$C $1"}/geo; |
| 284 | #} |
| 285 | local(@parts) = split(/\\begin\s*$O\d+$C\s*theindex/); |
| 286 | if (scalar(@parts) == 3) { |
| 287 | print "\n&add_bbl_and_idx_dummy_commands ==> adding module index"; |
| 288 | s/([\\]begin\s*$O\d+$C\s*theindex)/\\textohtmlmoduleindex $1/o; |
| 289 | } |
| 290 | s/([\\]begin\s*$O\d+$C\s*theindex)/\\textohtmlindex $1/o; |
| 291 | s/[\\]printindex/\\textohtmlindex /o; |
| 292 | &lib_add_bbl_and_idx_dummy_commands() if defined(&lib_add_bbl_and_idx_dummy_commands); |
| 293 | } |
| 294 | |
| 295 | # The bibliographic references, the appendices, the lists of figures and tables |
| 296 | # etc. must appear in the contents table at the same level as the outermost |
| 297 | # sectioning command. This subroutine finds what is the outermost level and |
| 298 | # sets the above to the same level; |
| 299 | sub set_depth_levels { |
| 300 | $section_headings['textohtmlmoduleindex'] = 'h1'; |
| 301 | # Sets $outermost_level |
| 302 | local($level); |
| 303 | foreach $level ("part", "chapter", "section", "subsection", |
| 304 | "subsubsection", "paragraph") { |
| 305 | last if (($outermost_level) = /\\($level)$delimiter_rx/); |
| 306 | } |
| 307 | $level = ($outermost_level ? $section_commands{$outermost_level} : |
| 308 | do {$outermost_level = 'section'; 3;}); |
| 309 | $MAX_SPLIT_DEPTH = $MAX_SPLIT_DEPTH + $level; |
| 310 | %section_commands = ('tableofcontents', $level, 'listoffigures', $level, |
| 311 | 'listoftables', $level, 'bibliography', $level, |
| 312 | 'textohtmlindex', $level, |
| 313 | 'textohtmlmoduleindex', $level, |
| 314 | %section_commands); |
| 315 | } |
| 316 | |
Fred Drake | 784c6d3 | 1996-11-11 20:46:44 +0000 | [diff] [blame] | 317 | 1; # This must be the last line |