Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 13210ed

Browse files
committed
Get the index working at least partway again.
Some small cleanups.
1 parent bd2796e commit 13210ed

1 file changed

Lines changed: 126 additions & 193 deletions

File tree

Doc/perl/l2hinit.perl

Lines changed: 126 additions & 193 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#LaTeX2HTML Version 96.1 : dot.latex2html-init -*- perl -*-
22
#
3+
# Significantly revised by Fred L. Drake, Jr. <[email protected]> for use
4+
# with the Python documentation.
5+
#
6+
# New name to avoid distributing "dot" files with the Python documentation.
7+
#
38

49
$INFO = 1; # 0 = do not make a "About this document..." section
510
$MAX_LINK_DEPTH = 3;
@@ -47,187 +52,115 @@ sub find_my_file{
4752
$LATEX2HTMLSTYLES = "$mydir$envkey$LATEX2HTMLSTYLES";
4853

4954

50-
sub top_navigation_panel {
51-
52-
# Now add a few buttons with a space between them
53-
"<div class=navigation>\n" .
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) .
55+
sub make_nav_panel{
56+
($NEXT_TITLE ? "$NEXT\n" : '')
57+
. ($UP_TITLE ? "$UP\n" : '')
58+
. ($PREVIOUS_TITLE ? "$PREVIOUS\n" : '')
59+
. "$CONTENTS\n$INDEX"
60+
# . " $CUSTOM_BUTTONS"
61+
. "<br>\n"
62+
. ($NEXT_TITLE ? "<b> Next:</b> $NEXT_TITLE\n" : '')
63+
. ($UP_TITLE ? "<b>Up:</b> $UP_TITLE\n" : '')
64+
. ($PREVIOUS_TITLE ? "<b>Previous:</b> $PREVIOUS_TITLE\n" : '');
65+
}
6666

67-
# Line Break, horizontal rule (3-d dividing line) and new paragraph
68-
"<br><hr><p></div>"
67+
sub top_navigation_panel {
68+
"<div class=navigation>\n"
69+
. &make_nav_panel
70+
. "<br><hr><p></div>"
6971
}
7072

7173
sub bot_navigation_panel {
72-
73-
# Start with a horizontal rule (3-d dividing line)
74-
"<div class=navigation><hr>".
75-
76-
# Now add a few buttons with a space between them
77-
"$NEXT\n$UP\n$PREVIOUS\n$CONTENTS\n$INDEX $CUSTOM_BUTTONS" .
78-
79-
"<br>\n" . # Line break
80-
81-
# If ``next'' section exists, add its title to the navigation panel
82-
($NEXT_TITLE ? "<b> Next:</b> $NEXT_TITLE\n" : undef) .
83-
84-
# Similarly with the ``up'' title ...
85-
($UP_TITLE ? "<b>Up:</b> $UP_TITLE\n" : undef) .
86-
87-
# ... and the ``previous'' title
88-
($PREVIOUS_TITLE ? "<b> Previous:</b> $PREVIOUS_TITLE\n" : undef) .
89-
90-
"</div>"
74+
"<div class=navigation><hr>"
75+
. &make_nav_panel
76+
. "</div>"
9177
}
9278

9379

94-
# sub make_section_heading {
95-
# local($text, $level, $anchors) = @_;
96-
# local($section_tag) = join('', @curr_sec_id);
97-
# local($align,$pre_anchors);
98-
# # separate any invisible anchors or alignment, if this has not already been done
99-
# if (!($anchors)){ ($anchors,$text) = &extract_anchors($text) }
100-
# else {
101-
# $anchors =~ s/(ALIGN=\"\w*\")/$align = " $1";''/e;
102-
# $anchors = &translate_commands($anchors) if ($anchors =~ /\\/);
103-
# }
104-
# if (!($text)) {
105-
# # anchor to a single `.' only
106-
# $text = "<a name=SECTION$section_tag>.</a>$anchors\n";
107-
# } elsif ($anchors) {
108-
# # keep it short and simple!
109-
# $text = "<a name=SECTION$section_tag>$text</a>";
110-
# } elsif (!($text =~ /<A[^\w]/io)) {
111-
# # no embedded anchors, so anchor it all
112-
# $text = "<a name=SECTION$section_tag>\n" . $text . "</a>";
113-
# } else {
114-
# # there are embedded anchors; these cannot be nested
115-
# local ($tmp) = $text;
116-
# $tmp =~ s/<//o ; # find 1st <
117-
# if ($`) { # anchor text before the first <
118-
# # $text = "<A NAME=\"SECTION$section_tag\">\n" . $` . "</A>\n<" . $';
119-
# $text = "<a name=SECTION$section_tag>\n" . $` . "</a>";
120-
# $pre_anchors = "<" . $';
121-
# if ($pre_anchors =~ /^(<A NAME=\"[^\"]+>${anchor_invisible_mark}<\/A>\s*)+$/) {
122-
# $pre_anchors .= "\n"
123-
# } else { $text .= $pre_anchors; $pre_anchors = '' }
124-
# } else {
125-
# # $text starts with a tag
126-
# local($after,$tmp) = ($','');
127-
# if ( $after =~ /^A[^\w]/i ) {
128-
# # it is an anchor already, so need a separate line
129-
# $text = "<a name=SECTION$section_tag>$anchor_invisible_mark</a><br>\n$text";
130-
# } else {
131-
# # Is it a tag enclosing the anchor ?
132-
# $after =~ s/^(\w)*[\s|>]/$tmp = $1;''/eo;
133-
# if ($after =~ /<A.*<\/$tmp>/) {
134-
# # it encloses an anchor, so use anchor_mark + break
135-
# $text = "<a name=SECTION$section_tag>$anchor_invisible_mark</a><br>\n$text";
136-
# } else {
137-
# # take up to the anchor
138-
# $text =~ s/^(.*)<A([^\w])/"<a name=SECTION$section_tag>$1<A$2"/oe;
139-
# }
140-
# }
141-
# }
142-
# }
143-
# "$pre_anchors\n<$level$align>$text\n<\/$level>";
144-
# }
145-
146-
14780
sub gen_index_id {
14881
# this is used to ensure common index key generation and a stable sort
14982
local($str,$extra) = @_;
15083
sprintf("%s###%s%010d", $str, $extra, ++$global{'max_id'});
15184
}
15285

153-
# sub make_index_entry {
154-
# local($br_id,$str) = @_;
155-
# # If TITLE is not yet available (i.e the \index command is in the title of the
156-
# # current section), use $ref_before.
157-
# $TITLE = $ref_before unless $TITLE;
158-
# # Save the reference
159-
# $str = gen_index_id($str, '');
160-
# $index{$str} .= &make_half_href("$CURRENT_FILE#$br_id");
161-
# "<a name=\"$br_id\">$anchor_invisible_mark<\/a>";
162-
# }
86+
sub make_index_entry {
87+
local($br_id,$str) = @_;
88+
# If TITLE is not yet available (i.e the \index command is in the title of the
89+
# current section), use $ref_before.
90+
$TITLE = $ref_before unless $TITLE;
91+
# Save the reference
92+
$str = gen_index_id($str, '');
93+
$index{$str} .= &make_half_href("$CURRENT_FILE#$br_id");
94+
"<a name=\"$br_id\">$anchor_invisible_mark<\/a>";
95+
}
16396

164-
# sub add_idx {
165-
# print "\nDoing the index ...";
166-
# local($key, $str, @keys, $index, $level, $count, @previous, @current);
167-
# @keys = keys %index;
168-
# @keys = sort keysort @keys;
169-
# $level = 0;
170-
# foreach $key (@keys) {
171-
# @current = split(/!/, $key);
172-
# $count = 0;
173-
# while ($current[$count] eq $previous[$count]) {
174-
# $count++;
175-
# }
176-
# while ($count > $level) {
177-
# $index .= "<dl compact>\n";
178-
# $level++;
179-
# }
180-
# while ($count < $level) {
181-
# $index .= "</dl>\n";
182-
# $level--;
183-
# }
184-
# foreach $term (@current[$count .. $#current-1]) {
185-
# # need to "step in" a little
186-
# $index .= "<dt>" . $term . "\n<dl compact>\n";
187-
# $level++;
188-
# }
189-
# $str = $current[$#current];
190-
# $str =~ s/\#\#\#\d+$//o; # Remove the unique id's
191-
# $str =~ s/\#\#\#[DR]EF\d+$//o; # Remove the unique id's
192-
# if (&index_key_eq(join('',@current), join('',@previous))) {
193-
# $index .= ",\n$index{$key}" . $cross_ref_visible_mark . "</a>"; }
194-
# else {
195-
# $index .= "\n<dt>$index{$key}" . $str . "</a>"; }
196-
# @previous = @current;
197-
# }
198-
# while ($count < $level) {
199-
# $index .= "</dl>\n";
200-
# $level--;
201-
# }
202-
# s/$idx_mark/<dl compact>$index<\/dl>/o;
203-
# }
97+
sub add_idx {
98+
print "\nDoing the index ...";
99+
local($key, $str, @keys, $index, $level, $count, @previous, @current);
100+
@keys = keys %index;
101+
@keys = sort keysort @keys;
102+
$level = 0;
103+
foreach $key (@keys) {
104+
@current = split(/!/, $key);
105+
$count = 0;
106+
while ($current[$count] eq $previous[$count]) {
107+
$count++;
108+
}
109+
while ($count > $level) {
110+
$index .= "<dl compact>\n";
111+
$level++;
112+
}
113+
while ($count < $level) {
114+
$index .= "</dl>\n";
115+
$level--;
116+
}
117+
foreach $term (@current[$count .. $#current-1]) {
118+
# need to "step in" a little
119+
$index .= "<dt>" . $term . "\n<dl compact>\n";
120+
$level++;
121+
}
122+
$str = $current[$#current];
123+
$str =~ s/\#\#\#\d+$//o; # Remove the unique id's
124+
$str =~ s/\#\#\#[DR]EF\d+$//o; # Remove the unique id's
125+
if (&index_key_eq(join('',@current), join('',@previous))) {
126+
$index .= ",\n$index{$key}" . $cross_ref_visible_mark . "</a>"; }
127+
else {
128+
$index .= "\n<dt>$index{$key}" . $str . "</a>"; }
129+
@previous = @current;
130+
}
131+
while ($count < $level) {
132+
$index .= "</dl>\n";
133+
$level--;
134+
}
135+
s/$idx_mark/<dl compact>$index<\/dl>/o;
136+
}
204137

205138

206-
# sub index_key_eq {
207-
# local($a,$b) = @_;
208-
# $a = &clean_key($a);
209-
# $a =~ s/\#\#\#\d+$//o; # Remove the unique id's
210-
# $a =~ s/\#\#\#[dr]ef\d+$//o; # Remove the unique id's
211-
# $b = &clean_key($b);
212-
# $b =~ s/\#\#\#\d+$//o; # Remove the unique id's
213-
# $b =~ s/\#\#\#[dr]ef\d+$//o; # Remove the unique id's
214-
# $a eq $b;
215-
# }
139+
sub index_key_eq{
140+
local($a,$b) = @_;
141+
$a = &clean_key($a);
142+
$a =~ s/\#\#\#\d+$//o; # Remove the unique id's
143+
$a =~ s/\#\#\#[dr]ef\d+$//o; # Remove the unique id's
144+
$b = &clean_key($b);
145+
$b =~ s/\#\#\#\d+$//o; # Remove the unique id's
146+
$b =~ s/\#\#\#[dr]ef\d+$//o; # Remove the unique id's
147+
$a eq $b;
148+
}
216149

217150
# need to remove leading <...>
218-
# sub clean_key {
219-
# local ($_) = @_;
220-
# tr/A-Z/a-z/;
221-
# s/\s//;
222-
# s/^<[a-z][-._a-z0-9]*>//; # Remove leading <gi>
223-
# $_;
224-
# }
151+
sub clean_key{
152+
local ($_) = @_;
153+
tr/A-Z/a-z/;
154+
s/\s//;
155+
s/^<[a-z][-._a-z0-9]*>//; # Remove leading <gi> (no attributes)
156+
$_;
157+
}
225158

226159

227160
$idx_module_mark = '<tex2html_idx_module_mark>';
228161
$idx_module_title = 'Module Index';
229162

230-
sub add_module_idx {
163+
sub add_module_idx{
231164
print "\nDoing the module index ...";
232165
local($key, @keys, $index);
233166
$index = "<p>";
@@ -261,7 +194,7 @@ sub do_cmd_tableofcontents {
261194
$TITLE = $toc_title;
262195
$tocfile = $CURRENT_FILE;
263196
local($closures,$reopens) = &preserve_open_tags();
264-
&anchor_label("contents",$CURRENT_FILE,$_); # this is added
197+
&anchor_label("contents",$CURRENT_FILE,$_); # this is added
265198
join('', "<BR>\n", $closures
266199
, &make_section_heading($toc_title, "H2"), $toc_mark
267200
, $reopens, $_);
@@ -272,7 +205,7 @@ sub do_cmd_listoffigures {
272205
$TITLE = $lof_title;
273206
$loffile = $CURRENT_FILE;
274207
local($closures,$reopens) = &preserve_open_tags();
275-
&anchor_label("lof",$CURRENT_FILE,$_); # this is added
208+
&anchor_label("lof",$CURRENT_FILE,$_); # this is added
276209
join('', "<BR>\n", $closures
277210
, &make_section_heading($lof_title, "H2"), $lof_mark
278211
, $reopens, $_);
@@ -283,7 +216,7 @@ sub do_cmd_listoftables {
283216
$TITLE = $lot_title;
284217
$lotfile = $CURRENT_FILE;
285218
local($closures,$reopens) = &preserve_open_tags();
286-
&anchor_label("lot",$CURRENT_FILE,$_); # this is added
219+
&anchor_label("lot",$CURRENT_FILE,$_); # this is added
287220
join('', "<BR>\n", $closures
288221
, &make_section_heading($lot_title, "H2"), $lot_mark
289222
, $reopens, $_);
@@ -320,7 +253,7 @@ sub do_cmd_textohtmlindex {
320253
local($heading) = join('',&make_section_heading($idx_title, "H2"),
321254
$idx_mark);
322255
local($pre,$post) = &minimize_open_tags($heading);
323-
&anchor_label("genindex",$CURRENT_FILE,$_); # this is added
256+
&anchor_label("genindex",$CURRENT_FILE,$_); # this is added
324257
join('',"<BR>\n" , $pre, $_);
325258
}
326259

@@ -377,38 +310,38 @@ sub add_bbl_and_idx_dummy_commands {
377310
# sectioning command. This subroutine finds what is the outermost level and
378311
# sets the above to the same level;
379312

380-
%section_commands = ('textohtmlmoduleindex', 2, %section_commands);
313+
#%section_commands = ('textohtmlmoduleindex', 1, %section_commands);
381314

382-
# sub set_depth_levels {
383-
# # Sets $outermost_level
384-
# local($level);
385-
# #RRM: do not alter user-set value for $MAX_SPLIT_DEPTH
386-
# foreach $level ("part", "chapter", "section", "subsection",
387-
# "subsubsection", "paragraph") {
388-
# last if (($outermost_level) = /\\($level)$delimiter_rx/);
389-
# }
390-
# $level = ($outermost_level ? $section_commands{$outermost_level} :
391-
# do {$outermost_level = 'section'; 3;});
392-
393-
# #RRM: but calculate value for $MAX_SPLIT_DEPTH when a $REL_DEPTH was given
394-
# if ($REL_DEPTH && $MAX_SPLIT_DEPTH) {
395-
# $MAX_SPLIT_DEPTH = $level + $MAX_SPLIT_DEPTH;
396-
# } elsif (!($MAX_SPLIT_DEPTH)) { $MAX_SPLIT_DEPTH = 1 };
397-
398-
# %unnumbered_section_commands = (
399-
# 'tableofcontents', $level
400-
# , 'listoffigures', $level
401-
# , 'listoftables', $level
402-
# , 'bibliography', $level
403-
# , 'textohtmlindex', $level
404-
# , 'textohtmlmoduleindex', $level
405-
# );
406-
407-
# %section_commands = (
408-
# %unnumbered_section_commands
409-
# , %section_commands
410-
# );
411-
# }
315+
sub set_depth_levels {
316+
# Sets $outermost_level
317+
local($level);
318+
#RRM: do not alter user-set value for $MAX_SPLIT_DEPTH
319+
foreach $level ("part", "chapter", "section", "subsection",
320+
"subsubsection", "paragraph") {
321+
last if (($outermost_level) = /\\($level)$delimiter_rx/);
322+
}
323+
$level = ($outermost_level ? $section_commands{$outermost_level} :
324+
do {$outermost_level = 'section'; 3;});
325+
326+
#RRM: but calculate value for $MAX_SPLIT_DEPTH when a $REL_DEPTH was given
327+
if ($REL_DEPTH && $MAX_SPLIT_DEPTH) {
328+
$MAX_SPLIT_DEPTH = $level + $MAX_SPLIT_DEPTH;
329+
} elsif (!($MAX_SPLIT_DEPTH)) { $MAX_SPLIT_DEPTH = 1 };
330+
331+
%unnumbered_section_commands = (
332+
'tableofcontents', $level
333+
, 'listoffigures', $level
334+
, 'listoftables', $level
335+
, 'bibliography', $level
336+
, 'textohtmlindex', $level
337+
, 'textohtmlmoduleindex', $level
338+
);
339+
340+
%section_commands = (
341+
%unnumbered_section_commands
342+
, %section_commands
343+
);
344+
}
412345

413346

414347
# Fix from Ross Moore for ']' in \item[...]; this can be removed once the next

0 commit comments

Comments
 (0)