blob: 2a800c583033897da914d0fb9eb8a7e8e7a08159 [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{
101 close(IDXFILE);
102 my $index = `$myrootdir/tools/buildindex.py index.dat`;
103 s/$idx_mark/$index/;
Fred Drake13210ed1998-03-17 06:28:05 +0000104}
Fred Drakebc7101d1998-03-06 21:18:55 +0000105
106
107$idx_module_mark = '<tex2html_idx_module_mark>';
108$idx_module_title = 'Module Index';
109
Fred Drake13210ed1998-03-17 06:28:05 +0000110sub add_module_idx{
Fred Drakebc7101d1998-03-06 21:18:55 +0000111 print "\nDoing the module index ...";
Fred Drake235e6b11998-03-27 05:19:43 +0000112 my $key;
113 my $index = "<p>";
114 open(MODIDXFILE, ">modindex.dat") || die "\n$!\n";
115 foreach $key (keys %Modules) {
116 # dump the line in the data file; just use a dummy seqno field
117 print MODIDXFILE "$Modules{$key}\0$key###\n";
Fred Drakebc7101d1998-03-06 21:18:55 +0000118 }
Fred Drake235e6b11998-03-27 05:19:43 +0000119 close(MODIDXFILE);
120 $index = `$myrootdir/tools/buildindex.py modindex.dat`;
121 s/$idx_module_mark/$index<p>/;
Fred Drakebc7101d1998-03-06 21:18:55 +0000122}
123
Fred Drake235e6b11998-03-27 05:19:43 +0000124# replace both indexes as needed:
125sub add_idx_hook{
126 &add_idx if (/$idx_mark/);
127 &add_module_idx if (/$idx_module_mark/);
128}
Fred Drakebc7101d1998-03-06 21:18:55 +0000129
Fred Drakebc7101d1998-03-06 21:18:55 +0000130
131# In addition to the standard stuff, add label to allow named node files.
132sub do_cmd_tableofcontents {
133 local($_) = @_;
134 $TITLE = $toc_title;
135 $tocfile = $CURRENT_FILE;
Fred Drake11916921998-04-02 22:30:57 +0000136 my($closures,$reopens) = &preserve_open_tags();
Fred Drake13210ed1998-03-17 06:28:05 +0000137 &anchor_label("contents",$CURRENT_FILE,$_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000138 join('', "<BR>\n", $closures
139 , &make_section_heading($toc_title, "H2"), $toc_mark
140 , $reopens, $_);
141}
142# In addition to the standard stuff, add label to allow named node files.
143sub do_cmd_listoffigures {
144 local($_) = @_;
145 $TITLE = $lof_title;
146 $loffile = $CURRENT_FILE;
Fred Drake11916921998-04-02 22:30:57 +0000147 my($closures,$reopens) = &preserve_open_tags();
Fred Drake13210ed1998-03-17 06:28:05 +0000148 &anchor_label("lof",$CURRENT_FILE,$_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000149 join('', "<BR>\n", $closures
150 , &make_section_heading($lof_title, "H2"), $lof_mark
151 , $reopens, $_);
152}
153# In addition to the standard stuff, add label to allow named node files.
154sub do_cmd_listoftables {
155 local($_) = @_;
156 $TITLE = $lot_title;
157 $lotfile = $CURRENT_FILE;
Fred Drake11916921998-04-02 22:30:57 +0000158 my($closures,$reopens) = &preserve_open_tags();
Fred Drake13210ed1998-03-17 06:28:05 +0000159 &anchor_label("lot",$CURRENT_FILE,$_); # this is added
Fred Drakebc7101d1998-03-06 21:18:55 +0000160 join('', "<BR>\n", $closures
161 , &make_section_heading($lot_title, "H2"), $lot_mark
162 , $reopens, $_);
163}
164# In addition to the standard stuff, add label to allow named node files.
165sub do_cmd_textohtmlinfopage {
166 local($_) = @_;
167 if ($INFO) { #
168 &anchor_label("about",$CURRENT_FILE,$_); # this is added
169 } #
170 ( ($INFO == 1)
171 ? join('', $close_all
172 , "<STRONG>$t_title</STRONG><P>\nThis document was generated using the\n"
173 , "<A HREF=\"$TEX2HTMLADDRESS\"><STRONG>LaTeX</STRONG>2<tt>HTML</tt></A>"
174 , " translator Version $TEX2HTMLVERSION\n"
175 , "<P>Copyright &#169; 1993, 1994, 1995, 1996, 1997,\n"
176 , "<A HREF=\"$AUTHORADDRESS\">Nikos Drakos</A>, \n"
177 , "Computer Based Learning Unit, University of Leeds.\n"
178 , "<P>The command line arguments were: <BR>\n "
179 , "<STRONG>latex2html</STRONG> <tt>$argv</tt>.\n"
180 , "<P>The translation was initiated by $address_data[0] on $address_data[1]"
181 , $open_all, $_)
182 : join('', $close_all, $INFO,"\n", $open_all, $_))
183}
184
185# $idx_mark will be replaced with the real index at the end
186sub do_cmd_textohtmlindex {
187 local($_) = @_;
188 $TITLE = $idx_title;
189 $idxfile = $CURRENT_FILE;
Fred Drake235e6b11998-03-27 05:19:43 +0000190 if (%index_labels) { make_index_labels(); }
191 if (($SHORT_INDEX) && (%index_segment)) { make_preindex(); }
Fred Drakebc7101d1998-03-06 21:18:55 +0000192 else { $preindex = ''; }
Fred Drake235e6b11998-03-27 05:19:43 +0000193 my $heading = make_section_heading($idx_title, 'h2') . $idx_mark;
Fred Drake11916921998-04-02 22:30:57 +0000194 my($pre,$post) = minimize_open_tags($heading);
Fred Drake235e6b11998-03-27 05:19:43 +0000195 anchor_label('genindex',$CURRENT_FILE,$_); # this is added
196 '<br>\n' . $pre . $_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000197}
198
199# $idx_module_mark will be replaced with the real index at the end
200sub do_cmd_textohtmlmoduleindex {
201 local($_) = @_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000202 $TITLE = $idx_module_title;
203 &anchor_label("modindex",$CURRENT_FILE,$_);
Fred Drake235e6b11998-03-27 05:19:43 +0000204 '<p>' . make_section_heading($idx_module_title, "h2")
205 . $idx_module_mark . $_;
Fred Drakebc7101d1998-03-06 21:18:55 +0000206}
207
208# The bibliography and the index should be treated as separate sections
209# in their own HTML files. The \bibliography{} command acts as a sectioning command
210# that has the desired effect. But when the bibliography is constructed
211# manually using the thebibliography environment, or when using the
212# theindex environment it is not possible to use the normal sectioning
213# mechanism. This subroutine inserts a \bibliography{} or a dummy
214# \textohtmlindex command just before the appropriate environments
215# to force sectioning.
216
217# XXX This *assumes* that if there are two {theindex} environments, the
218# first is the module index and the second is the standard index. This
219# is sufficient for the current Python documentation, but that's about
220# it.
221
222sub add_bbl_and_idx_dummy_commands {
Fred Drake11916921998-04-02 22:30:57 +0000223 my $id = $global{'max_id'};
Fred Drakebc7101d1998-03-06 21:18:55 +0000224
225 s/([\\]begin\s*$O\d+$C\s*thebibliography)/$bbl_cnt++; $1/eg;
226 s/([\\]begin\s*$O\d+$C\s*thebibliography)/$id++; "\\bibliography$O$id$C$O$id$C $1"/geo
227 #if ($bbl_cnt == 1)
228 ;
229 #}
Fred Drake11916921998-04-02 22:30:57 +0000230 #----------------------------------------------------------------------
231 # (FLD) This was added
232 my(@parts) = split(/\\begin\s*$O\d+$C\s*theindex/);
233 if (scalar(@parts) == 3) {
234 # Be careful to re-write the string in place, since $_ is *not*
235 # returned explicity; *** nasty side-effect dependency! ***
236 print "\nadd_bbl_and_idx_dummy_commands ==> adding module index";
237 my $rx = "([\\\\]begin\\s*$O\\d+$C\\s*theindex[\\s\\S]*)"
238 . "([\\\\]begin\\s*$O\\d+$C\\s*theindex)";
239 s/$rx/\\textohtmlmoduleindex \1 \\textohtmlindex \2/o;
240 }
241 else {
242 $global{'max_id'} = $id; # not sure why....
243 s/([\\]begin\s*$O\d+$C\s*theindex)/\\textohtmlindex $1/o;
244 s/[\\]printindex/\\textohtmlindex /o;
245 }
246 #----------------------------------------------------------------------
247 &lib_add_bbl_and_idx_dummy_commands()
248 if defined(&lib_add_bbl_and_idx_dummy_commands);
Fred Drakebc7101d1998-03-06 21:18:55 +0000249}
250
251# The bibliographic references, the appendices, the lists of figures and tables
252# etc. must appear in the contents table at the same level as the outermost
253# sectioning command. This subroutine finds what is the outermost level and
254# sets the above to the same level;
255
Fred Drake13210ed1998-03-17 06:28:05 +0000256sub set_depth_levels {
257 # Sets $outermost_level
Fred Drake11916921998-04-02 22:30:57 +0000258 my $level;
Fred Drake13210ed1998-03-17 06:28:05 +0000259 #RRM: do not alter user-set value for $MAX_SPLIT_DEPTH
260 foreach $level ("part", "chapter", "section", "subsection",
261 "subsubsection", "paragraph") {
262 last if (($outermost_level) = /\\($level)$delimiter_rx/);
263 }
264 $level = ($outermost_level ? $section_commands{$outermost_level} :
265 do {$outermost_level = 'section'; 3;});
Fred Drakebc7101d1998-03-06 21:18:55 +0000266
Fred Drake13210ed1998-03-17 06:28:05 +0000267 #RRM: but calculate value for $MAX_SPLIT_DEPTH when a $REL_DEPTH was given
268 if ($REL_DEPTH && $MAX_SPLIT_DEPTH) {
269 $MAX_SPLIT_DEPTH = $level + $MAX_SPLIT_DEPTH;
270 } elsif (!($MAX_SPLIT_DEPTH)) { $MAX_SPLIT_DEPTH = 1 };
Fred Drakebc7101d1998-03-06 21:18:55 +0000271
Fred Drake13210ed1998-03-17 06:28:05 +0000272 %unnumbered_section_commands = (
273 'tableofcontents', $level
274 , 'listoffigures', $level
275 , 'listoftables', $level
276 , 'bibliography', $level
277 , 'textohtmlindex', $level
278 , 'textohtmlmoduleindex', $level
279 );
Fred Drake11916921998-04-02 22:30:57 +0000280 $section_headings{'textohtmlmoduleindex'} = "h1";
Fred Drakebc7101d1998-03-06 21:18:55 +0000281
Fred Drake13210ed1998-03-17 06:28:05 +0000282 %section_commands = (
283 %unnumbered_section_commands
284 , %section_commands
285 );
Fred Drake11916921998-04-02 22:30:57 +0000286
287 make_sections_rx();
Fred Drake13210ed1998-03-17 06:28:05 +0000288}
Fred Drakebc7101d1998-03-06 21:18:55 +0000289
290
291# Fix from Ross Moore for ']' in \item[...]; this can be removed once the next
Fred Drake235e6b11998-03-27 05:19:43 +0000292# patch to LaTeX2HTML is released and tested ... if the patch gets included.
293# Be very careful to keep this around, just in case things break again!
Fred Drakebc7101d1998-03-06 21:18:55 +0000294#
295sub protect_useritems {
296 local(*_) = @_;
Fred Drake11916921998-04-02 22:30:57 +0000297 local($preitems,$thisitem);
Fred Drakebc7101d1998-03-06 21:18:55 +0000298 while (/\\item\s*\[/) {
Fred Drake11916921998-04-02 22:30:57 +0000299 $preitems .= $`;
300 $_ = $';
Fred Drakebc7101d1998-03-06 21:18:55 +0000301 $thisitem = $&.'<<'.++$global{'max_id'}.'>>';
302 s/^(((($O|$OP)\d+($C|$CP)).*\3|<[^<>]*>|[^\]<]+)*)\]/$thisitem.=$1;''/e;
Fred Drake11916921998-04-02 22:30:57 +0000303 $preitems .= $thisitem . '<<' . $global{'max_id'} . '>>]';
304 s/^]//;
Fred Drakebc7101d1998-03-06 21:18:55 +0000305 }
306 $_ = $preitems . $_;
307}
308
3091; # This must be the last line