]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/lilypond-texi2html.init
ae609e3d521461167d4aa7c7eb8497c4770774e8
[lilypond.git] / Documentation / lilypond-texi2html.init
1 #!/usr/bin/env perl
2 # -*- coding: utf-8; -*-
3
4 ### texi2html customization script for LilyPond
5 ### Author: Reinhold Kainhofer <reinhold@kainhofer.com>, 2008.
6 ###         Some code parts copied from texi2html and adapted. These functions
7 ###         were written mainly by Patrice Dumas
8 ### License: GPLv2+
9 ###
10 ###
11 ### Features implemented here:
12 ### -) For split manuals, the main page is index.html.
13 ### -) All @unnumbered* sections are placed into the same file
14 ###    (implemented by split_at_numbered_sections)
15 ### -) Use our custom CSS file, with IE-specific fixes in another CSS file,
16 ###    impelmented by lilypond_css_lines
17 ### -) TOC (folded, with the current page highlighted) in an overflown <div>
18 ###    is added to every page; implemented by:
19 ###           lilypond_print_element_header -- building of the TOC
20 ###           lilypond_toc_body -- generation of customized TOC output
21 ###           lilypond_print_page_head -- start <div id="main">
22 ###           print_lilypond_page_foot -- closing id=main, output of footer & TOC
23 ### -) External refs are formatted only as "Text of the node" (not as >>see
24 ###    "NODE" section "SECTION" in "BOOK"<< like with default texi2html). Also,
25 ###    the leading "(book-name)" is removed.
26 ###    Implemented by overriding lilypond_external_ref
27 ### -) Navigation bars on top/bottom of the page and between sections are not
28 ###    left-aligned, but use a combination of left/center/right aligned table
29 ###    cells; For this, I heavily extend the texi2html code to allow for
30 ###    differently aligned cells and for multi-line tables);
31 ###    Implemented in lilypond_print_navigation
32 ### -) Different formatting than the default: example uses the same formatting
33 ###    as quote.
34 ### -) Allow translated section titles: All section titles can be translated,
35 ###    the original (English) title is associated with @translationof. This is
36 ###    needed, because the file name / anchor is generated from the original
37 ###    English title, since otherwise language-autoselection would break with
38 ###    posted links.
39 ###    Since it is then no longer possible to obtain the file name from the
40 ###    section title, I keep a sectionname<=>filename/anchor around. This way,
41 ###    xrefs from other manuals can simply load that map and retrieve the
42 ###    correct file name for the link. Implemented in:
43 ###           lilypond_unknown (handling of @translationof, in case
44 ###                             extract_texi_filenames.py messes up...)
45 ###           lilypond_element_file_name (correct file name: use the map)
46 ###           lilypond_element_target_name (correct anchor: use the map)
47 ###           lilypond_init_map (read in the externally created map from disk)
48 ###           lilypond_external_href (load the map for xrefs, use the correct
49 ###                                   link target)
50 ### -) The HTML anchors for all sections are derived from the node name /
51 ###    section title (pre-generated in the .xref-map file). Implemented by:
52 ###           lilypond_element_target_name (adjust section anchors)
53 ### -) Use the standard footnote format "<sup>nr</sup> text" instead of the
54 ###    ugly format of texi2html (<h3>(nr)</h3><p>text</p>). Implemented in
55 ###           makeinfo_like_foot_line_and_ref
56 ###           makeinfo_like_foot_lines
57 ###           makeinfo_like_paragraph
58 ###
59 ###
60 ### Useful helper functions:
61 ### -) texinfo_file_name($node_name): returns a texinfo-compatible file name
62 ###    for the given string $node_name (whitespace trimmed/replaced by -,
63 ###    non-standard chars replaced by _xxxx (ascii char code) and forced to
64 ###    start with a letter by prepending t_g if necessary)
65
66
67 package Texi2HTML::Config;
68
69 use utf8;
70 use Encode qw(decode);
71
72 #############################################################################
73 ### TRANSLATIONS
74 #############################################################################
75
76 my $LY_LANGUAGES = {};
77 $LY_LANGUAGES->{'fr'} = {
78     'Back to Documentation Index' => 'Retour à l\'accueil de la documentation',
79 };
80 $LY_LANGUAGES->{'es'} = {
81     'Back to Documentation Index' => 'Volver al índice de la documentación',
82 };
83 $LY_LANGUAGES->{'de'} = {
84     'Back to Documentation Index' => 'Zur Dokumentationsübersicht',
85 };
86 $LY_LANGUAGES->{'ja'} = {
87     'Back to Documentation Index' => 'ドキュメント インデックスに戻る',
88 };
89
90 $LY_LANGUAGES->{'hu'} = {
91     'Back to Documentation Index' => 'Vissza a dokumentációk jegyzékéhez',
92 };
93
94 # FIXME: send the translation below to texi2html/texinfo devs
95 $LANGUAGES->{'hu'} = {
96                        '  The buttons in the navigation panels have the following meaning:' => '  A navigációs panelen levő gombok jelentése a következő:',
97                        '  where the @strong{ Example } assumes that the current position is at @strong{ Subsubsection One-Two-Three } of a document of the following structure:' => '  ahol a @strong{ Példa } feltételezi, hogy az aktuális pozíció az @strong{ 1-2-3 alalszakasz } egy olyan dokumentumban, melynek szerkezete a következő:',
98                        ' Up ' => ' Fel ',
99                        '(outside of any element)' => '(bármelyik elemen kívül)',
100                        '(outside of any node)' => '(bármelyik csomóponton kívül)',
101                        '@b{{quotation_arg}:} ' => '@b{{quotation_arg}:} ',
102                        '@cite{{book}}' => '@cite{{book}}',
103                        '@{No value for `{value}\'@}' => '@{Nincs értéke ennek: `{value}\'@}',
104                        'About' => 'Névjegy',
105                        'About (help)' => 'Névjegy (súgó)',
106                        'About This Document' => 'Erről a dokumentumról',
107                        'April' => 'április',
108                        'August' => 'augusztus',
109                        'Back' => 'Vissza',
110                        'Back section in previous file' => 'Előző fájl hátsó szakasza',
111                        'Beginning of this chapter or previous chapter' => 'Fejezet eleje vagy előző fejezet',
112                        'Button' => 'Gomb',
113                        'Contents' => 'Tartalom',
114                        'Cover (top) of document' => 'Dokumentum borítója',
115                        'Current' => 'Aktuális',
116                        'Current Position' => 'Aktuális pozíció',
117                        'Current section' => 'Aktuális szakasz',
118                        'December' => 'december',
119                        'FastBack' => 'Gyorsan vissza',
120                        'FastForward' => 'Gyorsan előre',
121                        'February' => 'február',
122                        'First' => 'Első',
123                        'First section in reading order' => 'Első szakasz az olvasási sorrendben',
124                        'Following' => 'Következő',
125                        'Following node' => 'Következő csomópont',
126                        'Footnotes' => 'Lábjegyzet',
127                        'Forward' => 'Előre',
128                        'Forward section in next file' => 'Következő fájl elülső szakasza',
129                        'From 1.2.3 go to' => '1.2.3-ból menj ide:',
130                        'Go to' => 'Menj ide:',
131                        'Index' => 'Tárgymutató',
132                        'Index Entry' => 'Tárgymutató-bejegyzés',
133                        'January' => 'január',
134                        'July' => 'július',
135                        'Jump to' => 'Ugorj ide:',
136                        'June' => 'június',
137                        'Last' => 'Utolsó',
138                        'Last section in reading order' => 'Utolsó szakasz az olvasási sorrendben',
139                        'March' => 'március',
140                        'May' => 'május',
141                        'Menu:' => 'Menü:',
142                        'Name' => 'Név',
143                        'Next' => 'Következő',
144                        'Next chapter' => 'Következő fejezet',
145                        'Next file' => 'Következő fájl',
146                        'Next node' => 'Következő csomópont',
147                        'Next section in reading order' => 'Következő szakasz az olvasási sorrendben',
148                        'Next section on same level' => 'Következő szakasz ugyanazon a szinten',
149                        'NextFile' => 'KövetkezőFájl',
150                        'Node following in node reading order' => 'Következő csomópont az olvasási sorrendben',
151                        'Node up' => 'Szülő csomópont',
152                        'NodeNext' => 'KövetkezőCsomópont',
153                        'NodePrev' => 'ElőzőCsomópont',
154                        'NodeUp' => 'SzülőCsomópont',
155                        'November' => 'november',
156                        'October' => 'október',
157                        'Overview' => 'Áttekintés',
158                        'Prev' => 'Előző',
159                        'PrevFile' => 'ElőzőFájl',
160                        'Previous' => 'Előző',
161                        'Previous file' => 'Előző fájl',
162                        'Previous node' => 'Előző csomópont',
163                        'Previous section in reading order' => 'Előző szakasz az olvasási sorrendben',
164                        'Previous section on same level' => 'Előző szakasz ugyanazon a szinten',
165                        'Section' => 'Szakasz',
166                        'Section One' => '1. szakasz',
167                        'See ' => 'Ld. ',
168                        'See @cite{{book}}' => 'Ld. @cite{{book}}',
169                        'See section `@asis{}`{section_name}\'@asis{}\' in @cite{{book}}' => 'Ld. ezt a szakaszt: `@asis{}`{section_name}\'@asis{}\' itt: @cite{{book}}',
170                        'See section `{section}\' in @cite{{book}}' => 'Ld. ezt a szakaszt: `{section}\' itt: @cite{{book}}',
171                        'See section {reference_name}' => 'Ld. ezt a szakaszt: {reference_name}',
172                        'See {node_file_href}' => 'Ld. {node_file_href}',
173                        'See {node_file_href} @cite{{book}}' => 'See {node_file_href} @cite{{book}}',
174                        'See {node_file_href} section `{section}\' in @cite{{book}}' => 'Ld. {node_file_href} ezt a szakaszt: `{section}\' itt: @cite{{book}}',
175                        'See {reference_name}' => 'Ld. {reference_name}',
176                        'See {ref}' => 'Ld. {ref}',
177                        'See {title_ref}' => 'Ld. {title_ref}',
178                        'September' => 'szeptember',
179                        'Short Table of Contents' => 'Rövid tartalomjegyzék',
180                        'Short table of contents' => 'Rövid tartalomjegyzék',
181                        'Subsection One-Four' => '1-4 alszakasz',
182                        'Subsection One-One' => '1-1 alszakasz',
183                        'Subsection One-Three' => '1-3 alszakasz',
184                        'Subsection One-Two' => '1-2 alszakasz',
185                        'Subsubsection One-Two-Four' => '1-2-4 alalszakasz',
186                        'Subsubsection One-Two-One' => '1-2-1 alalszakasz',
187                        'Subsubsection One-Two-Three' => '1-2-3 alalszakasz',
188                        'Subsubsection One-Two-Two' => '1-2-2 alalszakasz',
189                        'T2H_today' => '%s, %d %d',
190                        'Table of Contents' => 'Tartalomjegyzék',
191                        'Table of contents' => 'Tartalomjegyzék',
192                        'The node you are looking for is at {href}.' => 'A keresett csomópont itt található: {href}.',
193                        'This' => 'Ez a(z)',
194                        'This document was generated on @i{{date}} using @uref{{program_homepage}, @i{{program}}}.' => 'Ezt a dokumentumot @i{{date}} napon generálta a(z) @uref{{program_homepage}, @i{{program}}}.',
195                        'This document was generated using @uref{{program_homepage}, @emph{{program}}}.' => 'Ezt a dokumentumot a(z) @uref{{program_homepage}, @emph{{program}}} generálta.',
196                        'Top' => 'Tetejére',
197                        'Untitled Document' => 'Névtelen dokumentum',
198                        'Up' => 'Fel',
199                        'Up node' => 'Szülő csomópont',
200                        'Up section' => 'Szülő szakasz',
201                        'current' => 'aktuális',
202                        'on @emph{{date}}' => 'ekkor: @emph{{date}}',
203                        'section `@asis{}`{section_name}\'@asis{}\' in @cite{{book}}' => 'szakasz: `@asis{}`{section_name}\'@asis{}\' itt: @cite{{book}}',
204                        'section `{section}\' in @cite{{book}}' => 'szakasz: `{section}\' itt: @cite{{book}}',
205                        'see ' => 'ld. ',
206                        'see @cite{{book}}' => 'ld. @cite{{book}}',
207                        'see section `@asis{}`{section_name}\'@asis{}\' in @cite{{book}}' => 'ld. ezt a szakaszt: `@asis{}`{section_name}\'@asis{}\' itt: @cite{{book}}',
208                        'see section `{section}\' in @cite{{book}}' => 'ld. ezt a szakaszt: `{section}\' itt: @cite{{book}}',
209                        'see section {reference_name}' => 'ld. ezt a szakaszt: {reference_name}',
210                        'see {node_file_href}' => 'ld. {node_file_href}',
211                        'see {node_file_href} @cite{{book}}' => 'ld. {node_file_href} @cite{{book}}',
212                        'see {node_file_href} section `{section}\' in @cite{{book}}' => 'ld. {node_file_href} ezt a szakaszt: `{section}\' itt: @cite{{book}}',
213                        'see {reference_name}' => 'ld. {reference_name}',
214                        'see {ref}' => 'ld. {ref}',
215                        'see {title_ref}' => 'ld. {title_ref}',
216                        '{acronym_like} ({explanation})' => '{acronym_like} ({explanation})',
217                        '{name} of {class}' => '{name} típusa: {class}',
218                        '{name} on {class}' => '{name} ezen: {class}',
219                        '{node_file_href}' => '{node_file_href}',
220                        '{node_file_href} @cite{{book}}' => '{node_file_href} @cite{{book}}',
221                        '{node_file_href} section `{section}\' in @cite{{book}}' => '{node_file_href} szakasz: `{section}\' itt: @cite{{book}}',
222                        '{reference_name}' => '{reference_name}',
223                        '{ref}' => '{ref}',
224                        '{style} {number}' => '{style} {number}',
225                        '{style}: {caption_first_line}' => '{style}: {caption_first_line}',
226                        '{style}: {shortcaption_first_line}' => '{style}: {shortcaption_first_line}',
227                        '{title_ref}' => '{title_ref}'
228                      };
229
230 sub ly_get_string () {
231     my $lang = $Texi2HTML::THISDOC{current_lang};
232     my $string = shift;
233     if ($lang and $lang ne "en" and $LY_LANGUAGES->{$lang}->{$string}) {
234         return $LY_LANGUAGES->{$lang}->{$string};
235     } else {
236         return $string;
237     }
238 }
239
240
241 #############################################################################
242 ### FUNCTIONALITY FOR MAIN WEB PAGES
243 #############################################################################
244
245 my $web_manual = 0;
246 sub lilypond_init_web_manual ()
247 {
248   if (exists($main::value{'web_manual'}))
249   {
250       print STDERR "Initializing settings for web site\n";
251     $web_manual = 1;
252     web_settings();
253   }
254 }
255 push @Texi2HTML::Config::command_handler_process, \&lilypond_init_web_manual;
256
257 #############################################################################
258 ###  SETTINGS FOR TEXI2HTML
259 #############################################################################
260
261 # Validation fix for texi2html<=1.82
262 $Texi2HTML::Config::DOCTYPE = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
263
264 sub web_settings() {
265   if ($web_manual) {
266     @Texi2HTML::Config::CSS_REFS      = (
267       {FILENAME => "lilypond-web.css", TITLE => "Default style"}
268     );
269   } else {
270     @Texi2HTML::Config::CSS_REFS      = (
271       {FILENAME => "lilypond-mccarty.css", TITLE => "Patrick McCarty's design"}
272     );
273   }
274 }
275 @Texi2HTML::Config::ALT_CSS_REFS      = (
276     {FILENAME => "lilypond.css", TITLE => "Andrew Hawryluk's design" },
277     {FILENAME => "lilypond-blue.css", TITLE => "Kurt Kroon's blue design" },
278 );
279 $Texi2HTML::Config::USE_ACCESSKEY = 1;
280 $Texi2HTML::Config::USE_LINKS     = 1;
281 $Texi2HTML::Config::USE_REL_REV   = 1;
282 $Texi2HTML::Config::SPLIT_INDEX   = 0;
283 $Texi2HTML::Config::SEPARATED_FOOTNOTES = 0; # Print footnotes on same page, not separated
284
285 if ($Texi2HTML::Config::SPLIT eq 'section' or
286     $Texi2HTML::Config::SPLIT eq 'subsubsection') {
287   $Texi2HTML::Config::element_file_name    = \&lilypond_element_file_name;
288 }
289
290 $Texi2HTML::Config::element_target_name  = \&lilypond_element_target_name;
291 $default_print_element_header = $Texi2HTML::Config::print_element_header;
292 $Texi2HTML::Config::print_element_header = \&lilypond_print_element_header;
293 $Texi2HTML::Config::print_page_foot      = \&print_lilypond_page_foot;
294 $Texi2HTML::Config::print_navigation     = \&lilypond_print_navigation;
295 $Texi2HTML::Config::external_ref         = \&lilypond_external_ref;
296 $default_external_href = $Texi2HTML::Config::external_href;
297 $Texi2HTML::Config::external_href        = \&lilypond_external_href;
298 $default_toc_body = $Texi2HTML::Config::toc_body;
299 $Texi2HTML::Config::toc_body             = \&lilypond_toc_body;
300 $Texi2HTML::Config::css_lines            = \&lilypond_css_lines;
301 $default_unknown = $Texi2HTML::Config::unknown;
302 $Texi2HTML::Config::unknown              = \&lilypond_unknown;
303 $default_print_page_head = $Texi2HTML::Config::print_page_head;
304 $Texi2HTML::Config::print_page_head      = \&lilypond_print_page_head;
305 # $Texi2HTML::Config::foot_line_and_ref    = \&lilypond_foot_line_and_ref;
306 $Texi2HTML::Config::foot_line_and_ref  = \&makeinfo_like_foot_line_and_ref;
307 $Texi2HTML::Config::foot_lines         = \&makeinfo_like_foot_lines;
308 $Texi2HTML::Config::paragraph          = \&makeinfo_like_paragraph;
309
310
311
312 # Examples should be formatted similar to quotes:
313 $Texi2HTML::Config::complex_format_map->{'example'} = {
314   'begin' => q{"<blockquote>"},
315   'end' => q{"</blockquote>\n"},
316   'style' => 'code',
317  };
318
319 %Texi2HTML::config::misc_pages_targets = (
320    'Overview' => 'Overview',
321    'Contents' => 'Contents',
322    'About' => 'About'
323 );
324
325
326 my @section_to_filename;
327
328
329
330
331 #############################################################################
332 ###  DEBUGGING
333 #############################################################################
334
335 use Data::Dumper;
336 $Data::Dumper::Maxdepth = 2;
337
338 sub print_element_info($)
339 {
340   my $element = shift;
341   print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
342   print "Element: $element\n";
343   print Dumper($element);
344 }
345
346
347
348
349
350 #############################################################################
351 ###  HELPER FUNCTIONS
352 #############################################################################
353
354 # Convert a given node name to its proper file name (normalization as explained
355 # in the texinfo manual:
356 # http://www.gnu.org/software/texinfo/manual/texinfo/html_node/HTML-Xref-Node-Name-Expansion.html
357 sub texinfo_file_name($)
358 {
359   my $text = shift;
360   my $result = '';
361   # File name normalization by texinfo:
362   # 1/2: letters and numbers are left unchanged
363   # 3/4: multiple, leading and trailing whitespace is removed
364   $text = main::normalise_space($text);
365   # 5/6: all remaining spaces are converted to '-', all other 7- or 8-bit
366   #      chars are replaced by _xxxx (xxxx=ascii character code)
367   while ($text ne '') {
368     if ($text =~ s/^([A-Za-z0-9]+)//o) { # number or letter stay unchanged
369       $result .= $1;
370     } elsif ($text =~ s/^ //o) { # space -> '-'
371       $result .= '-';
372     } elsif ($text =~ s/^(.)//o) { # Otherwise use _xxxx (ascii char code)
373       my $ccode = ord($1);
374       if ( $ccode <= 0xFFFF ) {
375         $result .= sprintf("_%04x", $ccode);
376       } else {
377         $result .= sprintf("__%06x", $ccode);
378       }
379     }
380   }
381   # 7: if name does not begin with a letter, prepend 't_g' (so it starts with a letter)
382   if ($result !~ /^[a-zA-Z]/) {
383     $result = 't_g' . $result;
384   }
385   # DONE
386   return lc($result)
387 }
388
389 # Load a file containing a nodename<=>filename map (tab-sepatared, i.e.
390 # NODENAME\tFILENAME\tANCHOR
391 # Returns a ref to a hash "Node title" => ["FilenameWithoutExt", "Anchor"]
392 sub load_map_file ($)
393 {
394     my $mapfile = shift;
395     my $node_map = ();
396
397     # For some unknown reason, Perl on my system (5.10.0 on Fedora 12)
398     # refuses to open map files of translated documents with
399     # '<:encoding(utf8)', but decoding from UTF-8 line by line works. -jm
400     if (open(XREFFILE,'<', $mapfile)) {
401         my $line;
402         while ( $line = decode ('UTF-8', <XREFFILE>) ) {
403             # parse the tab-separated entries and insert them into the map:
404             chomp($line);
405             my @entries = split(/\t/, $line);
406             if (scalar (@entries) == 3) {
407               $node_map->{$entries[0]} = [$entries[1], $entries[2]];
408             } else {
409               print STDERR "Invalid entry in the node file $mapfile: $line\n";
410             }
411         }
412         # print STDERR %{$node_map};
413         close (XREFFILE);
414     } else {
415         print STDERR "WARNING: Unable to load the map file $mapfile\n";
416     }
417     return $node_map;
418 }
419
420
421 # Split the given path into dir and basename (with .texi removed). Used mainly
422 # to get the path/basename of the original texi input file
423 sub split_texi_filename ($)
424 {
425   my $docu = shift;
426   my ($docu_dir, $docu_name);
427   if ($docu =~ /(.*\/)/) {
428     chop($docu_dir = $1);
429     $docu_name = $docu;
430     $docu_name =~ s/.*\///;
431   } else {
432      $docu_dir = '.';
433      $docu_name = $docu;
434   }
435   $docu_name =~ s/\.te?x(i|info)?$//;
436   return ($docu_dir, $docu_name);
437 }
438
439
440
441
442
443 #############################################################################
444 ###  CSS HANDLING
445 #############################################################################
446
447 # Include our standard CSS file, not hard-coded CSS code directly in the HTML!
448 # For IE, conditionally include the lilypond-ie-fixes.css style sheet
449 sub lilypond_css_lines ($$)
450 {
451     my $import_lines = shift;
452     my $rule_lines = shift;
453     return if (defined($Texi2HTML::THISDOC{'CSS_LINES'}));
454     if (@$rule_lines or @$import_lines)
455     {
456         $Texi2HTML::THISDOC{'CSS_LINES'} = "<style type=\"text/css\">\n<!--\n";
457         $Texi2HTML::THISDOC{'CSS_LINES'} .= join('',@$import_lines) . "\n" if (@$import_lines);
458         $Texi2HTML::THISDOC{'CSS_LINES'} .= join('',@$rule_lines) . "\n" if (@$rule_lines);
459         $Texi2HTML::THISDOC{'CSS_LINES'} .= "-->\n</style>\n";
460     }
461     foreach my $ref (@CSS_REFS)
462     {
463         $Texi2HTML::THISDOC{'CSS_LINES'} .= "<link rel=\"stylesheet\" type=\"text/css\" title=\"$ref->{TITLE}\" href=\"$ref->{FILENAME}\">\n";
464     }
465     foreach my $ref (@Texi2HTML::Config::ALT_CSS_REFS)
466     {
467         $Texi2HTML::THISDOC{'CSS_LINES'} .= "<link rel=\"alternate stylesheet\" type=\"text/css\" href=\"$ref->{FILENAME}\" title=\"$ref->{TITLE}\">\n";
468     }
469     # FIXME: the website doesn't use ie7-specific fixes; do the
470     # docs still need this?  -gp
471     $Texi2HTML::THISDOC{'CSS_LINES'} .= "<!--[if lte IE 7]>\n<link href=\"lilypond-ie-fixes.css\" rel=\"stylesheet\" type=\"text/css\">\n<![endif]-->\n";
472 }
473
474
475
476
477
478 #############################################################################
479 ###  SPLITTING BASED ON NUMBERED SECTIONS
480 #############################################################################
481
482 my $lastfilename;
483 my $docnr = 0;
484 my $node_to_filename_map = ();
485
486
487 # This function makes sure that files are only generated for numbered sections,
488 # but not for unnumbered ones. It is called after texi2html has done its own
489 # splitting and simply returns the filename for the node given as first argument
490 # Nodes with the same filename will be printed out to the same filename, so
491 # this really all we need. Also, make sure that the file names for sections
492 # are derived from the section title. We also might want to name the anchors
493 # according to node titles, which works by simply overriding the id element of
494 # the $element hash.
495 # If an external nodename<=>filename/anchor map file is found (loaded in
496 # the command handler, use the externally created values, otherwise use the
497 # same logic here.
498 sub lilypond_element_file_name($$$)
499 {
500   my $element = shift;
501   my $type = shift;
502   my $docu_name = shift;
503   my $docu_ext = $Texi2HTML::Config::EXTENSION;
504
505   my $node_name = main::remove_texi($element->{'node_ref'}->{'texi'});
506   # the snippets page does not use nodes for the snippets, so in this case
507   # we'll have to use the section name!
508   if ($node_name eq '') {
509     $node_name = main::remove_texi($element->{'texi'});
510   }
511
512   # If we have an entry in the section<=>filename map, use that one, otherwise
513   # generate the filename/anchor here. In the latter case, external manuals
514   # will not be able to retrieve the file name for xrefs!!! Still, I already
515   # had that code, so I'll leave it in in case something goes wrong with the
516   # extract_texi_filenames.py script in the lilypond build process!
517   if (exists ($node_to_filename_map->{$node_name})) {
518     (my $filename, my $anchor) = @{$node_to_filename_map->{$node_name}};
519     $filename .= ".$docu_ext" if (defined($docu_ext));
520
521     # unnumbered sections (except those at top-level!) always go to the same
522     # file as the previous numbered section
523     if (not ($element->{number}) and not ($lastfilename eq '') and ($element->{level} > 1)) {
524       $filename = $lastfilename;
525     }
526     if (($filename eq $lastfilename)) {
527       $$element{doc_nr} = $docnr;
528     } else {
529       $docnr += 1;
530       $$element{doc_nr} = $docnr;
531       $lastfilename = $filename;
532     }
533     # print STDERR "File name: $filename\n";
534     return lc($filename);
535
536   } elsif ($type eq "top" or $type eq "toc" or $type eq "doc" or $type eq "stoc" or $type eq "foot" or $type eq "about") {
537     return;
538   } else {
539     print STDERR "WARNING: Node '$node_name' was NOT found in the map\n"
540         unless ($node_name eq '') or ($element->{'tag'} eq 'unnumberedsec')
541                or ($node_name =~ /NOT REALLY USED/);
542
543     # Numbered sections will get a filename Node_title, unnumbered sections will use
544     # the file name of the previous numbered section:
545     if (($element->{number}) or ($lastfilename eq '') or ($element->{level} == 1)) {
546       # normalize to the same file name as texinfo
547       if ($element->{translationof}) {
548         $node_name = main::remove_texi($element->{translationof});
549       }
550       my $filename = texinfo_file_name($node_name);
551       $filename .= ".$docu_ext" if (defined($docu_ext));
552       $docnr += 1;
553       $$element{doc_nr} = $docnr;
554       $lastfilename = $filename;
555       print STDERR "File name: $filename\n";
556       return lc($filename);
557     } else {
558       $$element{doc_nr} = $docnr;
559       print STDERR "File name: $filename\n";
560       return lc($filename);
561     }
562   }
563
564   return;
565 }
566
567 sub lilypond_element_target_name($$$)
568 {
569   my $element = shift;
570   my $target = shift;
571   my $id = shift;
572   # Target is based on node name (or sec name for secs without node attached)
573   my $node_name = main::remove_texi($element->{'node_ref'}->{'texi'});
574   if ($node_name eq '') {
575     $node_name = main::remove_texi($element->{'texi'});
576   }
577
578   # If we have an entry in the section<=>filename map, use that one, otherwise
579   # generate the anchor here.
580   if (exists ($node_to_filename_map->{$node_name})) {
581     (my $filename, $target) = @{$node_to_filename_map->{$node_name}};
582   } else {
583     my $anchor = $node_name;
584     if ($element->{translationof}) {
585       $anchor = main::remove_texi($element->{translationof});
586     }
587     # normalize to the same file name as texinfo
588     $target = texinfo_file_name($anchor);
589   }
590   # TODO: Once texi2html correctly prints out the target and not the id for
591   #       the sections, change this back to ($id, $target)
592   $target = lc($target);
593   return ($target, $target);
594 }
595
596
597 ## Load the map file for the corrently processed texi file. We do this
598 #  using a command init handler, since texi2html does not have any
599 #  other hooks that are called after THISDOC is filled but before phase 2
600 #  of the texi2html conversion.
601 sub lilypond_init_map ()
602 {
603     my ($docu_dir, $docu_name) = split_texi_filename ($Texi2HTML::THISDOC{'input_file_name'});
604     my $map_filename = main::locate_include_file ("${docu_name}.$Texi2HTML::THISDOC{current_lang}.xref-map")
605         || main::locate_include_file ("${docu_name}.xref-map");
606     print STDERR "Map filename is: $map_filename\nDocu name is $docu_name\n";
607     $node_to_filename_map = load_map_file ($map_filename);
608 }
609 push @Texi2HTML::Config::command_handler_init, \&lilypond_init_map;
610
611
612
613 #############################################################################
614 ###  CLEANER LINK TITLE FOR EXTERNAL REFS
615 #############################################################################
616
617 # The default formatting of external refs returns e.g.
618 # "(lilypond-internals)Timing_translator", so we remove all (...) from the
619 # file_and_node argument. Also, we want only a very simple format, so we don't
620 # even call the default handler!
621 sub lilypond_external_ref($$$$$$)
622 {
623   my $type = shift;
624   my $section = shift;
625   my $book = shift;
626   my $file_node = shift;
627   my $href = lc(shift);
628   my $cross_ref = shift;
629
630   my $displaytext = '';
631
632   # 1) if we have a cross ref name, that's the text to be displayed:
633   # 2) For the top node, use the (printable) name of the manual, unless we
634   #    have an explicit cross ref name
635   # 3) In all other cases use the section name
636   if ($cross_ref ne '') {
637     $displaytext = $cross_ref;
638   } elsif (($section eq '') or ($section eq 'Top')) {
639     $displaytext = $book;
640   } else {
641     $displaytext = $section;
642   }
643
644   $displaytext = &$anchor('', $href, $displaytext) if ($displaytext ne '');
645   return &$I('%{node_file_href}', { 'node_file_href' => $displaytext });
646 }
647
648
649
650
651
652 #############################################################################
653 ###  HANDLING TRANSLATED SECTIONS: handle @translationof, secname<->filename
654 ###                  map stored on disk, xrefs in other manuals load that map
655 #############################################################################
656
657
658 # Try to make use of @translationof to generate files according to the original
659 # English section title...
660 sub lilypond_unknown($$$$$)
661 {
662     my $macro = shift;
663     my $line = shift;
664     my $pass = shift;
665     my $stack = shift;
666     my $state = shift;
667
668     # the @translationof macro provides the original English section title,
669     # which should be used for file/anchor naming, while the title will be
670     # translated to each language
671     # It is already used by extract_texi_filenames.py, so this should not be
672     # necessary here at all. Still, I'll leave the code in just in case the
673     # python script messed up ;-)
674     if ($pass == 1 and $macro eq "translationof") {
675       if (ref($state->{'element'}) eq 'HASH') {
676         $state->{'element'}->{'translationof'} = main::normalise_space($line);
677       }
678       return ('', 1, undef, undef);
679     } else {
680       return &$default_unknown($macro, $line, $pass, $stack, $state);
681     }
682 }
683
684
685
686
687 my %translated_books = ();
688 # Construct a href to an external source of information.
689 # node is the node with texinfo @-commands
690 # node_id is the node transliterated and transformed as explained in the
691 #         texinfo manual
692 # node_xhtml_id is the node transformed such that it is unique and can
693 #     be used to make an html cross ref as explained in the texinfo manual
694 # file is the file in '(file)node'
695 sub lilypond_external_href($$$)
696 {
697   my $node = shift;
698   my $node_id = shift;
699   my $node_hxmlt_id = shift;
700   my $file = shift;
701
702   # 1) Keep a hash of book->section_map
703   # 2) if not file in keys hash => try to load the map (assign empty map if
704   #    non-existent => will load only once!)
705   # 3) if node in the section=>(file, anchor) map, replace node_id and
706   #    node_xhtml_id by the map's values
707   # 4) call the default_external_href with these values (or the old ones if not found)
708
709   if (($node_id ne '') and defined($file) and ($node_id ne 'Top')) {
710     my $map_name = $file;
711     $map_name =~ s/-big-page//;
712
713     # Load the map if we haven't done so already
714     if (!exists($translated_books{$map_name})) {
715       my ($docu_dir, $docu_name) = split_texi_filename ($Texi2HTML::THISDOC{'input_file_name'});
716       my $map_filename = main::locate_include_file ("${map_name}.$Texi2HTML::THISDOC{current_lang}.xref-map")
717           || main::locate_include_file ("${map_name}.xref-map");
718       $translated_books{$map_name} = load_map_file ($map_filename);
719     }
720
721     # look up translation. use these values instead of the old filename/anchor
722     my $section_name_map = $translated_books{$map_name};
723     my $node_text = main::remove_texi($node);
724     if (defined($section_name_map->{$node_text})) {
725       ($node_id, $node_hxmlt_id) = @{$section_name_map->{$node_text}};
726     } else {
727       print STDERR "WARNING: Unable to find node '$node_text' in book $map_name.\n";
728     }
729   }
730
731   if (defined $file) {
732     return &$default_external_href($node, $node_id, $node_hxmlt_id, lc($file));
733   } else {
734     return &$default_external_href($node, $node_id, $node_hxmlt_id);
735   }
736 }
737
738
739
740
741
742 #############################################################################
743 ###  CUSTOM TOC FOR EACH PAGE (in a frame on the left)
744 #############################################################################
745
746 my $page_toc_depth = 2;
747 my @default_toc = [];
748
749 # Initialize the toc_depth to 1 if the command-line option -D=short_toc is given
750 sub lilypond_init_toc_depth ()
751 {
752   if (exists($main::value{'short_toc'}) and not exists($main::value{'bigpage'})) {
753     $page_toc_depth = 1;
754   }
755 }
756 # Set the TOC-depth (depending on a texinfo variable short_toc) in a 
757 # command-handler, so we have them available when creating the pages
758 push @Texi2HTML::Config::command_handler_process, \&lilypond_init_toc_depth;
759
760
761 # recursively generate the TOC entries for the element and its children (which
762 # are only shown up to maxlevel. All ancestors of the current element are also
763 # shown with their immediate children, irrespective of their level.
764 # Unnumbered entries are only printed out if they are at top-level or 2nd level 
765 # or their parent element is an ancestor of the currently viewed node.
766 # The conditions to call this method to print the entry for a child node is:
767 # -) the parent is an ancestor of the current page node
768 # -) the parent is a numbered element at top-level toplevel (i.e. show numbered 
769 #    and unnumbered 2nd-level children of numbered nodes)
770 # -) the child element is a numbered node below level maxlevel
771 sub generate_ly_toc_entries($$$)
772 {
773   my $element = shift;
774   my $element_path = shift;
775   if ($web_manual) {
776     my $maxlevel = 1;
777   } else {
778     my $maxlevel = shift;
779   }
780   # Skip undefined sections, plus all sections generated by index splitting
781   return() if (not defined($element) or exists($element->{'index_page'}));
782   my @result = ();
783   my $level = $element->{'toc_level'};
784   my $is_parent_of_current = $element->{'id'} && $element_path->{$element->{'id'}};
785   my $ind = '  ' x $level;
786   my $this_css_class;
787   if ($web_manual) {
788     $this_css_class = " class=\"";
789   } else {
790     $this_css_class = "";
791   }
792   $this_css_class .= $is_parent_of_current ? " toc_current" : "";
793 # HORRIBLE HACK
794   my @color_1 = (
795         "Learning", "Glossary", "Essay",
796         "Contact", "Tiny examples", "Bug reports"
797         );
798   my @color_2 = (
799         "Features", "Examples", "Freedom", "Background",
800         "Unix", "MacOS X", "Windows",
801         "Notation", "Usage", "Snippets",
802         "Help us", "Development", "Authors"
803         );
804   my @color_3 = (
805         "Productions", "Testimonials",
806         "Source", "Old downloads",
807         "FAQ", "Changes", "Extend", "Internals",
808         "Publications", "Old news"
809         );
810   my @color_4 = (
811         "Text input", "Alternate input",
812         "GPL",
813         "Translated", "All", "FDL"
814         );
815
816   my $addColor = " colorDefault";
817   foreach $color (@color_1) {
818     if ($element->{'text'} eq $color) {
819       $addColor = " color1";
820     }
821   }
822   foreach $color (@color_2) {
823     if ($element->{'text'} eq $color) {
824       $addColor = " color2";
825     }
826   }
827   foreach $color (@color_3) {
828     if ($element->{'text'} eq $color) {
829       $addColor = " color3";
830     }
831   }
832   foreach $color (@color_4) {
833     if ($element->{'text'} eq $color) {
834       $addColor = " color4";
835     }
836   }
837
838   $this_css_class .= $addColor . "\"";
839
840
841   my $entry = "$ind<li$this_css_class>" . &$anchor ($element->{'tocid'}, "$element->{'file'}#$element->{'target'}",$element->{'text'});
842
843   push (@result, $entry);
844   my $children = $element->{'section_childs'};
845   if (defined($children) and (ref($children) eq "ARRAY")) {
846     my $force_children = $is_parent_of_current or ($level == 1 and $element->{'number'});
847     my @child_result = ();
848     foreach my $c (@$children) {
849       my $is_numbered_child = defined ($c->{'number'});
850       my $below_maxlevel = $c->{'toc_level'} le $maxlevel;
851       if ($force_children or ($is_numbered_child and $below_maxlevel)) {
852         my @child_res = generate_ly_toc_entries($c, $element_path, $maxlevel);
853         push (@child_result, @child_res);
854       }
855     }
856     # if no child nodes were generated, e.g. for the index, where expanded pages
857     # are ignored, don't generate a list at all...
858     if (@child_result) {
859       push (@result, "\n$ind<ul$NO_BULLET_LIST_ATTRIBUTE>\n");
860       if ($web_manual) {
861         push (@result, "$ind<li$this_css_class>" . &$anchor ($element->{'tocid'}, "$element->{'file'}#$element->{'target'}","(main)"));
862       } else {
863         push (@result, @child_result);
864       }
865       push (@result, "$ind</ul>\n");
866     }
867   }
868   push (@result, "$ind</li>\n");
869   return @result;
870 }
871
872
873 # Print a customized TOC, containing only the first two levels plus the whole
874 # path to the current page
875 sub lilypond_generate_page_toc_body($)
876 {
877     my $element = shift;
878     my $current_element = $element;
879     my %parentelements;
880     $parentelements{$element->{'id'}} = 1;
881     # Find the path to the current element
882     while ( defined($current_element->{'sectionup'}) and
883            ($current_element->{'sectionup'} ne $current_element) )
884     {
885       $parentelements{$current_element->{'sectionup'}->{'id'}} = 1
886               if ($current_element->{'sectionup'}->{'id'} ne '');
887       $current_element = $current_element->{'sectionup'};
888       if ($web_manual) {
889         if (exists($main::value{'shallow_toc'})) {
890           last;
891         }
892       }
893     }
894     return () if not defined($current_element);
895     # Create the toc entries recursively
896     my @toc_entries = "";
897     if ($web_manual) {
898         push (@toc_entries, "<ul$NO_BULLET_LIST_ATTRIBUTE>\n");
899         # FIXME: add link to main page, really hackily.
900         if ($element->{'sectionup'}) {
901             # it's not the top element
902             push (@toc_entries, "<li><a href=\"index.html\">Main</a></li>\n");
903         } else {
904             push (@toc_entries, "<li class=\"toc_current\"><a href=\"index.html\">Main</a></li>\n");
905         }
906     } else {
907         push (@toc_entries, "<div class=\"contents\">\n");
908         push (@toc_entries, "<ul$NO_BULLET_LIST_ATTRIBUTE>\n");
909     }
910     my $children = $current_element->{'section_childs'};
911     foreach ( @$children ) {
912       push (@toc_entries, generate_ly_toc_entries($_, \%parentelements, $page_toc_depth));
913     }
914     # search box
915     if ($web_manual) {
916         # WTF, perl needs 6 lines of magic to do: ' ' + open ('file-name').read ()?
917         local $/=undef;
918         my $name = "search-box.html";
919         open FILE, "$ENV{SRC_DIR}/$name" or open FILE, "$ENV{SRC_DIR}/../$name" or die  die "no such file: $name: $!";
920
921         my $string = <FILE>;
922         $string =  "<li>\n" . $string . "</li>\n";
923         push (@toc_entries, $string);
924         close FILE;
925     }
926     push (@toc_entries, "</ul>\n");
927     push (@toc_entries, "</div>\n");
928     return @toc_entries;
929 }
930
931 sub lilypond_print_toc_div ($$)
932 {
933   my $fh = shift;
934   my $tocref = shift;
935   my @lines = @$tocref;
936   # use default TOC if no custom lines have been generated
937   @lines = @default_toc if (not @lines);
938   if (@lines) {
939   
940     print $fh "\n\n<div id=\"tocframe\">\n";
941     
942     # Remove the leading "GNU LilyPond --- " from the manual title
943     my $topname = $Texi2HTML::NAME{'Top'};
944     $topname =~ s/^GNU LilyPond(:| &[mn]dash;) //;
945     
946     # construct the top-level Docs index (relative path and including language!)
947     my $lang = $Texi2HTML::THISDOC{current_lang};
948     if ($lang and $lang ne "en") {
949       $lang .= ".";
950     } else {
951       $lang = "";
952     }
953     my $reldir = "";
954     $reldir = "../" if ($Texi2HTML::Config::SPLIT eq 'section');
955     my $uplink = $reldir."web/manuals.${lang}html";
956
957     if ($web_manual) {
958     } else {
959       print $fh "<p class=\"toc_uplink\"><a href=\"$uplink\" 
960          title=\"Documentation Index\">&lt;&lt; " .
961          &ly_get_string ('Back to Documentation Index') .
962          "</a></p>\n";
963
964       print $fh '<h4 class="toc_header"> ' . &$anchor('',
965                                     $Texi2HTML::HREF{'Top'},
966                                     $topname,
967                                     'title="Start of the manual"'
968                                    ) . "</h4>\n";
969     }
970
971     foreach my $line (@lines) {
972       print $fh $line;
973     }
974     print $fh "</div>\n\n";
975   }
976 }
977
978 # Create the custom TOC for this page (partially folded, current page is
979 # highlighted) and store it in a global variable. The TOC is written out after
980 # the html contents (but positioned correctly using CSS), so that browsers with
981 # css turned off still show the contents first.
982 our @this_page_toc = ();
983 sub lilypond_print_element_header
984 {
985   my $first_in_page = shift;
986   my $previous_is_top = shift;
987   if ($first_in_page and not @this_page_toc) {
988     if (defined($Texi2HTML::THIS_ELEMENT)) {
989       # Create the TOC for this page
990       @this_page_toc = lilypond_generate_page_toc_body($Texi2HTML::THIS_ELEMENT);
991     }
992   }
993   return &$default_print_element_header( $first_in_page, $previous_is_top);
994 }
995
996 # Generate the HTML output for the TOC
997 sub lilypond_toc_body($)
998 {
999     my $elements_list = shift;
1000     # Generate a default TOC for pages without THIS_ELEMENT
1001     @default_toc = lilypond_generate_page_toc_body(@$elements_list[0]);
1002     return &$default_toc_body($elements_list);
1003 }
1004
1005 # Print out the TOC in a <div> at the beginning of the page
1006 sub lilypond_print_page_head($)
1007 {
1008     my $fh = shift;
1009     &$default_print_page_head($fh);
1010     print $fh "<div id=\"main\">\n";
1011 }
1012
1013 # Print out the TOC in a <div> at the end of th page, which will be formatted as a
1014 # sidebar mimicking a TOC frame
1015 sub print_lilypond_page_foot($)
1016 {
1017   my $fh = shift;
1018   my $program_string = &$program_string();
1019 #   print $fh "<p><font size='-1'>$program_string</font><br>$PRE_BODY_CLOSE</p>\n";
1020   print $fh "<!-- FOOTER -->\n\n";
1021   print $fh "<!-- end div#main here -->\n</div>\n\n";
1022
1023   if ($web_manual) {
1024     # FIXME: This div and p#languages need to be in div#footer.
1025     #        Should we move this div to postprocess_html.py ?
1026     print $fh "<div id=\"verifier_texinfo\">\n";
1027     print $fh "<h3>Validation</h3>\n";
1028     print $fh "<p>Thanks to <a href=\"http://www.webdev.nl/\">webdev.nl</a>";
1029     print $fh " for hosting <code>lilypond.org</code>.\n";
1030     print $fh "<a href=\"http://validator.w3.org/check?uri=referer\">\n";
1031     print $fh "<img src=\"http://www.w3.org/Icons/valid-html401\"\n";
1032     print $fh "     alt=\"Valid HTML 4.01 Transitional\"\n";
1033     print $fh "     height=\"31\" width=\"88\"></a></p>\n";
1034     print $fh "</div>";
1035   }
1036
1037   # Print the TOC frame and reset the TOC:
1038   lilypond_print_toc_div ($fh, \@this_page_toc);
1039   @this_page_toc = ();
1040
1041   # Close the page:
1042   print $fh "</body>\n</html>\n";
1043 }
1044
1045
1046
1047
1048
1049 #############################################################################
1050 ###  NICER / MORE FLEXIBLE NAVIGATION PANELS
1051 #############################################################################
1052
1053 sub get_navigation_text
1054 {
1055   my $button = shift;
1056   my $text = $NAVIGATION_TEXT{$button};
1057   if ( ($button eq 'Back') or ($button eq 'FastBack') ) {
1058     $text = $text . $Texi2HTML::NODE{$button} . "&nbsp;";
1059   } elsif ( ($button eq 'Forward') or ($button eq 'FastForward') ) {
1060     $text = "&nbsp;" . $Texi2HTML::NODE{$button} . $text;
1061   } elsif ( $button eq 'Up' ) {
1062     $text = "&nbsp;".$text.":&nbsp;" . $Texi2HTML::NODE{$button} . "&nbsp;";
1063   }
1064   return $text;
1065 }
1066
1067
1068 # Don't automatically create left-aligned table cells for every link, but
1069 # instead create a <td> only on an appropriate '(left|right|center)-aligned-cell-n'
1070 # button text. It's alignment as well as the colspan will be taken from the
1071 # name of the button. Also, add 'newline' button text to create a new table
1072 # row. The texts of the buttons are generated by get_navigation_text and
1073 # will contain the name of the next/previous section/chapter.
1074 sub lilypond_print_navigation
1075 {
1076     my $buttons = shift;
1077     my $vertical = shift;
1078     my $spacing = 1;
1079     my $result = "<table class=\"nav_table\">\n";
1080
1081     $result .= "<tr>" unless $vertical;
1082     my $beginofline = 1;
1083     foreach my $button (@$buttons)
1084     {
1085         $result .= qq{<tr valign="top" align="left">\n} if $vertical;
1086         # Allow (left|right|center)-aligned-cell and newline as buttons!
1087         if ( $button =~ /^(.*)-aligned-cell-(.*)$/ )
1088         {
1089           $result .= qq{</td>} unless $beginofline;
1090           $result .= qq{<td valign="middle" align="$1" colspan="$2">};
1091           $beginofline = 0;
1092         }
1093         elsif ( $button eq 'newline' )
1094         {
1095           $result .= qq{</td>} unless $beginofline;
1096           $result .= qq{</tr>};
1097           $result .= qq{<tr>};
1098           $beginofline = 1;
1099
1100         }
1101         elsif (ref($button) eq 'CODE')
1102         {
1103             $result .= &$button($vertical);
1104         }
1105         elsif (ref($button) eq 'SCALAR')
1106         {
1107             $result .= "$$button" if defined($$button);
1108         }
1109         elsif (ref($button) eq 'ARRAY')
1110         {
1111             my $text = $button->[1];
1112             my $button_href = $button->[0];
1113             # verify that $button_href is simple text and text is a reference
1114             if (defined($button_href) and !ref($button_href) 
1115                and defined($text) and (ref($text) eq 'SCALAR') and defined($$text))
1116             {             # use given text
1117                 if ($Texi2HTML::HREF{$button_href})
1118                 {
1119                   my $anchor_attributes = '';
1120                   if ($USE_ACCESSKEY and (defined($BUTTONS_ACCESSKEY{$button_href})) and ($BUTTONS_ACCESSKEY{$button_href} ne ''))
1121                   {
1122                       $anchor_attributes = "accesskey=\"$BUTTONS_ACCESSKEY{$button_href}\"";
1123                   }
1124                   if ($USE_REL_REV and (defined($BUTTONS_REL{$button_href})) and ($BUTTONS_REL{$button_href} ne ''))
1125                   {
1126                       $anchor_attributes .= " rel=\"$BUTTONS_REL{$button_href}\"";
1127                   }
1128                   $result .=  "" .
1129                         &$anchor('',
1130                                     $Texi2HTML::HREF{$button_href},
1131                                     get_navigation_text($$text),
1132                                     $anchor_attributes
1133                                    );
1134                 }
1135                 else
1136                 {
1137                   $result .=  get_navigation_text($$text);
1138                 }
1139             }
1140         }
1141         elsif ($button eq ' ')
1142         {                       # handle space button
1143             $result .= 
1144                 ($ICONS && $ACTIVE_ICONS{' '}) ?
1145                     &$button_icon_img($BUTTONS_NAME{$button}, $ACTIVE_ICONS{' '}) :
1146                         $NAVIGATION_TEXT{' '};
1147             #next;
1148         }
1149         elsif ($Texi2HTML::HREF{$button})
1150         {                       # button is active
1151             my $btitle = $BUTTONS_GOTO{$button} ?
1152                 'title="' . $BUTTONS_GOTO{$button} . '"' : '';
1153             if ($USE_ACCESSKEY and (defined($BUTTONS_ACCESSKEY{$button})) and ($BUTTONS_ACCESSKEY{$button} ne ''))
1154             {
1155                 $btitle .= " accesskey=\"$BUTTONS_ACCESSKEY{$button}\"";
1156             }
1157             if ($USE_REL_REV and (defined($BUTTONS_REL{$button})) and ($BUTTONS_REL{$button} ne ''))
1158             {
1159                 $btitle .= " rel=\"$BUTTONS_REL{$button}\"";
1160             }
1161             if ($ICONS && $ACTIVE_ICONS{$button})
1162             {                   # use icon
1163                 $result .= '' .
1164                     &$anchor('',
1165                         $Texi2HTML::HREF{$button},
1166                         &$button_icon_img($BUTTONS_NAME{$button},
1167                                    $ACTIVE_ICONS{$button},
1168                                    $Texi2HTML::SIMPLE_TEXT{$button}),
1169                         $btitle
1170                       );
1171             }
1172             else
1173             {                   # use text
1174                 $result .= 
1175                     '[' .
1176                         &$anchor('',
1177                                     $Texi2HTML::HREF{$button},
1178                                     get_navigation_text($button),
1179                                     $btitle
1180                                    ) .
1181                                        ']';
1182             }
1183         }
1184         else
1185         {                       # button is passive
1186             $result .= 
1187                 $ICONS && $PASSIVE_ICONS{$button} ?
1188                     &$button_icon_img($BUTTONS_NAME{$button},
1189                                           $PASSIVE_ICONS{$button},
1190                                           $Texi2HTML::SIMPLE_TEXT{$button}) :
1191
1192                                               "[" . get_navigation_text($button) . "]";
1193         }
1194         $result .= "</td>\n" if $vertical;
1195         $result .= "</tr>\n" if $vertical;
1196     }
1197     $result .= "</td>" unless $beginofline;
1198     $result .= "</tr>" unless $vertical;
1199     $result .= "</table>\n";
1200     if ($web_manual) {
1201       return "\n";
1202     } else {
1203       return $result;
1204     }
1205 }
1206
1207
1208 @Texi2HTML::Config::SECTION_BUTTONS =
1209     ('left-aligned-cell-1', 'FastBack',
1210      'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
1211      'right-aligned-cell-1', 'FastForward',
1212      'newline',
1213      'left-aligned-cell-2', 'Back',
1214      'center-aligned-cell-1', 'Up',
1215      'right-aligned-cell-2', 'Forward'
1216     );
1217
1218 # buttons for misc stuff
1219 @Texi2HTML::Config::MISC_BUTTONS = ('center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About');
1220
1221 # buttons for chapter file footers
1222 # (and headers but only if SECTION_NAVIGATION is false)
1223 @Texi2HTML::Config::CHAPTER_BUTTONS =
1224     ('left-aligned-cell-1', 'FastBack',
1225      'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
1226      'right-aligned-cell-1', 'FastForward',
1227     );
1228
1229 # buttons for section file footers
1230 @Texi2HTML::Config::SECTION_FOOTER_BUTTONS =
1231     ('left-aligned-cell-1', 'FastBack',
1232      'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
1233      'right-aligned-cell-1', 'FastForward',
1234      'newline',
1235      'left-aligned-cell-2', 'Back',
1236      'center-aligned-cell-1', 'Up',
1237      'right-aligned-cell-2', 'Forward'
1238     );
1239
1240 @Texi2HTML::Config::NODE_FOOTER_BUTTONS =
1241     ('left-aligned-cell-1', 'FastBack',
1242      'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
1243      'right-aligned-cell-1', 'FastForward',
1244      'newline',
1245      'left-aligned-cell-2', 'Back',
1246      'center-aligned-cell-1', 'Up',
1247      'right-aligned-cell-2', 'Forward'
1248     );
1249
1250
1251
1252
1253
1254 #############################################################################
1255 ###  FOOTNOTE FORMATTING
1256 #############################################################################
1257
1258 # Format footnotes in a nicer way: Instead of printing the number in a separate
1259 # (nr) heading line, use the standard way of prepending <sup>nr</sup> immediately
1260 # before the fn text.
1261
1262
1263 # The following code is copied from texi2html's examples/makeinfo.init and
1264 # should be updated when texi2html makes some changes there!
1265
1266 my $makekinfo_like_footnote_absolute_number = 0;
1267
1268 sub makeinfo_like_foot_line_and_ref($$$$$$$$)
1269 {
1270     my $foot_num = shift;
1271     my $relative_num = shift;
1272     my $footid = shift;
1273     my $docid = shift;
1274     my $from_file = shift;
1275     my $footnote_file = shift;
1276     my $lines = shift;
1277     my $state = shift;
1278
1279     $makekinfo_like_footnote_absolute_number++;
1280
1281     # this is a bit obscure, this allows to add an anchor only if formatted
1282     # as part of the document.
1283     $docid = '' if ($state->{'outside_document'} or $state->{'multiple_pass'});
1284
1285     if ($from_file eq $footnote_file)
1286     {
1287         $from_file = $footnote_file = '';
1288     }
1289
1290     my $foot_anchor = "<sup>" . &$anchor($docid, "$footnote_file#$footid", $relative_num) . "</sup>";
1291     $foot_anchor = &$anchor($docid, "$footnote_file#$footid", "($relative_num)") if ($state->{'preformatted'});
1292
1293 #    unshift @$lines, "<li>";
1294 #    push @$lines, "</li>\n";
1295     return ($lines, $foot_anchor);
1296 }
1297
1298 sub makeinfo_like_foot_lines($)
1299 {
1300     my $lines = shift;
1301     unshift @$lines, "<hr>\n<h4>$Texi2HTML::I18n::WORDS->{'Footnotes_Title'}</h4>\n";
1302 #<ol type=\"1\">\n";
1303 #    push @$lines, "</ol>";
1304     return $lines;
1305 }
1306
1307 my %makekinfo_like_paragraph_in_footnote_nr;
1308
1309 sub makeinfo_like_paragraph ($$$$$$$$$$$$$)
1310 {
1311     my $text = shift;
1312     my $align = shift;
1313     my $indent = shift;
1314     my $paragraph_command = shift;
1315     my $paragraph_command_formatted = shift;
1316     my $paragraph_number = shift;
1317     my $format = shift;
1318     my $item_nr = shift;
1319     my $enumerate_style = shift;
1320     my $number = shift;
1321     my $command_stack_at_end = shift;
1322     my $command_stack_at_begin = shift;
1323     my $state = shift;
1324 #print STDERR "format: $format\n" if (defined($format));
1325 #print STDERR "paragraph @$command_stack_at_end; @$command_stack_at_begin\n";
1326     $paragraph_command_formatted = '' if (!defined($paragraph_command_formatted) or
1327           exists($special_list_commands{$format}->{$paragraph_command}));
1328     return '' if ($text =~ /^\s*$/);
1329     foreach my $style(t2h_collect_styles($command_stack_at_begin))
1330     {
1331        $text = t2h_begin_style($style, $text);
1332     }
1333     foreach my $style(t2h_collect_styles($command_stack_at_end))
1334     {
1335        $text = t2h_end_style($style, $text);
1336     }
1337     if (defined($paragraph_number) and defined($$paragraph_number))
1338     {
1339          $$paragraph_number++;
1340          return $text  if (($format eq 'itemize' or $format eq 'enumerate') and
1341             ($$paragraph_number == 1));
1342     }
1343     my $open = '<p';
1344     if ($align)
1345     {
1346         $open .= " align=\"$paragraph_style{$align}\"";
1347     }
1348     my $footnote_text = '';
1349     if (defined($command_stack_at_begin->[0]) and $command_stack_at_begin->[0] eq 'footnote')
1350     {
1351         my $state = $Texi2HTML::THISDOC{'state'};
1352         $makekinfo_like_paragraph_in_footnote_nr{$makekinfo_like_footnote_absolute_number}++;
1353         if ($makekinfo_like_paragraph_in_footnote_nr{$makekinfo_like_footnote_absolute_number} <= 1)
1354         {
1355            $open.=' class="footnote"';
1356            my $document_file = $state->{'footnote_document_file'};
1357            if ($document_file eq $state->{'footnote_footnote_file'})
1358            {
1359                $document_file = '';
1360            }
1361            my $docid = $state->{'footnote_place_id'};
1362            my $doc_state = $state->{'footnote_document_state'};
1363            $docid = '' if ($doc_state->{'outside_document'} or $doc_state->{'multiple_pass'});
1364            my $foot_label = &$anchor($state->{'footnote_footnote_id'},
1365                  $document_file . "#$state->{'footnote_place_id'}",
1366                  "$state->{'footnote_number_in_page'}");
1367            $footnote_text = "<small>[${foot_label}]</small> ";
1368         }
1369     }
1370     return $open.'>'.$footnote_text.$text.'</p>';
1371 }
1372
1373
1374 #############################################################################
1375 ###  OTHER SETTINGS
1376 #############################################################################
1377
1378 # For split pages, use index.html as start page!
1379 if ($Texi2HTML::Config::SPLIT eq 'section') {
1380   $Texi2HTML::Config::TOP_FILE = 'index.html';
1381 }
1382 if ($web_node) {
1383 } else {
1384   push @Texi2HTML::Config::command_handler_process, \&lilypond_init_toc_depth;
1385 }
1386
1387
1388 return 1;