blob: 3b2cbf7b43944d50f7374a74ba67a6807008ff72 [file] [log] [blame]
Fred Drakebc7101d1998-03-06 21:18:55 +00001#LaTeX2HTML Version 96.1 : dot.latex2html-init -*- perl -*-
2#
Fred Drake13210ed1998-03-17 06:28:05 +00003# 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 Drakebc7101d1998-03-06 21:18:55 +00008
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 Drakedb34a1e1998-03-10 23:02:57 +000024# 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#
28sub 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 Drakebc7101d1998-03-06 21:18:55 +000041
Fred Drakec9f2c141998-03-11 12:08:21 +000042
Fred Drakedb34a1e1998-03-10 23:02:57 +000043# 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 Drakec9f2c141998-03-11 12:08:21 +000046use Cwd;
47use File::Basename;
48($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
49chop $mydir; # remove trailing '/'
50$mydir = getcwd() . "$dd$mydir"
51 unless $mydir =~ s|^/|/|;
Fred Drakedb34a1e1998-03-10 23:02:57 +000052$LATEX2HTMLSTYLES = "$mydir$envkey$LATEX2HTMLSTYLES";
Fred Drakebc7101d1998-03-06 21:18:55 +000053
54
Fred Drake13210ed1998-03-17 06:28:05 +000055sub 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 Drakebc7101d1998-03-06 21:18:55 +000067sub top_navigation_panel {
Fred Drake13210ed1998-03-17 06:28:05 +000068 "<div class=navigation>\n"
69 . &make_nav_panel
70 . "<br><hr><p></div>"
Fred Drakebc7101d1998-03-06 21:18:55 +000071}
72
73sub bot_navigation_panel {
Fred Drake13210ed1998-03-17 06:28:05 +000074 "<div class=navigation><hr>"
75 . &make_nav_panel
76 . "</div>"
Fred Drakebc7101d1998-03-06 21:18:55 +000077}
78
79
Fred Drakebc7101d1998-03-06 21:18:55 +000080sub 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 Drake13210ed1998-03-17 06:28:05 +000086sub 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 Drakebc7101d1998-03-06 21:18:55 +000096
Fred Drake13210ed1998-03-17 06:28:05 +000097sub 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 Drakebc7101d1998-03-06 21:18:55 +0000137
138
Fred Drake13210ed1998-03-17 06:28:05 +0000139sub 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 Drakebc7101d1998-03-06 21:18:55 +0000149
150# need to remove leading <...>
Fred Drake13210ed1998-03-17 06:28:05 +0000151sub 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 Drakebc7101d1998-03-06 21:18:55 +0000158
159
160$idx_module_mark = '<tex2html_idx_module_mark>';
161$idx_module_title = 'Module Index';
162
Fred Drake13210ed1998-03-17 06:28:05 +0000163sub add_module_idx{
Fred Drakebc7101d1998-03-06 21:18:55 +0000164 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.
192sub do_cmd_tableofcontents {
193 local($_) = @_;
194 $TITLE = $toc_title;
195 $tocfile = $CURRENT_FILE;
196 local($closures,$reopens) = &preserve_open_tags();
Fred Drake13210ed1998-03-17 06:28:05 +0000197 &anchor_label("contents",$CURRENT_FILE,$_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000198 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.
203sub do_cmd_listoffigures {
204 local($_) = @_;
205 $TITLE = $lof_title;
206 $loffile = $CURRENT_FILE;
207 local($closures,$reopens) = &preserve_open_tags();
Fred Drake13210ed1998-03-17 06:28:05 +0000208 &anchor_label("lof",$CURRENT_FILE,$_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000209 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.
214sub do_cmd_listoftables {
215 local($_) = @_;
216 $TITLE = $lot_title;
217 $lotfile = $CURRENT_FILE;
218 local($closures,$reopens) = &preserve_open_tags();
Fred Drake13210ed1998-03-17 06:28:05 +0000219 &anchor_label("lot",$CURRENT_FILE,$_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000220 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.
225sub 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 &#169; 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
246sub 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 Drake13210ed1998-03-17 06:28:05 +0000256 &anchor_label("genindex",$CURRENT_FILE,$_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000257 join('',"<BR>\n" , $pre, $_);
258}
259
260# $idx_module_mark will be replaced with the real index at the end
261sub 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
284sub 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 Drake13210ed1998-03-17 06:28:05 +0000313#%section_commands = ('textohtmlmoduleindex', 1, %section_commands);
Fred Drakebc7101d1998-03-06 21:18:55 +0000314
Fred Drake13210ed1998-03-17 06:28:05 +0000315sub 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 Drakebc7101d1998-03-06 21:18:55 +0000325
Fred Drake13210ed1998-03-17 06:28:05 +0000326 #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 Drakebc7101d1998-03-06 21:18:55 +0000330
Fred Drake13210ed1998-03-17 06:28:05 +0000331 %unnumbered_section_commands = (
332 'tableofcontents', $level
333 , 'listoffigures', $level
334 , 'listoftables', $level
335 , 'bibliography', $level
336 , 'textohtmlindex', $level
337 , 'textohtmlmoduleindex', $level
338 );
Fred Drakebc7101d1998-03-06 21:18:55 +0000339
Fred Drake13210ed1998-03-17 06:28:05 +0000340 %section_commands = (
341 %unnumbered_section_commands
342 , %section_commands
343 );
344}
Fred Drakebc7101d1998-03-06 21:18:55 +0000345
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#
350sub 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
3621; # This must be the last line