Oops -- Lib/Test should be Lib/test, of course!
[python/dscho.git] / Doc / perl / l2hinit.perl
blob2fa29aff0194b12f8cdbf3757e3a802bb17acde6
1 #LaTeX2HTML Version 96.1 : dot.latex2html-init -*- perl -*-
3 # Significantly revised by Fred L. Drake, Jr. <fdrake@acm.org> for use
4 # with the Python documentation.
6 # New name to avoid distributing "dot" files with the Python documentation.
9 $INFO = 1; # 0 = do not make a "About this document..." section
10 $MAX_LINK_DEPTH = 3;
12 $NUMBERED_FOOTNOTES = 1;
14 # Python documentation uses section numbers to support references to match
15 # in the printed and online versions.
17 $SHOW_SECTION_NUMBERS = 1;
19 $ICONSERVER = '../icons';
21 $CHILDLINE = "\n<p><hr>\n";
22 $VERBOSITY = 0;
24 # 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.
28 sub find_my_file{
29 my($myfile,$key,$tmp,$mydir) = (@_[0], '', '', '');
30 foreach $key (keys %INC) {
31 $tmp = "$key";
32 $tmp =~ s|^.*/||o;
33 if ($tmp eq $myfile) {
34 $mydir = $INC{$key};
37 $mydir =~ s|/[^/]*$||;
38 $mydir;
42 # 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).
45 use Cwd;
46 use File::Basename;
47 ($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
48 chop $mydir; # remove trailing '/'
49 $mydir = getcwd() . "$dd$mydir"
50 unless $mydir =~ s|^/|/|;
51 $LATEX2HTMLSTYLES = "$mydir$envkey$LATEX2HTMLSTYLES";
53 ($myrootname, $myrootdir, $myext) = fileparse($mydir, '\..*');
54 chop $myrootdir;
57 sub 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" : '');
69 sub top_navigation_panel {
70 "<div class=navigation>\n"
71 . &make_nav_panel
72 . "<br><hr><p></div>"
75 sub bot_navigation_panel {
76 "<p>\n<div class=navigation><hr>"
77 . &make_nav_panel
78 . "</div>"
82 sub gen_index_id {
83 # this is used to ensure common index key generation and a stable sort
84 my($str,$extra) = @_;
85 sprintf("%s###%s%010d", $str, $extra, ++$global{'max_id'});
88 sub make_index_entry {
89 my($br_id,$str) = @_;
90 # 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>";
99 # use this instead with the buildindex.py tool
100 sub add_idx{
101 print "\nDoing the index ...";
102 close(IDXFILE);
103 my $index = `$myrootdir/tools/buildindex.py index.dat`;
104 s/$idx_mark/$index/;
108 $idx_module_mark = '<tex2html_idx_module_mark>';
109 $idx_module_title = 'Module Index';
111 sub add_module_idx{
112 print "\nDoing the module index ...";
113 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}" . $IDXFILE_FIELD_SEP . "$key###\n";
120 close(MODIDXFILE);
121 $index = `$myrootdir/tools/buildindex.py modindex.dat`;
122 s/$idx_module_mark/$index<p>/;
125 # replace both indexes as needed:
126 sub add_idx_hook{
127 &add_idx if (/$idx_mark/);
128 &add_module_idx if (/$idx_module_mark/);
132 # In addition to the standard stuff, add label to allow named node files.
133 sub do_cmd_tableofcontents {
134 local($_) = @_;
135 $TITLE = $toc_title;
136 $tocfile = $CURRENT_FILE;
137 my($closures,$reopens) = &preserve_open_tags();
138 &anchor_label("contents",$CURRENT_FILE,$_); # this is added
139 join('', "<BR>\n", $closures
140 , &make_section_heading($toc_title, "H2"), $toc_mark
141 , $reopens, $_);
143 # In addition to the standard stuff, add label to allow named node files.
144 sub do_cmd_listoffigures {
145 local($_) = @_;
146 $TITLE = $lof_title;
147 $loffile = $CURRENT_FILE;
148 my($closures,$reopens) = &preserve_open_tags();
149 &anchor_label("lof",$CURRENT_FILE,$_); # this is added
150 join('', "<BR>\n", $closures
151 , &make_section_heading($lof_title, "H2"), $lof_mark
152 , $reopens, $_);
154 # In addition to the standard stuff, add label to allow named node files.
155 sub do_cmd_listoftables {
156 local($_) = @_;
157 $TITLE = $lot_title;
158 $lotfile = $CURRENT_FILE;
159 my($closures,$reopens) = &preserve_open_tags();
160 &anchor_label("lot",$CURRENT_FILE,$_); # this is added
161 join('', "<BR>\n", $closures
162 , &make_section_heading($lot_title, "H2"), $lot_mark
163 , $reopens, $_);
165 # In addition to the standard stuff, add label to allow named node files.
166 sub do_cmd_textohtmlinfopage {
167 local($_) = @_;
168 if ($INFO) { #
169 &anchor_label("about",$CURRENT_FILE,$_); # this is added
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, $_))
186 # $idx_mark will be replaced with the real index at the end
187 sub do_cmd_textohtmlindex {
188 local($_) = @_;
189 $TITLE = $idx_title;
190 $idxfile = $CURRENT_FILE;
191 if (%index_labels) { make_index_labels(); }
192 if (($SHORT_INDEX) && (%index_segment)) { make_preindex(); }
193 else { $preindex = ''; }
194 my $heading = make_section_heading($idx_title, 'h2') . $idx_mark;
195 my($pre,$post) = minimize_open_tags($heading);
196 anchor_label('genindex',$CURRENT_FILE,$_); # this is added
197 '<br>\n' . $pre . $_;
200 # $idx_module_mark will be replaced with the real index at the end
201 sub do_cmd_textohtmlmoduleindex {
202 local($_) = @_;
203 $TITLE = $idx_module_title;
204 &anchor_label("modindex",$CURRENT_FILE,$_);
205 '<p>' . make_section_heading($idx_module_title, "h2")
206 . $idx_module_mark . $_;
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.
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.
223 sub add_bbl_and_idx_dummy_commands {
224 my $id = $global{'max_id'};
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)
231 #----------------------------------------------------------------------
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;
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;
247 #----------------------------------------------------------------------
248 &lib_add_bbl_and_idx_dummy_commands()
249 if defined(&lib_add_bbl_and_idx_dummy_commands);
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;
257 sub set_depth_levels {
258 # Sets $outermost_level
259 my $level;
260 #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/);
265 $level = ($outermost_level ? $section_commands{$outermost_level} :
266 do {$outermost_level = 'section'; 3;});
268 #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 };
273 %unnumbered_section_commands = (
274 'tableofcontents', $level
275 , 'listoffigures', $level
276 , 'listoftables', $level
277 , 'bibliography', $level
278 , 'textohtmlindex', $level
279 , 'textohtmlmoduleindex', $level
281 $section_headings{'textohtmlmoduleindex'} = "h1";
283 %section_commands = (
284 %unnumbered_section_commands
285 , %section_commands
288 make_sections_rx();
292 # Fix from Ross Moore for ']' in \item[...]; this can be removed once the next
293 # 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!
296 sub protect_useritems {
297 local(*_) = @_;
298 local($preitems,$thisitem);
299 while (/\\item\s*\[/) {
300 $preitems .= $`;
301 $_ = $';
302 $thisitem = $&.'<<'.++$global{'max_id'}.'>>';
303 s/^(((($O|$OP)\d+($C|$CP)).*\3|<[^<>]*>|[^\]<]+)*)\]/$thisitem.=$1;''/e;
304 $preitems .= $thisitem . '<<' . $global{'max_id'} . '>>]';
305 s/^]//;
307 $_ = $preitems . $_;
310 # This changes the markup used for {verbatim} environments, and is the
311 # best way I've found that ensures the <dl> goes one the outside of the
312 # <pre>...</pre>.
314 # Note that this *must* be done in the init file, not the python.perl
315 # style support file. The %declarations must be set before initialize()
316 # is called in the main script.
318 %declarations = ('preform', '<dl><dd><pre></pre></dl>',
319 %declarations);
321 1; # This must be the last line