blob: 96146e911d77ed9b18a484bb5d298abaaafcd169 [file] [log] [blame]
Fred Drakebc7101d1998-03-06 21:18:55 +00001#LaTeX2HTML Version 96.1 : dot.latex2html-init -*- perl -*-
2#
3
4$INFO = 1; # 0 = do not make a "About this document..." section
5$MAX_LINK_DEPTH = 3;
6
7$NUMBERED_FOOTNOTES = 1;
8
9# Python documentation uses section numbers to support references to match
10# in the printed and online versions.
11#
12$SHOW_SECTION_NUMBERS = 1;
13
14$ICONSERVER = '../icons';
15
16$CHILDLINE = "\n<p><hr>\n";
17$VERBOSITY = 0;
18
Fred Drakedb34a1e1998-03-10 23:02:57 +000019# Locate a file that's been "require"d. Assumes that the file name of interest
20# is unique within the set of loaded files, after directory names have been
21# stripped. Only the directory is returned.
22#
23sub find_my_file{
24 local($myfile,$key,$tmp,$mydir) = (@_[0], '', '', '');
25 foreach $key (keys %INC) {
26 $tmp = "$key";
27 $tmp =~ s|^.*/||o;
28 if ($tmp eq $myfile) {
29 #print "\nfound $tmp: $key --> ", $INC{$key}, "\n";
30 $mydir = $INC{$key};
31 }
32 }
33 $mydir =~ s|/[^/]*$||;
34 $mydir;
35}
Fred Drakebc7101d1998-03-06 21:18:55 +000036
Fred Drakedb34a1e1998-03-10 23:02:57 +000037# A little painful, but lets us clean up the top level directory a little,
38# and not be tied to the current directory (as far as I can tell).
39#
40$mydir = &find_my_file("l2hinit.perl");
41#print "\nmy dir = $mydir\n";
42$LATEX2HTMLSTYLES = "$mydir$envkey$LATEX2HTMLSTYLES";
Fred Drakebc7101d1998-03-06 21:18:55 +000043
44
45sub top_navigation_panel {
46
47 # Now add a few buttons with a space between them
48 "<div class=navigation>\n" .
49 "$NEXT\n$UP\n$PREVIOUS\n$CONTENTS\n$INDEX $CUSTOM_BUTTONS" .
50
51 "<br>\n" . # Line break
52
53 # If ``next'' section exists, add its title to the navigation panel
54 ($NEXT_TITLE ? "<b> Next:</b> $NEXT_TITLE\n" : undef) .
55
56 # Similarly with the ``up'' title ...
57 ($UP_TITLE ? "<b>Up:</b> $UP_TITLE\n" : undef) .
58
59 # ... and the ``previous'' title
60 ($PREVIOUS_TITLE ? "<b> Previous:</b> $PREVIOUS_TITLE\n" : undef) .
61
62 # Line Break, horizontal rule (3-d dividing line) and new paragraph
63 "<br><hr><p></div>"
64}
65
66sub bot_navigation_panel {
67
68 # Start with a horizontal rule (3-d dividing line)
69 "<div class=navigation><hr>".
70
71 # Now add a few buttons with a space between them
72 "$NEXT\n$UP\n$PREVIOUS\n$CONTENTS\n$INDEX $CUSTOM_BUTTONS" .
73
74 "<br>\n" . # Line break
75
76 # If ``next'' section exists, add its title to the navigation panel
77 ($NEXT_TITLE ? "<b> Next:</b> $NEXT_TITLE\n" : undef) .
78
79 # Similarly with the ``up'' title ...
80 ($UP_TITLE ? "<b>Up:</b> $UP_TITLE\n" : undef) .
81
82 # ... and the ``previous'' title
83 ($PREVIOUS_TITLE ? "<b> Previous:</b> $PREVIOUS_TITLE\n" : undef) .
84
85 "</div>"
86}
87
88
89# sub make_section_heading {
90# local($text, $level, $anchors) = @_;
91# local($section_tag) = join('', @curr_sec_id);
92# local($align,$pre_anchors);
93# # separate any invisible anchors or alignment, if this has not already been done
94# if (!($anchors)){ ($anchors,$text) = &extract_anchors($text) }
95# else {
96# $anchors =~ s/(ALIGN=\"\w*\")/$align = " $1";''/e;
97# $anchors = &translate_commands($anchors) if ($anchors =~ /\\/);
98# }
99# if (!($text)) {
100# # anchor to a single `.' only
101# $text = "<a name=SECTION$section_tag>.</a>$anchors\n";
102# } elsif ($anchors) {
103# # keep it short and simple!
104# $text = "<a name=SECTION$section_tag>$text</a>";
105# } elsif (!($text =~ /<A[^\w]/io)) {
106# # no embedded anchors, so anchor it all
107# $text = "<a name=SECTION$section_tag>\n" . $text . "</a>";
108# } else {
109# # there are embedded anchors; these cannot be nested
110# local ($tmp) = $text;
111# $tmp =~ s/<//o ; # find 1st <
112# if ($`) { # anchor text before the first <
113# # $text = "<A NAME=\"SECTION$section_tag\">\n" . $` . "</A>\n<" . $';
114# $text = "<a name=SECTION$section_tag>\n" . $` . "</a>";
115# $pre_anchors = "<" . $';
116# if ($pre_anchors =~ /^(<A NAME=\"[^\"]+>${anchor_invisible_mark}<\/A>\s*)+$/) {
117# $pre_anchors .= "\n"
118# } else { $text .= $pre_anchors; $pre_anchors = '' }
119# } else {
120# # $text starts with a tag
121# local($after,$tmp) = ($','');
122# if ( $after =~ /^A[^\w]/i ) {
123# # it is an anchor already, so need a separate line
124# $text = "<a name=SECTION$section_tag>$anchor_invisible_mark</a><br>\n$text";
125# } else {
126# # Is it a tag enclosing the anchor ?
127# $after =~ s/^(\w)*[\s|>]/$tmp = $1;''/eo;
128# if ($after =~ /<A.*<\/$tmp>/) {
129# # it encloses an anchor, so use anchor_mark + break
130# $text = "<a name=SECTION$section_tag>$anchor_invisible_mark</a><br>\n$text";
131# } else {
132# # take up to the anchor
133# $text =~ s/^(.*)<A([^\w])/"<a name=SECTION$section_tag>$1<A$2"/oe;
134# }
135# }
136# }
137# }
138# "$pre_anchors\n<$level$align>$text\n<\/$level>";
139# }
140
141
142sub gen_index_id {
143 # this is used to ensure common index key generation and a stable sort
144 local($str,$extra) = @_;
145 sprintf("%s###%s%010d", $str, $extra, ++$global{'max_id'});
146}
147
148# sub make_index_entry {
149# local($br_id,$str) = @_;
150# # If TITLE is not yet available (i.e the \index command is in the title of the
151# # current section), use $ref_before.
152# $TITLE = $ref_before unless $TITLE;
153# # Save the reference
154# $str = gen_index_id($str, '');
155# $index{$str} .= &make_half_href("$CURRENT_FILE#$br_id");
156# "<a name=\"$br_id\">$anchor_invisible_mark<\/a>";
157# }
158
159# sub add_idx {
160# print "\nDoing the index ...";
161# local($key, $str, @keys, $index, $level, $count, @previous, @current);
162# @keys = keys %index;
163# @keys = sort keysort @keys;
164# $level = 0;
165# foreach $key (@keys) {
166# @current = split(/!/, $key);
167# $count = 0;
168# while ($current[$count] eq $previous[$count]) {
169# $count++;
170# }
171# while ($count > $level) {
172# $index .= "<dl compact>\n";
173# $level++;
174# }
175# while ($count < $level) {
176# $index .= "</dl>\n";
177# $level--;
178# }
179# foreach $term (@current[$count .. $#current-1]) {
180# # need to "step in" a little
181# $index .= "<dt>" . $term . "\n<dl compact>\n";
182# $level++;
183# }
184# $str = $current[$#current];
185# $str =~ s/\#\#\#\d+$//o; # Remove the unique id's
186# $str =~ s/\#\#\#[DR]EF\d+$//o; # Remove the unique id's
187# if (&index_key_eq(join('',@current), join('',@previous))) {
188# $index .= ",\n$index{$key}" . $cross_ref_visible_mark . "</a>"; }
189# else {
190# $index .= "\n<dt>$index{$key}" . $str . "</a>"; }
191# @previous = @current;
192# }
193# while ($count < $level) {
194# $index .= "</dl>\n";
195# $level--;
196# }
197# s/$idx_mark/<dl compact>$index<\/dl>/o;
198# }
199
200
201# sub index_key_eq {
202# local($a,$b) = @_;
203# $a = &clean_key($a);
204# $a =~ s/\#\#\#\d+$//o; # Remove the unique id's
205# $a =~ s/\#\#\#[dr]ef\d+$//o; # Remove the unique id's
206# $b = &clean_key($b);
207# $b =~ s/\#\#\#\d+$//o; # Remove the unique id's
208# $b =~ s/\#\#\#[dr]ef\d+$//o; # Remove the unique id's
209# $a eq $b;
210# }
211
212# need to remove leading <...>
213# sub clean_key {
214# local ($_) = @_;
215# tr/A-Z/a-z/;
216# s/\s//;
217# s/^<[a-z][-._a-z0-9]*>//; # Remove leading <gi>
218# $_;
219# }
220
221
222$idx_module_mark = '<tex2html_idx_module_mark>';
223$idx_module_title = 'Module Index';
224
225sub add_module_idx {
226 print "\nDoing the module index ...";
227 local($key, @keys, $index);
228 $index = "<p>";
229 @keys = keys %Modules;
230 @keys = sort keysort @keys;
231 foreach $key (@keys) {
232 $index .= "$Modules{$key}$key</a><br>\n";
233 }
234 s/$idx_module_mark/$index<p>/o;
235}
236
237
238# sub remove_general_markers {
239# s/$lof_mark/<UL>$figure_captions<\/UL>/o;
240# s/$lot_mark/<UL>$table_captions<\/UL>/o;
241# &replace_citations if /$bbl_mark/;
242# &add_toc if (/$toc_mark/);
243# &add_idx if (/$idx_mark/);
244# &add_module_idx if (/$idx_module_mark/);
245# &replace_cross_references if /$cross_ref_mark/;
246# &replace_external_references if /$external_ref_mark/;
247# &replace_cite_references if /$cite_mark/;
248# if (defined &replace_user_references) {
249# &replace_user_references if /$user_ref_mark/;
250# }
251# }
252
253# In addition to the standard stuff, add label to allow named node files.
254sub do_cmd_tableofcontents {
255 local($_) = @_;
256 $TITLE = $toc_title;
257 $tocfile = $CURRENT_FILE;
258 local($closures,$reopens) = &preserve_open_tags();
259 &anchor_label("contents",$CURRENT_FILE,$_); # this is added
260 join('', "<BR>\n", $closures
261 , &make_section_heading($toc_title, "H2"), $toc_mark
262 , $reopens, $_);
263}
264# In addition to the standard stuff, add label to allow named node files.
265sub do_cmd_listoffigures {
266 local($_) = @_;
267 $TITLE = $lof_title;
268 $loffile = $CURRENT_FILE;
269 local($closures,$reopens) = &preserve_open_tags();
270 &anchor_label("lof",$CURRENT_FILE,$_); # this is added
271 join('', "<BR>\n", $closures
272 , &make_section_heading($lof_title, "H2"), $lof_mark
273 , $reopens, $_);
274}
275# In addition to the standard stuff, add label to allow named node files.
276sub do_cmd_listoftables {
277 local($_) = @_;
278 $TITLE = $lot_title;
279 $lotfile = $CURRENT_FILE;
280 local($closures,$reopens) = &preserve_open_tags();
281 &anchor_label("lot",$CURRENT_FILE,$_); # this is added
282 join('', "<BR>\n", $closures
283 , &make_section_heading($lot_title, "H2"), $lot_mark
284 , $reopens, $_);
285}
286# In addition to the standard stuff, add label to allow named node files.
287sub do_cmd_textohtmlinfopage {
288 local($_) = @_;
289 if ($INFO) { #
290 &anchor_label("about",$CURRENT_FILE,$_); # this is added
291 } #
292 ( ($INFO == 1)
293 ? join('', $close_all
294 , "<STRONG>$t_title</STRONG><P>\nThis document was generated using the\n"
295 , "<A HREF=\"$TEX2HTMLADDRESS\"><STRONG>LaTeX</STRONG>2<tt>HTML</tt></A>"
296 , " translator Version $TEX2HTMLVERSION\n"
297 , "<P>Copyright &#169; 1993, 1994, 1995, 1996, 1997,\n"
298 , "<A HREF=\"$AUTHORADDRESS\">Nikos Drakos</A>, \n"
299 , "Computer Based Learning Unit, University of Leeds.\n"
300 , "<P>The command line arguments were: <BR>\n "
301 , "<STRONG>latex2html</STRONG> <tt>$argv</tt>.\n"
302 , "<P>The translation was initiated by $address_data[0] on $address_data[1]"
303 , $open_all, $_)
304 : join('', $close_all, $INFO,"\n", $open_all, $_))
305}
306
307# $idx_mark will be replaced with the real index at the end
308sub do_cmd_textohtmlindex {
309 local($_) = @_;
310 $TITLE = $idx_title;
311 $idxfile = $CURRENT_FILE;
312 if (%index_labels) { &make_index_labels(); }
313 if (($SHORT_INDEX) && (%index_segment)) { &make_preindex(); }
314 else { $preindex = ''; }
315 local($heading) = join('',&make_section_heading($idx_title, "H2"),
316 $idx_mark);
317 local($pre,$post) = &minimize_open_tags($heading);
318 &anchor_label("genindex",$CURRENT_FILE,$_); # this is added
319 join('',"<BR>\n" , $pre, $_);
320}
321
322# $idx_module_mark will be replaced with the real index at the end
323sub do_cmd_textohtmlmoduleindex {
324 local($_) = @_;
325 local($key) = q/modindex/;
326 $TITLE = $idx_module_title;
327 &anchor_label("modindex",$CURRENT_FILE,$_);
328 join('', '<p>' , &make_section_heading($idx_module_title, "h2"),
329 $idx_module_mark, $_);
330}
331
332# The bibliography and the index should be treated as separate sections
333# in their own HTML files. The \bibliography{} command acts as a sectioning command
334# that has the desired effect. But when the bibliography is constructed
335# manually using the thebibliography environment, or when using the
336# theindex environment it is not possible to use the normal sectioning
337# mechanism. This subroutine inserts a \bibliography{} or a dummy
338# \textohtmlindex command just before the appropriate environments
339# to force sectioning.
340
341# XXX This *assumes* that if there are two {theindex} environments, the
342# first is the module index and the second is the standard index. This
343# is sufficient for the current Python documentation, but that's about
344# it.
345
346sub add_bbl_and_idx_dummy_commands {
347 local($id) = $global{'max_id'};
348
349 $section_commands{'textohtmlmoduleindex'} = 2;
350
351 s/([\\]begin\s*$O\d+$C\s*thebibliography)/$bbl_cnt++; $1/eg;
352 s/([\\]begin\s*$O\d+$C\s*thebibliography)/$id++; "\\bibliography$O$id$C$O$id$C $1"/geo
353 #if ($bbl_cnt == 1)
354 ;
355 #}
356 #----------------------------------------------------------------------#
357 # (FLD) This was added #
358 local(@parts) = split(/\\begin\s*$O\d+$C\s*theindex/); #
359 if (scalar(@parts) == 3) { #
360 print "\n&add_bbl_and_idx_dummy_commands ==> adding module index"; #
361 s/([\\]begin\s*$O\d+$C\s*theindex)/\\textohtmlmoduleindex $1/o; #
362 } #
363 #----------------------------------------------------------------------#
364 $global{'max_id'} = $id;
365 s/([\\]begin\s*$O\d+$C\s*theindex)/\\textohtmlindex $1/o;
366 s/[\\]printindex/\\textohtmlindex /o;
367 &lib_add_bbl_and_idx_dummy_commands() if defined(&lib_add_bbl_and_idx_dummy_commands);
368}
369
370# The bibliographic references, the appendices, the lists of figures and tables
371# etc. must appear in the contents table at the same level as the outermost
372# sectioning command. This subroutine finds what is the outermost level and
373# sets the above to the same level;
374
375%section_commands = ('textohtmlmoduleindex', 2, %section_commands);
376
377# sub set_depth_levels {
378# # Sets $outermost_level
379# local($level);
380# #RRM: do not alter user-set value for $MAX_SPLIT_DEPTH
381# foreach $level ("part", "chapter", "section", "subsection",
382# "subsubsection", "paragraph") {
383# last if (($outermost_level) = /\\($level)$delimiter_rx/);
384# }
385# $level = ($outermost_level ? $section_commands{$outermost_level} :
386# do {$outermost_level = 'section'; 3;});
387
388# #RRM: but calculate value for $MAX_SPLIT_DEPTH when a $REL_DEPTH was given
389# if ($REL_DEPTH && $MAX_SPLIT_DEPTH) {
390# $MAX_SPLIT_DEPTH = $level + $MAX_SPLIT_DEPTH;
391# } elsif (!($MAX_SPLIT_DEPTH)) { $MAX_SPLIT_DEPTH = 1 };
392
393# %unnumbered_section_commands = (
394# 'tableofcontents', $level
395# , 'listoffigures', $level
396# , 'listoftables', $level
397# , 'bibliography', $level
398# , 'textohtmlindex', $level
399# , 'textohtmlmoduleindex', $level
400# );
401
402# %section_commands = (
403# %unnumbered_section_commands
404# , %section_commands
405# );
406# }
407
408
409# Fix from Ross Moore for ']' in \item[...]; this can be removed once the next
410# patch to LaTeX2HTML is released and tested.
411#
412sub protect_useritems {
413 local(*_) = @_;
414 local($preitems, $thisitem);
415 while (/\\item\s*\[/) {
416 $preitems .= $`; $_ = $';
417 $thisitem = $&.'<<'.++$global{'max_id'}.'>>';
418 s/^(((($O|$OP)\d+($C|$CP)).*\3|<[^<>]*>|[^\]<]+)*)\]/$thisitem.=$1;''/e;
419 $preitems .= $thisitem.'<<'.$global{'max_id'}.'>>]'; s/^]//;
420 }
421 $_ = $preitems . $_;
422}
423
4241; # This must be the last line