blob: 35a73002b82058c3dd155c9785dfdcf2c866d758 [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
Fred Drake235e6b11998-03-27 05:19:43 +000054($myrootname, $myrootdir, $myext) = fileparse($mydir, '\..*');
55chop $myrootdir;
56
Fred Drakebc7101d1998-03-06 21:18:55 +000057
Fred Drake13210ed1998-03-17 06:28:05 +000058sub make_nav_panel{
59 ($NEXT_TITLE ? "$NEXT\n" : '')
60 . ($UP_TITLE ? "$UP\n" : '')
61 . ($PREVIOUS_TITLE ? "$PREVIOUS\n" : '')
62 . "$CONTENTS\n$INDEX"
63# . " $CUSTOM_BUTTONS"
64 . "<br>\n"
65 . ($NEXT_TITLE ? "<b> Next:</b> $NEXT_TITLE\n" : '')
66 . ($UP_TITLE ? "<b>Up:</b> $UP_TITLE\n" : '')
67 . ($PREVIOUS_TITLE ? "<b>Previous:</b> $PREVIOUS_TITLE\n" : '');
68}
69
Fred Drakebc7101d1998-03-06 21:18:55 +000070sub top_navigation_panel {
Fred Drake13210ed1998-03-17 06:28:05 +000071 "<div class=navigation>\n"
72 . &make_nav_panel
73 . "<br><hr><p></div>"
Fred Drakebc7101d1998-03-06 21:18:55 +000074}
75
76sub bot_navigation_panel {
Fred Drake13210ed1998-03-17 06:28:05 +000077 "<div class=navigation><hr>"
78 . &make_nav_panel
79 . "</div>"
Fred Drakebc7101d1998-03-06 21:18:55 +000080}
81
82
Fred Drakebc7101d1998-03-06 21:18:55 +000083sub gen_index_id {
84 # this is used to ensure common index key generation and a stable sort
Fred Drake235e6b11998-03-27 05:19:43 +000085 my($str,$extra) = @_;
Fred Drakebc7101d1998-03-06 21:18:55 +000086 sprintf("%s###%s%010d", $str, $extra, ++$global{'max_id'});
87}
88
Fred Drake13210ed1998-03-17 06:28:05 +000089sub make_index_entry {
90 local($br_id,$str) = @_;
91 # If TITLE is not yet available (i.e the \index command is in the title of the
92 # current section), use $ref_before.
93 $TITLE = $ref_before unless $TITLE;
94 # Save the reference
95 $str = gen_index_id($str, '');
96 $index{$str} .= &make_half_href("$CURRENT_FILE#$br_id");
97 "<a name=\"$br_id\">$anchor_invisible_mark<\/a>";
98}
Fred Drakebc7101d1998-03-06 21:18:55 +000099
Fred Drake235e6b11998-03-27 05:19:43 +0000100# use this instead with the buildindex.py tool
101sub add_idx{
102 close(IDXFILE);
103 my $index = `$myrootdir/tools/buildindex.py index.dat`;
104 s/$idx_mark/$index/;
Fred Drake13210ed1998-03-17 06:28:05 +0000105}
Fred Drakebc7101d1998-03-06 21:18:55 +0000106
107
108$idx_module_mark = '<tex2html_idx_module_mark>';
109$idx_module_title = 'Module Index';
110
Fred Drake13210ed1998-03-17 06:28:05 +0000111sub add_module_idx{
Fred Drakebc7101d1998-03-06 21:18:55 +0000112 print "\nDoing the module index ...";
Fred Drake235e6b11998-03-27 05:19:43 +0000113 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 Drakebc7101d1998-03-06 21:18:55 +0000119 }
Fred Drake235e6b11998-03-27 05:19:43 +0000120 close(MODIDXFILE);
121 $index = `$myrootdir/tools/buildindex.py modindex.dat`;
122 s/$idx_module_mark/$index<p>/;
Fred Drakebc7101d1998-03-06 21:18:55 +0000123}
124
Fred Drake235e6b11998-03-27 05:19:43 +0000125# replace both indexes as needed:
126sub add_idx_hook{
127 &add_idx if (/$idx_mark/);
128 &add_module_idx if (/$idx_module_mark/);
129}
Fred Drakebc7101d1998-03-06 21:18:55 +0000130
Fred Drakebc7101d1998-03-06 21:18:55 +0000131
132# In addition to the standard stuff, add label to allow named node files.
133sub do_cmd_tableofcontents {
134 local($_) = @_;
135 $TITLE = $toc_title;
136 $tocfile = $CURRENT_FILE;
137 local($closures,$reopens) = &preserve_open_tags();
Fred Drake13210ed1998-03-17 06:28:05 +0000138 &anchor_label("contents",$CURRENT_FILE,$_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000139 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.
144sub do_cmd_listoffigures {
145 local($_) = @_;
146 $TITLE = $lof_title;
147 $loffile = $CURRENT_FILE;
148 local($closures,$reopens) = &preserve_open_tags();
Fred Drake13210ed1998-03-17 06:28:05 +0000149 &anchor_label("lof",$CURRENT_FILE,$_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000150 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.
155sub do_cmd_listoftables {
156 local($_) = @_;
157 $TITLE = $lot_title;
158 $lotfile = $CURRENT_FILE;
159 local($closures,$reopens) = &preserve_open_tags();
Fred Drake13210ed1998-03-17 06:28:05 +0000160 &anchor_label("lot",$CURRENT_FILE,$_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000161 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.
166sub 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 &#169; 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
187sub do_cmd_textohtmlindex {
188 local($_) = @_;
189 $TITLE = $idx_title;
190 $idxfile = $CURRENT_FILE;
Fred Drake235e6b11998-03-27 05:19:43 +0000191 if (%index_labels) { make_index_labels(); }
192 if (($SHORT_INDEX) && (%index_segment)) { make_preindex(); }
Fred Drakebc7101d1998-03-06 21:18:55 +0000193 else { $preindex = ''; }
Fred Drake235e6b11998-03-27 05:19:43 +0000194 my $heading = make_section_heading($idx_title, 'h2') . $idx_mark;
195 local($pre,$post) = minimize_open_tags($heading);
196 anchor_label('genindex',$CURRENT_FILE,$_); # this is added
197 '<br>\n' . $pre . $_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000198}
199
200# $idx_module_mark will be replaced with the real index at the end
201sub do_cmd_textohtmlmoduleindex {
202 local($_) = @_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000203 $TITLE = $idx_module_title;
204 &anchor_label("modindex",$CURRENT_FILE,$_);
Fred Drake235e6b11998-03-27 05:19:43 +0000205 '<p>' . make_section_heading($idx_module_title, "h2")
206 . $idx_module_mark . $_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000207}
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
223sub add_bbl_and_idx_dummy_commands {
224 local($id) = $global{'max_id'};
225
Fred Drake235e6b11998-03-27 05:19:43 +0000226# $section_commands{'textohtmlmoduleindex'} = 2;
Fred Drakebc7101d1998-03-06 21:18:55 +0000227
228 s/([\\]begin\s*$O\d+$C\s*thebibliography)/$bbl_cnt++; $1/eg;
229 s/([\\]begin\s*$O\d+$C\s*thebibliography)/$id++; "\\bibliography$O$id$C$O$id$C $1"/geo
230 #if ($bbl_cnt == 1)
231 ;
232 #}
233 #----------------------------------------------------------------------#
234 # (FLD) This was added #
235 local(@parts) = split(/\\begin\s*$O\d+$C\s*theindex/); #
236 if (scalar(@parts) == 3) { #
Fred Drake235e6b11998-03-27 05:19:43 +0000237 print "\nadd_bbl_and_idx_dummy_commands ==> adding module index"; #
Fred Drakebc7101d1998-03-06 21:18:55 +0000238 s/([\\]begin\s*$O\d+$C\s*theindex)/\\textohtmlmoduleindex $1/o; #
239 } #
240 #----------------------------------------------------------------------#
241 $global{'max_id'} = $id;
242 s/([\\]begin\s*$O\d+$C\s*theindex)/\\textohtmlindex $1/o;
243 s/[\\]printindex/\\textohtmlindex /o;
244 &lib_add_bbl_and_idx_dummy_commands() if defined(&lib_add_bbl_and_idx_dummy_commands);
245}
246
247# The bibliographic references, the appendices, the lists of figures and tables
248# etc. must appear in the contents table at the same level as the outermost
249# sectioning command. This subroutine finds what is the outermost level and
250# sets the above to the same level;
251
Fred Drake13210ed1998-03-17 06:28:05 +0000252sub set_depth_levels {
253 # Sets $outermost_level
254 local($level);
255 #RRM: do not alter user-set value for $MAX_SPLIT_DEPTH
256 foreach $level ("part", "chapter", "section", "subsection",
257 "subsubsection", "paragraph") {
258 last if (($outermost_level) = /\\($level)$delimiter_rx/);
259 }
260 $level = ($outermost_level ? $section_commands{$outermost_level} :
261 do {$outermost_level = 'section'; 3;});
Fred Drakebc7101d1998-03-06 21:18:55 +0000262
Fred Drake13210ed1998-03-17 06:28:05 +0000263 #RRM: but calculate value for $MAX_SPLIT_DEPTH when a $REL_DEPTH was given
264 if ($REL_DEPTH && $MAX_SPLIT_DEPTH) {
265 $MAX_SPLIT_DEPTH = $level + $MAX_SPLIT_DEPTH;
266 } elsif (!($MAX_SPLIT_DEPTH)) { $MAX_SPLIT_DEPTH = 1 };
Fred Drakebc7101d1998-03-06 21:18:55 +0000267
Fred Drake13210ed1998-03-17 06:28:05 +0000268 %unnumbered_section_commands = (
269 'tableofcontents', $level
270 , 'listoffigures', $level
271 , 'listoftables', $level
272 , 'bibliography', $level
273 , 'textohtmlindex', $level
274 , 'textohtmlmoduleindex', $level
275 );
Fred Drakebc7101d1998-03-06 21:18:55 +0000276
Fred Drake13210ed1998-03-17 06:28:05 +0000277 %section_commands = (
278 %unnumbered_section_commands
279 , %section_commands
280 );
281}
Fred Drakebc7101d1998-03-06 21:18:55 +0000282
283
284# Fix from Ross Moore for ']' in \item[...]; this can be removed once the next
Fred Drake235e6b11998-03-27 05:19:43 +0000285# patch to LaTeX2HTML is released and tested ... if the patch gets included.
286# Be very careful to keep this around, just in case things break again!
Fred Drakebc7101d1998-03-06 21:18:55 +0000287#
288sub protect_useritems {
289 local(*_) = @_;
290 local($preitems, $thisitem);
291 while (/\\item\s*\[/) {
292 $preitems .= $`; $_ = $';
293 $thisitem = $&.'<<'.++$global{'max_id'}.'>>';
294 s/^(((($O|$OP)\d+($C|$CP)).*\3|<[^<>]*>|[^\]<]+)*)\]/$thisitem.=$1;''/e;
295 $preitems .= $thisitem.'<<'.$global{'max_id'}.'>>]'; s/^]//;
296 }
297 $_ = $preitems . $_;
298}
299
3001; # This must be the last line