blob: 090cdfdd942aab3bd0ee734c1815bd58daef7813 [file] [log] [blame]
Fred Drakea5a3cdc1997-12-08 20:58:13 +00001#LaTeX2HTML Version 96.1 : dot.latex2html-init -*- perl -*-
Fred Drake784c6d31996-11-11 20:46:44 +00002#
3
Fred Draked5692421997-12-11 21:46:07 +00004$INFO = 1; # 0 = do not make a "About this document..." section
Fred Drake784c6d31996-11-11 20:46:44 +00005$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#
18sub 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 Drake616b23b1997-12-18 14:16:46 +000023 join('','<img ',$iconsizes{$1},' align=bottom alt="',$1,
24 '" src="',$ICONSERVER,"/$icon",'" border=0>')
Fred Drake784c6d31996-11-11 20:46:44 +000025 } :
26 $icon);
27}
28
Fred Drakedce22ad1996-12-06 14:50:58 +000029# This replacement for process_command() is needed to add the case for
Fred Drake784c6d31996-11-11 20:46:44 +000030# "\,"; it is unfortunate we need to do it this way.
31#
32sub 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 Draked5692421997-12-11 21:46:07 +000063 $after = "<math>" . $after . "</math>";
Fred Drake784c6d31996-11-11 20:46:44 +000064 ++$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 Draked5692421997-12-11 21:46:07 +000076 $after = "<math>&$mathentity;</math>" . $after;
Fred Drake784c6d31996-11-11 20:46:44 +000077 ++$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 Drakef2d7e551997-12-03 19:44:27 +000098sub top_navigation_panel {
99
100 # Now add a few buttons with a space between them
Fred Drake616b23b1997-12-18 14:16:46 +0000101 "<div class=navigation>\n" .
Fred Drakef2d7e551997-12-03 19:44:27 +0000102 "$NEXT $UP $PREVIOUS $CONTENTS $INDEX $CUSTOM_BUTTONS" .
Fred Draked5692421997-12-11 21:46:07 +0000103
Fred Drake60a3d271998-01-09 14:39:41 +0000104 "<br>\n" . # Line break
Fred Draked5692421997-12-11 21:46:07 +0000105
Fred Drakef2d7e551997-12-03 19:44:27 +0000106 # If ``next'' section exists, add its title to the navigation panel
Fred Drake616b23b1997-12-18 14:16:46 +0000107 ($NEXT_TITLE ? "<b> Next:</b> $NEXT_TITLE\n" : undef) .
Fred Draked5692421997-12-11 21:46:07 +0000108
Fred Drakef2d7e551997-12-03 19:44:27 +0000109 # Similarly with the ``up'' title ...
Fred Drake616b23b1997-12-18 14:16:46 +0000110 ($UP_TITLE ? "<b>Up:</b> $UP_TITLE\n" : undef) .
Fred Draked5692421997-12-11 21:46:07 +0000111
Fred Drakef2d7e551997-12-03 19:44:27 +0000112 # ... and the ``previous'' title
Fred Drake616b23b1997-12-18 14:16:46 +0000113 ($PREVIOUS_TITLE ? "<b> Previous:</b> $PREVIOUS_TITLE\n" : undef) .
Fred Draked5692421997-12-11 21:46:07 +0000114
115 # Line Break, horizontal rule (3-d dividing line) and new paragraph
Fred Drake616b23b1997-12-18 14:16:46 +0000116 "<br><hr><p></div>\n"
Fred Drakef2d7e551997-12-03 19:44:27 +0000117}
118
119sub bot_navigation_panel {
120
121 # Start with a horizontal rule (3-d dividing line)
Fred Draked5692421997-12-11 21:46:07 +0000122 "\n<div class=navigation><hr>".
Fred Drakef2d7e551997-12-03 19:44:27 +0000123
124 # Now add a few buttons with a space between them
125 "$NEXT $UP $PREVIOUS $CONTENTS $INDEX $CUSTOM_BUTTONS" .
126
Fred Draked5692421997-12-11 21:46:07 +0000127 "<br>\n" . # Line break
Fred Drakef2d7e551997-12-03 19:44:27 +0000128
129 # If ``next'' section exists, add its title to the navigation panel
Fred Draked5692421997-12-11 21:46:07 +0000130 ($NEXT_TITLE ? "<b> Next:</b> $NEXT_TITLE\n" : undef) .
131
Fred Drakef2d7e551997-12-03 19:44:27 +0000132 # Similarly with the ``up'' title ...
Fred Draked5692421997-12-11 21:46:07 +0000133 ($UP_TITLE ? "<b>Up:</b> $UP_TITLE\n" : undef) .
134
Fred Drakef2d7e551997-12-03 19:44:27 +0000135 # ... and the ``previous'' title
Fred Draked5692421997-12-11 21:46:07 +0000136 ($PREVIOUS_TITLE ? "<b> Previous:</b> $PREVIOUS_TITLE\n" : undef) .
137
138 "</div>\n"
Fred Drakef2d7e551997-12-03 19:44:27 +0000139}
140
141
Fred Drake819b7891997-12-17 03:08:27 +0000142sub 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
148sub make_index_entry {
Fred Drakef2d7e551997-12-03 19:44:27 +0000149 local($br_id,$str) = @_;
Fred Drake819b7891997-12-17 03:08:27 +0000150 # If TITLE is not yet available (i.e the \index command is in the title of the
151 # current section), use $ref_before.
Fred Drakef2d7e551997-12-03 19:44:27 +0000152 $TITLE = $ref_before unless $TITLE;
153 # Save the reference
Fred Drake819b7891997-12-17 03:08:27 +0000154 $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 Drakef2d7e551997-12-03 19:44:27 +0000157}
158
159sub add_idx {
160 print "\nDoing the index ...";
Fred Drake819b7891997-12-17 03:08:27 +0000161 local($key, $str, @keys, $index, $level, $count, @previous, @current);
Fred Drakef2d7e551997-12-03 19:44:27 +0000162 @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 Draked5692421997-12-11 21:46:07 +0000174 }
Fred Drakef2d7e551997-12-03 19:44:27 +0000175 while ($count < $level) {
176 $index .= "</dl>\n";
177 $level--;
Fred Draked5692421997-12-11 21:46:07 +0000178 }
Fred Drakef2d7e551997-12-03 19:44:27 +0000179 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 Drake819b7891997-12-17 03:08:27 +0000185 $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 Drakef2d7e551997-12-03 19:44:27 +0000191 @previous = @current;
192 }
193 while ($count < $level) {
194 $index .= "</dl>\n";
195 $level--;
Fred Draked5692421997-12-11 21:46:07 +0000196 }
Fred Drakef2d7e551997-12-03 19:44:27 +0000197 s/$idx_mark/<dl compact>$index<\/dl>/o;
198}
199
200
Fred Drake819b7891997-12-17 03:08:27 +0000201sub 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 Drakea5a3cdc1997-12-08 20:58:13 +0000212# need to remove leading <...>
213sub clean_key {
214 local ($_) = @_;
215 tr/A-Z/a-z/;
216 s/\s//;
Fred Drakea5a3cdc1997-12-08 20:58:13 +0000217 s/^<[a-z][-._a-z0-9]*>//; # Remove leading <gi>
218 $_
219}
220
221
Fred Drake9b6f1d21998-01-13 04:03:02 +0000222$idx_module_mark = '<tex2html_idx_module_mark>';
223$idx_module_title = 'Module Index';
224$idxmodulefile = '';
225
226sub 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
239sub 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
256sub 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
278sub 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;
299sub 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 Drake784c6d31996-11-11 20:46:44 +00003171; # This must be the last line