blob: 272a328556d4f91f56b341d296bdf0b886a079bc [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{
Fred Drake11916921998-04-02 22:30:57 +000029 my($myfile,$key,$tmp,$mydir) = (@_[0], '', '', '');
Fred Drakedb34a1e1998-03-10 23:02:57 +000030 foreach $key (keys %INC) {
31 $tmp = "$key";
32 $tmp =~ s|^.*/||o;
33 if ($tmp eq $myfile) {
Fred Drakedb34a1e1998-03-10 23:02:57 +000034 $mydir = $INC{$key};
35 }
36 }
37 $mydir =~ s|/[^/]*$||;
38 $mydir;
39}
Fred Drakebc7101d1998-03-06 21:18:55 +000040
Fred Drakec9f2c141998-03-11 12:08:21 +000041
Fred Drakedb34a1e1998-03-10 23:02:57 +000042# A little painful, but lets us clean up the top level directory a little,
43# and not be tied to the current directory (as far as I can tell).
44#
Fred Drakec9f2c141998-03-11 12:08:21 +000045use Cwd;
46use File::Basename;
47($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
48chop $mydir; # remove trailing '/'
49$mydir = getcwd() . "$dd$mydir"
50 unless $mydir =~ s|^/|/|;
Fred Drakedb34a1e1998-03-10 23:02:57 +000051$LATEX2HTMLSTYLES = "$mydir$envkey$LATEX2HTMLSTYLES";
Fred Drakebc7101d1998-03-06 21:18:55 +000052
Fred Drake235e6b11998-03-27 05:19:43 +000053($myrootname, $myrootdir, $myext) = fileparse($mydir, '\..*');
54chop $myrootdir;
55
Fred Drakebc7101d1998-03-06 21:18:55 +000056
Fred Drake13210ed1998-03-17 06:28:05 +000057sub make_nav_panel{
58 ($NEXT_TITLE ? "$NEXT\n" : '')
59 . ($UP_TITLE ? "$UP\n" : '')
60 . ($PREVIOUS_TITLE ? "$PREVIOUS\n" : '')
61 . "$CONTENTS\n$INDEX"
62# . " $CUSTOM_BUTTONS"
63 . "<br>\n"
64 . ($NEXT_TITLE ? "<b> Next:</b> $NEXT_TITLE\n" : '')
65 . ($UP_TITLE ? "<b>Up:</b> $UP_TITLE\n" : '')
66 . ($PREVIOUS_TITLE ? "<b>Previous:</b> $PREVIOUS_TITLE\n" : '');
67}
68
Fred Drakebc7101d1998-03-06 21:18:55 +000069sub top_navigation_panel {
Fred Drake13210ed1998-03-17 06:28:05 +000070 "<div class=navigation>\n"
71 . &make_nav_panel
72 . "<br><hr><p></div>"
Fred Drakebc7101d1998-03-06 21:18:55 +000073}
74
75sub bot_navigation_panel {
Fred Drake13210ed1998-03-17 06:28:05 +000076 "<div class=navigation><hr>"
77 . &make_nav_panel
78 . "</div>"
Fred Drakebc7101d1998-03-06 21:18:55 +000079}
80
81
Fred Drakebc7101d1998-03-06 21:18:55 +000082sub gen_index_id {
83 # this is used to ensure common index key generation and a stable sort
Fred Drake235e6b11998-03-27 05:19:43 +000084 my($str,$extra) = @_;
Fred Drakebc7101d1998-03-06 21:18:55 +000085 sprintf("%s###%s%010d", $str, $extra, ++$global{'max_id'});
86}
87
Fred Drake13210ed1998-03-17 06:28:05 +000088sub make_index_entry {
Fred Drake11916921998-04-02 22:30:57 +000089 my($br_id,$str) = @_;
Fred Drake13210ed1998-03-17 06:28:05 +000090 # If TITLE is not yet available (i.e the \index command is in the title of the
91 # current section), use $ref_before.
92 $TITLE = $ref_before unless $TITLE;
93 # Save the reference
94 $str = gen_index_id($str, '');
95 $index{$str} .= &make_half_href("$CURRENT_FILE#$br_id");
96 "<a name=\"$br_id\">$anchor_invisible_mark<\/a>";
97}
Fred Drakebc7101d1998-03-06 21:18:55 +000098
Fred Drake235e6b11998-03-27 05:19:43 +000099# use this instead with the buildindex.py tool
100sub add_idx{
Fred Drake5a525191998-04-02 22:39:05 +0000101 print "\nDoing the index ...";
Fred Drake235e6b11998-03-27 05:19:43 +0000102 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;
Fred Drake11916921998-04-02 22:30:57 +0000137 my($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;
Fred Drake11916921998-04-02 22:30:57 +0000148 my($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;
Fred Drake11916921998-04-02 22:30:57 +0000159 my($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;
Fred Drake11916921998-04-02 22:30:57 +0000195 my($pre,$post) = minimize_open_tags($heading);
Fred Drake235e6b11998-03-27 05:19:43 +0000196 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 {
Fred Drake11916921998-04-02 22:30:57 +0000224 my $id = $global{'max_id'};
Fred Drakebc7101d1998-03-06 21:18:55 +0000225
226 s/([\\]begin\s*$O\d+$C\s*thebibliography)/$bbl_cnt++; $1/eg;
227 s/([\\]begin\s*$O\d+$C\s*thebibliography)/$id++; "\\bibliography$O$id$C$O$id$C $1"/geo
228 #if ($bbl_cnt == 1)
229 ;
230 #}
Fred Drake11916921998-04-02 22:30:57 +0000231 #----------------------------------------------------------------------
232 # (FLD) This was added
233 my(@parts) = split(/\\begin\s*$O\d+$C\s*theindex/);
234 if (scalar(@parts) == 3) {
235 # Be careful to re-write the string in place, since $_ is *not*
236 # returned explicity; *** nasty side-effect dependency! ***
237 print "\nadd_bbl_and_idx_dummy_commands ==> adding module index";
238 my $rx = "([\\\\]begin\\s*$O\\d+$C\\s*theindex[\\s\\S]*)"
239 . "([\\\\]begin\\s*$O\\d+$C\\s*theindex)";
240 s/$rx/\\textohtmlmoduleindex \1 \\textohtmlindex \2/o;
241 }
242 else {
243 $global{'max_id'} = $id; # not sure why....
244 s/([\\]begin\s*$O\d+$C\s*theindex)/\\textohtmlindex $1/o;
245 s/[\\]printindex/\\textohtmlindex /o;
246 }
247 #----------------------------------------------------------------------
248 &lib_add_bbl_and_idx_dummy_commands()
249 if defined(&lib_add_bbl_and_idx_dummy_commands);
Fred Drakebc7101d1998-03-06 21:18:55 +0000250}
251
252# The bibliographic references, the appendices, the lists of figures and tables
253# etc. must appear in the contents table at the same level as the outermost
254# sectioning command. This subroutine finds what is the outermost level and
255# sets the above to the same level;
256
Fred Drake13210ed1998-03-17 06:28:05 +0000257sub set_depth_levels {
258 # Sets $outermost_level
Fred Drake11916921998-04-02 22:30:57 +0000259 my $level;
Fred Drake13210ed1998-03-17 06:28:05 +0000260 #RRM: do not alter user-set value for $MAX_SPLIT_DEPTH
261 foreach $level ("part", "chapter", "section", "subsection",
262 "subsubsection", "paragraph") {
263 last if (($outermost_level) = /\\($level)$delimiter_rx/);
264 }
265 $level = ($outermost_level ? $section_commands{$outermost_level} :
266 do {$outermost_level = 'section'; 3;});
Fred Drakebc7101d1998-03-06 21:18:55 +0000267
Fred Drake13210ed1998-03-17 06:28:05 +0000268 #RRM: but calculate value for $MAX_SPLIT_DEPTH when a $REL_DEPTH was given
269 if ($REL_DEPTH && $MAX_SPLIT_DEPTH) {
270 $MAX_SPLIT_DEPTH = $level + $MAX_SPLIT_DEPTH;
271 } elsif (!($MAX_SPLIT_DEPTH)) { $MAX_SPLIT_DEPTH = 1 };
Fred Drakebc7101d1998-03-06 21:18:55 +0000272
Fred Drake13210ed1998-03-17 06:28:05 +0000273 %unnumbered_section_commands = (
274 'tableofcontents', $level
275 , 'listoffigures', $level
276 , 'listoftables', $level
277 , 'bibliography', $level
278 , 'textohtmlindex', $level
279 , 'textohtmlmoduleindex', $level
280 );
Fred Drake11916921998-04-02 22:30:57 +0000281 $section_headings{'textohtmlmoduleindex'} = "h1";
Fred Drakebc7101d1998-03-06 21:18:55 +0000282
Fred Drake13210ed1998-03-17 06:28:05 +0000283 %section_commands = (
284 %unnumbered_section_commands
285 , %section_commands
286 );
Fred Drake11916921998-04-02 22:30:57 +0000287
288 make_sections_rx();
Fred Drake13210ed1998-03-17 06:28:05 +0000289}
Fred Drakebc7101d1998-03-06 21:18:55 +0000290
291
292# Fix from Ross Moore for ']' in \item[...]; this can be removed once the next
Fred Drake235e6b11998-03-27 05:19:43 +0000293# patch to LaTeX2HTML is released and tested ... if the patch gets included.
294# Be very careful to keep this around, just in case things break again!
Fred Drakebc7101d1998-03-06 21:18:55 +0000295#
296sub protect_useritems {
297 local(*_) = @_;
Fred Drake11916921998-04-02 22:30:57 +0000298 local($preitems,$thisitem);
Fred Drakebc7101d1998-03-06 21:18:55 +0000299 while (/\\item\s*\[/) {
Fred Drake11916921998-04-02 22:30:57 +0000300 $preitems .= $`;
301 $_ = $';
Fred Drakebc7101d1998-03-06 21:18:55 +0000302 $thisitem = $&.'<<'.++$global{'max_id'}.'>>';
303 s/^(((($O|$OP)\d+($C|$CP)).*\3|<[^<>]*>|[^\]<]+)*)\]/$thisitem.=$1;''/e;
Fred Drake11916921998-04-02 22:30:57 +0000304 $preitems .= $thisitem . '<<' . $global{'max_id'} . '>>]';
305 s/^]//;
Fred Drakebc7101d1998-03-06 21:18:55 +0000306 }
307 $_ = $preitems . $_;
308}
309
3101; # This must be the last line