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