]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/lilypond-texi2html.init
texi2html: Use IE stylesheet for the docs only.
[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: GPLv3+
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 package main;
67 $original_normalise_node = \&normalise_node;
68
69 sub t2h_default_normalise_node($)
70 {
71     my $text = shift;
72     $original_normalise_node->($text);
73 }
74
75 *normalise_node = sub($)
76 {
77     my $text = shift;
78     return &$Texi2HTML::Config::normalise_node($text);
79 };
80
81 package Texi2HTML::Config;
82 ##$normalise_node = \&t2h_default_normalise_node;
83 $normalise_node = \&lilypond_normalise_node;
84
85
86 use utf8;
87 use Encode qw(decode);
88
89 #############################################################################
90 ### TRANSLATIONS
91 #############################################################################
92
93 my $LY_LANGUAGES = {};
94 $LY_LANGUAGES->{'fr'} = {
95     'Back to Documentation Index' => 'Retour à l\'accueil de la documentation',
96     '<p>Thanks to ${webdev_link} for hosting ${lily_site}.' => '<p>Remerciements à ${webdev_link} pour l\'hébergement de ${lily_site}.',
97 };
98
99 $LY_LANGUAGES->{'es'} = {
100     'Back to Documentation Index' => 'Volver al índice de la documentación',
101     '<p>Thanks to ${webdev_link} for hosting ${lily_site}.' => '<p>Agradecemos a ${webdev_link} el alojamiento de ${lily_site}.',
102 };
103
104 $LY_LANGUAGES->{'de'} = {
105     'Back to Documentation Index' => 'Zur Dokumentationsübersicht',
106     '<p>Thanks to ${webdev_link} for hosting ${lily_site}.' => '',
107 };
108
109 $LY_LANGUAGES->{'ja'} = {
110     'Back to Documentation Index' => 'ドキュメント インデックスに戻る',
111     '<p>Thanks to ${webdev_link} for hosting ${lily_site}.' => '',
112 };
113
114 $LY_LANGUAGES->{'hu'} = {
115     'Back to Documentation Index' => 'Vissza a dokumentációk jegyzékéhez',
116     '<p>Thanks to ${webdev_link} for hosting ${lily_site}.' => 'Köszönet a ${webdev_link} részére a ${lily_site} tárhelyért.',
117 };
118
119 $LY_LANGUAGES->{'it'} = {
120     'Back to Documentation Index' => 'Torna all\'indice della documentazione',
121     '<p>Thanks to ${webdev_link} for hosting ${lily_site}.' => '',
122 };
123
124 $LY_LANGUAGES->{'nl'} = {
125     'Back to Documentation Index' => 'Terug naar de Documentatieindex',
126     '<p>Met dank aan ${webdev_link} voor het hosten van ${lily_site}.' => '',
127 };
128
129 # FIXME: request the translations below then send them to texi2html/texinfo devs
130 $LANGUAGES->{'it'} = {
131                        '  The buttons in the navigation panels have the following meaning:' => '  I bottoni nei pannelli di navigazione hanno il seguente significato:',
132                        '  where the @strong{ Example } assumes that the current position is at @strong{ Subsubsection One-Two-Three } of a document of the following structure:' => '  dove @strong{ Esempio } assume che l\'attuale posizione è alla @strong{ Sottosottosezione Uno-Due-Tre } di un documento che ha la seguente struttura:',
133                        ' Up ' => ' Su ',
134                        '(outside of any element)' => '(fuori da qualsiasi elemento)',
135                        '(outside of any node)' => '(fuori da qualsiasi nodo)',
136                        '@b{{quotation_arg}:} ' => '@b{{quotation_arg}:} ',
137                        '@cite{{book}}' => '@cite{{book}}',
138                        '@{No value for `{value}\'@}' => '@{Nessun valore per `{value}\'@}',
139                        'About' => 'Informazioni',
140                        'About (help)' => 'Informazioni (aiuto)',
141                        'About This Document' => 'Informazioni su questo documento',
142                        'April' => 'Aprile',
143                        'August' => 'Agosto',
144                        'Back' => 'Indietro',
145                        'Back section in previous file' => '',
146                        'Beginning of this chapter or previous chapter' => 'Inizio di questo capitolo o capitolo precedente',
147                        'Button' => 'Bottone',
148                        'Contents' => 'Contenuti',
149                        'Cover (top) of document' => 'Copertina (inizio) del documento',
150                        'Current' => 'Attuale',
151                        'Current Position' => 'Posizione Attuale',
152                        'Current section' => 'Sezione attuale',
153                        'December' => 'Dicembre',
154                        'FastBack' => 'Indietro veloce',
155                        'FastForward' => 'Avanti veloce',
156                        'February' => 'Febbraio',
157                        'First' => 'Primo',
158                        'First section in reading order' => 'Prima sezione in ordine di lettura',
159                        'Following' => 'Seguente',
160                        'Following node' => 'Nodo seguente',
161                        'Footnotes' => 'Note a piè di pagina',
162                        'Forward' => 'Avanti',
163                        'Forward section in next file' => 'Sezione successiva nel prossimo file',
164                        'From 1.2.3 go to' => 'Da 1.2.3 vai a',
165                        'Go to' => 'Vai a',
166                        'Index' => 'Indice',
167                        'Index Entry' => 'Voce dell\'indice',
168                        'January' => 'Gennaio',
169                        'July' => 'Luglio',
170                        'Jump to' => 'Salta a',
171                        'June' => 'Giugno',
172                        'Last' => 'Ultimo',
173                        'Last section in reading order' => 'Ultima sezione in ordine di lettura',
174                        'March' => 'Marzo',
175                        'May' => 'Maggio',
176                        'Menu:' => 'Menu',
177                        'Name' => 'Nome',
178                        'Next' => 'Successivo',
179                        'Next chapter' => 'Capitolo successivo',
180                        'Next file' => 'File successivo',
181                        'Next node' => 'Nodo successivo',
182                        'Next section in reading order' => 'Sezione successiva in ordine di lettura',
183                        'Next section on same level' => 'Sezione successiva sullo stesso livello',
184                        'NextFile' => 'File successivo',
185                        'Node following in node reading order' => 'Nodo seguente in ordine di lettura',
186                        'Node up' => 'Nodo superiore',
187                        'NodeNext' => 'Nodo successivo',
188                        'NodePrev' => 'Nodo precedente',
189                        'NodeUp' => 'Nodo superiore',
190                        'November' => 'Novembre',
191                        'October' => 'Ottobre',
192                        'Overview' => 'Panoramica',
193                        'Prev' => 'Prec.',
194                        'PrevFile' => 'File precedente',
195                        'Previous' => 'Precedente',
196                        'Previous file' => 'File precedente',
197                        'Previous node' => 'Nodo precedente',
198                        'Previous section in reading order' => 'Sezione precedente in ordine di lettura',
199                        'Previous section on same level' => 'Sezione precedente sullo stesso livello',
200                        'Section' => 'Sezione',
201                        'Section One' => 'Sezione uno',
202                        'See ' => 'Vedi',
203                        'See @cite{{book}}' => 'Vedi @cite{{book}}',
204                        'See section `@asis{}`{section_name}\'@asis{}\' in @cite{{book}}' => 'Vedi la sezione `@asis{}`{section_name}\'@asis{}\' in @cite{{book}}',
205                        'See section `{section}\' in @cite{{book}}' => 'Vedi la sezione `{section}\' in @cite{{book}}',
206                        'See section {reference_name}' => 'Vedi la sezione {reference_name}',
207                        'See {node_file_href}' => 'Vedi {node_file_href}',
208                        'See {node_file_href} @cite{{book}}' => 'Vedi {node_file_href} @cite{{book}}',
209                        'See {node_file_href} section `{section}\' in @cite{{book}}' => 'Vedi {node_file_href} nella sezione `{section}\' in @cite{{book}}',
210                        'See {reference_name}' => 'Vedi {reference_name}',
211                        'See {ref}' => 'Vedi {ref}',
212                        'See {title_ref}' => 'Vedi {title_ref}',
213                        'September' => 'Settembre',
214                        'Short Table of Contents' => 'Indice breve',
215                        'Short table of contents' => 'Indice breve',
216                        'Subsection One-Four' => 'Sottosezione Uno-Quattro',
217                        'Subsection One-One' => 'Sottosezione Uno-Uno',
218                        'Subsection One-Three' => 'Sottosezione Uno-Tre',
219                        'Subsection One-Two' => 'Sottosezione Uno-Due',
220                        'Subsubsection One-Two-Four' => 'Sottosottosezione Uno-Due-Quattro',
221                        'Subsubsection One-Two-One' => 'Sottosottosezione Uno-Due-Uno',
222                        'Subsubsection One-Two-Three' => 'Sottosottosezione Uno-Due-Tre',
223                        'Subsubsection One-Two-Two' => 'Sottosottosezione Uno-Due-Due',
224                        'T2H_today' => '%s, %d %d',
225                        'Table of Contents' => 'Indice',
226                        'Table of contents' => 'Indice',
227                        'The node you are looking for is at {href}.' => 'Il nodo che stai cercando è {href}',
228                        'This' => 'Questo',
229                        'This document was generated on @i{{date}} using @uref{{program_homepage}, @i{{program}}}.' => 'Questo documento è stato generato il @i{{date}} con @uref{{program_homepage}, @i{{program}}}.',
230                        'This document was generated using @uref{{program_homepage}, @emph{{program}}}.' => 'Questo documento è stato generato con @uref{{program_homepage}, @emph{{program}}}.',
231                        'Top' => 'Inizio',
232                        'Untitled Document' => 'Documento senza titolo',
233                        'Up' => 'Su',
234                        'Up node' => 'Nodo superiore',
235                        'Up section' => 'Sezione superiore',
236                        'current' => 'attuale',
237                        'on @emph{{date}}' => 'il @emph{{date}}',
238                        'section `@asis{}`{section_name}\'@asis{}\' in @cite{{book}}' => 'sezione `@asis{}`{section_name}\'@asis{}\' in @cite{{book}}',
239                        'section `{section}\' in @cite{{book}}' => 'sezione `{section}\' in @cite{{book}}',
240                        'see ' => 'vedi ',
241                        'see @cite{{book}}' => 'vedi @cite{{book}}',
242                        'see section `@asis{}`{section_name}\'@asis{}\' in @cite{{book}}' => 'vedi la sezione `@asis{}`{section_name}\'@asis{}\' in @cite{{book}}',
243                        'see section `{section}\' in @cite{{book}}' => 'vedi la sezione `{section}\' in @cite{{book}}',
244                        'see section {reference_name}' => 'vedi la sezione {reference_name}',
245                        'see {node_file_href}' => 'vedi {node_file_href}',
246                        'see {node_file_href} @cite{{book}}' => 'vedi {node_file_href} @cite{{book}}',
247                        'see {node_file_href} section `{section}\' in @cite{{book}}' => 'vedi {node_file_href} nella sezione `{section}\' in @cite{{book}}',
248                        'see {reference_name}' => 'vedi {reference_name}',
249                        'see {ref}' => 'vedi {ref}',
250                        'see {title_ref}' => 'vedi {title_ref}',
251                        '{acronym_like} ({explanation})' => '{acronym_like} ({explanation})',
252                        '{name} of {class}' => '{name} di {class}',
253                        '{name} on {class}' => '{name} in {class}',
254                        '{node_file_href}' => '{node_file_href}',
255                        '{node_file_href} @cite{{book}}' => '{node_file_href} @cite{{book}}',
256                        '{node_file_href} section `{section}\' in @cite{{book}}' => '{node_file_href} nella sezione `{section}\' in @cite{{book}}',
257                        '{reference_name}' => '{reference_name}',
258                        '{ref}' => '{ref}',
259                        '{style} {number}' => '{style} {number}',
260                        '{style}: {caption_first_line}' => '{style}: {caption_first_line}',
261                        '{style}: {shortcaption_first_line}' => '{style}: {shortcaption_first_line}',
262                        '{title_ref}' => '{title_ref}'
263                      };
264
265 $LANGUAGES->{'hu'} = {
266                        '  The buttons in the navigation panels have the following meaning:' => '  A navigációs panelen levő gombok jelentése a következő:',
267                        '  where the @strong{ Example } assumes that the current position is at @strong{ Subsubsection One-Two-Three } of a document of the following structure:' => '  @strong{ Példánkban } az aktuális pozíció az @strong{ 1.2.3 alalszakasz } egy olyan dokumentumban, melynek szerkezete a következő:',
268                        ' Up ' => 'Fel',
269                        '(outside of any element)' => '(bármelyik elemen kívül)',
270                        '(outside of any node)' => '(bármelyik csomóponton kívül)',
271                        '@b{{quotation_arg}:} ' => '@b{{quotation_arg}:} ',
272                        '@cite{{book}}' => '@cite{{book}}',
273                        '@{No value for `{value}\'@}' => '@{Nincs értéke ennek: `{value}\'@}',
274                        'About' => 'Súgó',
275                        'About (help)' => 'Segítség a navigációhoz',
276                        'About This Document' => 'A navigációs panel használata',
277                        'April' => 'április',
278                        'August' => 'augusztus',
279                        'Back' => 'Vissza',
280                        'Back section in previous file' => 'Előző fájl hátsó szakasza',
281                        'Beginning of this chapter or previous chapter' => 'Fejezet eleje vagy előző fejezet',
282                        'Button' => 'Gomb',
283                        'Contents' => 'Tartalom',
284                        'Cover (top) of document' => 'Dokumentum címoldala',
285                        'Current' => 'Aktuális',
286                        'Current Position' => 'Aktuális pozíció',
287                        'Current section' => 'Aktuális szakasz',
288                        'December' => 'december',
289                        'FastBack' => 'Visszaugrás',
290                        'FastForward' => 'Előreugrás',
291                        'February' => 'február',
292                        'First' => 'Első',
293                        'First section in reading order' => 'Első szakasz az olvasási sorrendben',
294                        'Following' => 'Következő',
295                        'Following node' => 'Következő csomópont',
296                        'Footnotes' => 'Lábjegyzet',
297                        'Forward' => 'Előre',
298                        'Forward section in next file' => 'Következő fájl elülső szakasza',
299                        'From 1.2.3 go to' => '1.2.3-ból ide jutunk',
300                        'Go to' => 'Cél',
301                        'Index' => 'Tárgymutató',
302                        'Index Entry' => 'Tárgymutató-bejegyzés',
303                        'January' => 'január',
304                        'July' => 'július',
305                        'Jump to' => 'Ugorj ide',
306                        'June' => 'június',
307                        'Last' => 'Utolsó',
308                        'Last section in reading order' => 'Utolsó szakasz az olvasási sorrendben',
309                        'March' => 'március',
310                        'May' => 'május',
311                        'Menu:' => 'Menü:',
312                        'Name' => 'Név',
313                        'Next' => 'Következő',
314                        'Next chapter' => 'Következő fejezet',
315                        'Next file' => 'Következő fájl',
316                        'Next node' => 'Következő csomópont',
317                        'Next section in reading order' => 'Következő szakasz az olvasási sorrendben',
318                        'Next section on same level' => 'Következő szakasz ugyanazon a szinten',
319                        'NextFile' => 'KövetkezőFájl',
320                        'Node following in node reading order' => 'Következő csomópont az olvasási sorrendben',
321                        'Node up' => 'Szülő csomópont',
322                        'NodeNext' => 'KövetkezőCsomópont',
323                        'NodePrev' => 'ElőzőCsomópont',
324                        'NodeUp' => 'SzülőCsomópont',
325                        'November' => 'november',
326                        'October' => 'október',
327                        'Overview' => 'Áttekintés',
328                        'Prev' => 'Előző',
329                        'PrevFile' => 'ElőzőFájl',
330                        'Previous' => 'Előző',
331                        'Previous file' => 'Előző fájl',
332                        'Previous node' => 'Előző csomópont',
333                        'Previous section in reading order' => 'Előző szakasz az olvasási sorrendben',
334                        'Previous section on same level' => 'Előző szakasz ugyanazon a szinten',
335                        'Section' => 'Szakasz',
336                        'Section One' => 'szakasz',
337                        'See ' => 'Ld. ',
338                        'See @cite{{book}}' => 'Ld. @cite{{book}}',
339                        'See section `@asis{}`{section_name}\'@asis{}\' in @cite{{book}}' => 'Ld. ezt a szakaszt: `@asis{}`{section_name}\'@asis{}\' itt: @cite{{book}}',
340                        'See section `{section}\' in @cite{{book}}' => 'Ld. ezt a szakaszt: `{section}\' itt: @cite{{book}}',
341                        'See section {reference_name}' => 'Ld. ezt a szakaszt: {reference_name}',
342                        'See {node_file_href}' => 'Ld. {node_file_href}',
343                        'See {node_file_href} @cite{{book}}' => 'See {node_file_href} @cite{{book}}',
344                        'See {node_file_href} section `{section}\' in @cite{{book}}' => 'Ld. {node_file_href} ezt a szakaszt: `{section}\' itt: @cite{{book}}',
345                        'See {reference_name}' => 'Ld. {reference_name}',
346                        'See {ref}' => 'Ld. {ref}',
347                        'See {title_ref}' => 'Ld. {title_ref}',
348                        'September' => 'szeptember',
349                        'Short Table of Contents' => 'Rövid tartalomjegyzék',
350                        'Short table of contents' => 'Rövid tartalomjegyzék',
351                        'Subsection One-Four' => 'alszakasz',
352                        'Subsection One-One' => 'alszakasz',
353                        'Subsection One-Three' => 'alszakasz',
354                        'Subsection One-Two' => 'alszakasz',
355                        'Subsubsection One-Two-Four' => 'alalszakasz',
356                        'Subsubsection One-Two-One' => 'alalszakasz',
357                        'Subsubsection One-Two-Three' => 'alalszakasz',
358                        'Subsubsection One-Two-Two' => 'alalszakasz',
359                        'T2H_today' => '%s, %d %d',
360                        'Table of Contents' => 'Tartalomjegyzék',
361                        'Table of contents' => 'Tartalomjegyzék',
362                        'The node you are looking for is at {href}.' => 'A keresett csomópont itt található: {href}.',
363                        'This' => 'Ez a(z)',
364                        '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}}}.',
365                        'This document was generated using @uref{{program_homepage}, @emph{{program}}}.' => 'Ezt a dokumentumot a(z) @uref{{program_homepage}, @emph{{program}}} generálta.',
366                        'Top' => 'Címoldal',
367                        'Untitled Document' => 'Névtelen dokumentum',
368                        'Up' => 'Fel',
369                        'Up node' => 'Szülő csomópont',
370                        'Up section' => 'Szülő szakasz',
371                        'current' => 'aktuális',
372                        'on @emph{{date}}' => 'ekkor: @emph{{date}}',
373                        'section `@asis{}`{section_name}\'@asis{}\' in @cite{{book}}' => 'szakasz: `@asis{}`{section_name}\'@asis{}\' itt: @cite{{book}}',
374                        'section `{section}\' in @cite{{book}}' => 'szakasz: `{section}\' itt: @cite{{book}}',
375                        'see ' => 'ld. ',
376                        'see @cite{{book}}' => 'ld. @cite{{book}}',
377                        'see section `@asis{}`{section_name}\'@asis{}\' in @cite{{book}}' => 'ld. ezt a szakaszt: `@asis{}`{section_name}\'@asis{}\' itt: @cite{{book}}',
378                        'see section `{section}\' in @cite{{book}}' => 'ld. ezt a szakaszt: `{section}\' itt: @cite{{book}}',
379                        'see section {reference_name}' => 'ld. ezt a szakaszt: {reference_name}',
380                        'see {node_file_href}' => 'ld. {node_file_href}',
381                        'see {node_file_href} @cite{{book}}' => 'ld. {node_file_href} @cite{{book}}',
382                        'see {node_file_href} section `{section}\' in @cite{{book}}' => 'ld. {node_file_href} ezt a szakaszt: `{section}\' itt: @cite{{book}}',
383                        'see {reference_name}' => 'ld. {reference_name}',
384                        'see {ref}' => 'ld. {ref}',
385                        'see {title_ref}' => 'ld. {title_ref}',
386                        '{acronym_like} ({explanation})' => '{acronym_like} ({explanation})',
387                        '{name} of {class}' => '{name} típusa: {class}',
388                        '{name} on {class}' => '{name} ezen: {class}',
389                        '{node_file_href}' => '{node_file_href}',
390                        '{node_file_href} @cite{{book}}' => '{node_file_href} @cite{{book}}',
391                        '{node_file_href} section `{section}\' in @cite{{book}}' => '{node_file_href} szakasz: `{section}\' itt: @cite{{book}}',
392                        '{reference_name}' => '{reference_name}',
393                        '{ref}' => '{ref}',
394                        '{style} {number}' => '{style} {number}',
395                        '{style}: {caption_first_line}' => '{style}: {caption_first_line}',
396                        '{style}: {shortcaption_first_line}' => '{style}: {shortcaption_first_line}',
397                        '{title_ref}' => '{title_ref}'
398                      };
399
400 $LANGUAGES->{'ja'} = {
401                        '  The buttons in the navigation panels have the following meaning:' => '  ナビゲーション パネルの中にあるボタンには以下のような意味があります:',
402                        '  where the @strong{ Example } assumes that the current position is at @strong{ Subsubsection One-Two-Three } of a document of the following structure:' => '  この表で、@strong{ 行き先 } は、現在の位置が以下のような構造を持つドキュメントの @strong{ サブサブセクション 1-2-3 } であると仮定しています:',
403                        ' Up ' => ' 上へ ',
404                        '(outside of any element)' => '(outside of any element)',
405                        '(outside of any node)' => '(outside of any node)',
406                        '@b{{quotation_arg}:} ' => '@b{{quotation_arg}:} ',
407                        '@cite{{book}}' => '@cite{{book}}',
408                        '@{No value for `{value}\'@}' => '@{No value for `{value}\'@}',
409                        'About' => '情報',
410                        'About (help)' => '情報 (ヘルプ)',
411                        'About This Document' => 'このドキュメントについて',
412                        'April' => '4 月',
413                        'August' => '8 月',
414                        'Back' => 'Back',
415                        'Back section in previous file' => '',
416                        'Beginning of this chapter or previous chapter' => 'この章あるいは前の章の先頭',
417                        'Button' => 'ボタン',
418                        'Contents' => '目次',
419                        'Cover (top) of document' => 'ドキュメントの表紙 (先頭)',
420                        'Current' => '',
421                        'Current Position' => '現在の位置',
422                        'Current section' => '',
423                        'December' => '12 月',
424                        'FastBack' => '',
425                        'FastForward' => '',
426                        'February' => '2 月',
427                        'First' => '',
428                        'First section in reading order' => '',
429                        'Following' => '',
430                        'Following node' => '',
431                        'Footnotes' => '脚注',
432                        'Forward' => '',
433                        'Forward section in next file' => '',
434                        'From 1.2.3 go to' => '1.2.3 からの行き先',
435                        'Go to' => '行き先',
436                        'Index' => 'インデックス',
437                        'Index Entry' => 'インデックス エントリ',
438                        'January' => '1 月',
439                        'July' => '7 月',
440                        'Jump to' => '',
441                        'June' => '6月',
442                        'Last' => '',
443                        'Last section in reading order' => '',
444                        'March' => '3 月',
445                        'May' => '5 月',
446                        'Menu:' => 'メニュー',
447                        'Name' => '',
448                        'Next' => '',
449                        'Next chapter' => '次の章',
450                        'Next file' => '',
451                        'Next node' => '',
452                        'Next section in reading order' => '次のセクション',
453                        'Next section on same level' => '',
454                        'NextFile' => '',
455                        'Node following in node reading order' => '',
456                        'Node up' => '',
457                        'NodeNext' => '',
458                        'NodePrev' => '',
459                        'NodeUp' => '',
460                        'November' => '11 月',
461                        'October' => '10 月',
462                        'Overview' => '概要',
463                        'Prev' => '',
464                        'PrevFile' => '',
465                        'Previous' => '',
466                        'Previous file' => '',
467                        'Previous node' => '',
468                        'Previous section in reading order' => '前のセクション',
469                        'Previous section on same level' => '',
470                        'Section' => 'セクション',
471                        'Section One' => 'セクション 1',
472                        'See ' => '',
473                        'See @cite{{book}}' => '',
474                        'See section `@asis{}`{section_name}\'@asis{}\' in @cite{{book}}' => '',
475                        'See section `{section}\' in @cite{{book}}' => '',
476                        'See section {reference_name}' => '',
477                        'See {node_file_href}' => '',
478                        'See {node_file_href} @cite{{book}}' => '',
479                        'See {node_file_href} section `{section}\' in @cite{{book}}' => '',
480                        'See {reference_name}' => '',
481                        'See {ref}' => '',
482                        'See {title_ref}' => '',
483                        'September' => '9 月',
484                        'Short Table of Contents' => '',
485                        'Short table of contents' => '',
486                        'Subsection One-Four' => 'サブセクション 1-4',
487                        'Subsection One-One' => 'サブセクション 1-1',
488                        'Subsection One-Three' => 'サブセクション 1-3',
489                        'Subsection One-Two' => 'サブセクション 1-2',
490                        'Subsubsection One-Two-Four' => 'サブサブセクション 1-2-4',
491                        'Subsubsection One-Two-One' => 'サブサブセクション 1-2-1',
492                        'Subsubsection One-Two-Three' => 'サブサブセクション 1-2-3',
493                        'Subsubsection One-Two-Two' => 'サブサブセクション 1-2-2',
494                        'T2H_today' => '%s, %d %d',
495                        'Table of Contents' => '目次',
496                        'Table of contents' => '目次',
497                        'The node you are looking for is at {href}.' => '',
498                        'This' => '',
499                        'This document was generated on @i{{date}} using @uref{{program_homepage}, @i{{program}}}.' => 'このドキュメントは @i{{date}} に、@uref{{program_homepage}, @i{{program}}} を用いて生成されました。',
500                        'This document was generated using @uref{{program_homepage}, @emph{{program}}}.' => 'このドキュメントは @uref{{program_homepage}, @emph{{program}}} を用いて生成されました。',
501                        'Top' => 'トップ',
502                        'Untitled Document' => '',
503                        'Up' => '上',
504                        'Up node' => '',
505                        'Up section' => '上のセクション',
506                        'current' => '',
507                        'on @emph{{date}}' => '@emph{{date}} に',
508                        'section `@asis{}`{section_name}\'@asis{}\' in @cite{{book}}' => '',
509                        'section `{section}\' in @cite{{book}}' => '',
510                        'see ' => '',
511                        'see @cite{{book}}' => '',
512                        'see section `@asis{}`{section_name}\'@asis{}\' in @cite{{book}}' => '',
513                        'see section `{section}\' in @cite{{book}}' => '',
514                        'see section {reference_name}' => '',
515                        'see {node_file_href}' => '',
516                        'see {node_file_href} @cite{{book}}' => '',
517                        'see {node_file_href} section `{section}\' in @cite{{book}}' => '',
518                        'see {reference_name}' => '',
519                        'see {ref}' => '',
520                        'see {title_ref}' => '',
521                        '{acronym_like} ({explanation})' => '{acronym_like} ({explanation})',
522                        '{name} of {class}' => '',
523                        '{name} on {class}' => '',
524                        '{node_file_href}' => '',
525                        '{node_file_href} @cite{{book}}' => '',
526                        '{node_file_href} section `{section}\' in @cite{{book}}' => '',
527                        '{reference_name}' => '',
528                        '{ref}' => '{ref}',
529                        '{style} {number}' => '{style} {number}',
530                        '{style}: {caption_first_line}' => '{style}: {caption_first_line}',
531                        '{style}: {shortcaption_first_line}' => '{style}: {shortcaption_first_line}',
532                        '{title_ref}' => '{title_ref}'
533                      };
534
535
536 sub ly_get_string () {
537     my $lang = $Texi2HTML::THISDOC{current_lang};
538     my $string = shift;
539     if ($lang and $lang ne "en" and $LY_LANGUAGES->{$lang}->{$string}) {
540         return $LY_LANGUAGES->{$lang}->{$string};
541     } else {
542         return $string;
543     }
544 }
545
546
547 #############################################################################
548 ### FUNCTIONALITY FOR MAIN WEB PAGES
549 #############################################################################
550
551 our $web_manual;
552
553 #############################################################################
554 ###  SETTINGS FOR TEXI2HTML
555 #############################################################################
556
557 # Validation fix for texi2html<=1.82
558 $Texi2HTML::Config::DOCTYPE = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
559
560 @Texi2HTML::Config::CSS_REFS = (
561     {FILENAME => "lilypond-mccarty.css", TITLE => "Default style"}
562     );
563 @Texi2HTML::Config::ALT_CSS_REFS      = (
564     {FILENAME => "lilypond.css", TITLE => "Andrew Hawryluk's design" },
565     {FILENAME => "lilypond-blue.css", TITLE => "Kurt Kroon's blue design" },
566 );
567
568 sub web_settings() {
569   print STDERR "Initializing settings for web site: [$Texi2HTML::THISDOC{current_lang}]\n";
570   $Texi2HTML::Config::BODYTEXT = "";
571   @Texi2HTML::Config::CSS_REFS      = (
572       {FILENAME => "lilypond-web.css", TITLE => "Patrick McCarty's design"}
573       );
574   @Texi2HTML::Config::ALT_CSS_REFS      = (
575       {FILENAME => "lilypond-web-alt1.css", TITLE => "Alternate style 1"},
576       {FILENAME => "lilypond-web-alt2.css", TITLE => "Alternate style 2"},
577       );
578 }
579
580 $Texi2HTML::Config::USE_ACCESSKEY = 1;
581 $Texi2HTML::Config::USE_LINKS     = 1;
582 $Texi2HTML::Config::USE_REL_REV   = 1;
583 $Texi2HTML::Config::SPLIT_INDEX   = 0;
584 $Texi2HTML::Config::SEPARATED_FOOTNOTES = 0; # Print footnotes on same page, not separated
585
586 my $bigpage = 0;
587 my $have_index_entries = 0;
588 if ($Texi2HTML::Config::SPLIT eq 'section' or
589     $Texi2HTML::Config::SPLIT eq 'node') {
590   $Texi2HTML::Config::element_file_name    = \&lilypond_element_file_name;
591   $bigpage = 0;
592 } else {
593   $bigpage = 1;
594 }
595
596 $Texi2HTML::Config::anchor  = \&lilypond_anchor;
597 $Texi2HTML::Config::element_target_name  = \&lilypond_element_target_name;
598 $default_print_element_header = $Texi2HTML::Config::print_element_header;
599 $Texi2HTML::Config::print_element_header = \&lilypond_print_element_header;
600 $Texi2HTML::Config::print_page_foot      = \&print_lilypond_page_foot;
601 $Texi2HTML::Config::print_navigation     = \&lilypond_print_navigation;
602 $Texi2HTML::Config::external_ref         = \&lilypond_external_ref;
603 $default_external_href = $Texi2HTML::Config::external_href;
604 $Texi2HTML::Config::external_href        = \&lilypond_external_href;
605 $default_toc_body = $Texi2HTML::Config::toc_body;
606 $Texi2HTML::Config::toc_body             = \&lilypond_toc_body;
607 $Texi2HTML::Config::css_lines            = \&lilypond_css_lines;
608 $default_unknown = $Texi2HTML::Config::unknown;
609 $Texi2HTML::Config::unknown              = \&lilypond_unknown;
610 $default_print_page_head = $Texi2HTML::Config::print_page_head;
611 $Texi2HTML::Config::print_page_head      = \&lilypond_print_page_head;
612 # $Texi2HTML::Config::foot_line_and_ref    = \&lilypond_foot_line_and_ref;
613 $Texi2HTML::Config::foot_line_and_ref  = \&makeinfo_like_foot_line_and_ref;
614 $Texi2HTML::Config::foot_lines         = \&makeinfo_like_foot_lines;
615 $Texi2HTML::Config::paragraph          = \&makeinfo_like_paragraph;
616
617
618
619 # Examples should be formatted similar to quotes:
620 $Texi2HTML::Config::complex_format_map->{'example'} = {
621   'begin' => q{"<blockquote>"},
622   'end' => q{"</blockquote>\n"},
623   'style' => 'code',
624  };
625
626 %Texi2HTML::config::misc_pages_targets = (
627    'Overview' => 'Overview',
628    'Contents' => 'Contents',
629    'About' => 'About'
630 );
631
632
633 my @section_to_filename;
634
635
636
637
638 #############################################################################
639 ###  DEBUGGING
640 #############################################################################
641
642 use Data::Dumper;
643 $Data::Dumper::Maxdepth = 2;
644
645 sub print_element_info($)
646 {
647   my $element = shift;
648   print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
649   print "Element: $element\n";
650   print Dumper($element);
651 }
652
653
654
655
656
657 #############################################################################
658 ###  HELPER FUNCTIONS
659 #############################################################################
660
661 # only lc() the last portion of an href
662 sub lc_last($)
663 {
664   my $href = shift;
665   my @hrefsplit = split('/', $href);
666   # change the last portion (the filename), if it exists;
667   # if it is a plain filename with no path, change the string as a whole
668   if ($#hrefsplit > 0) {
669     @hrefsplit[$#hrefsplit] = lc( @hrefsplit[$#hrefsplit] );
670     $href = join("/", @hrefsplit);
671   } else {
672     $href = lc($href);
673   }
674   return $href;
675 }
676
677 # Convert a given node name to its proper file name (normalization as explained
678 # in the texinfo manual:
679 # http://www.gnu.org/software/texinfo/manual/texinfo/html_node/HTML-Xref-Node-Name-Expansion.html
680 sub texinfo_file_name($)
681 {
682   my $text = shift;
683   my $result = '';
684   # File name normalization by texinfo:
685   # 1/2: letters and numbers are left unchanged
686   # 3/4: multiple, leading and trailing whitespace is removed
687   $text = main::normalise_space($text);
688   # 5/6: all remaining spaces are converted to '-', all other 7- or 8-bit
689   #      chars are replaced by _xxxx (xxxx=ascii character code)
690   while ($text ne '') {
691     if ($text =~ s/^([A-Za-z0-9]+)//o) { # number or letter stay unchanged
692       $result .= $1;
693     } elsif ($text =~ s/^ //o) { # space -> '-'
694       $result .= '-';
695     } elsif ($text =~ s/^(.)//o) { # Otherwise use _xxxx (ascii char code)
696       my $ccode = ord($1);
697       if ( $ccode <= 0xFFFF ) {
698         $result .= sprintf("_%04x", $ccode);
699       } else {
700         $result .= sprintf("__%06x", $ccode);
701       }
702     }
703   }
704   # 7: if name does not begin with a letter, prepend 't_g' (so it starts with a letter)
705   if ($result !~ /^[a-zA-Z]/) {
706     $result = 't_g' . $result;
707   }
708   # DONE
709   return lc_last($result)
710 }
711
712 # Load a file containing a nodename<=>filename map (tab-sepatared, i.e.
713 # NODENAME\tFILENAME\tANCHOR
714 # Returns a ref to a hash "Node title" => ["FilenameWithoutExt", "Anchor"]
715 sub load_map_file ($)
716 {
717   my $mapfile = shift;
718   my $node_map = ();
719
720   # For some unknown reason, Perl on my system (5.10.0 on Fedora 12)
721   # refuses to open map files of translated documents with
722   # '<:encoding(utf8)', but decoding from UTF-8 line by line works. -jm
723   if (open(XREFFILE,'<', $mapfile)) {
724     my $line;
725     # print STDERR "*** PRINTING MAP FILE LINES ***\n";
726     while ( $line = decode ('UTF-8', <XREFFILE>) ) {
727       # parse the tab-separated entries and insert them into the map:
728       chomp($line);
729       my @entries = split(/\t/, $line);
730       if (scalar (@entries) == 3) {
731         $node_map->{$entries[0]} = [$entries[1], $entries[2]];
732         $, = " ";
733         # print STDERR @entries;
734         # print STDERR "\n";
735       } else {
736         print STDERR "Invalid entry in the node file $mapfile: $line\n";
737       }
738     }
739     close (XREFFILE);
740   } else {
741     print STDERR "WARNING: Unable to load the map file $mapfile\n";
742   }
743   return $node_map;
744 }
745
746
747 # Split the given path into dir and basename (with .texi removed). Used mainly
748 # to get the path/basename of the original texi input file
749 sub split_texi_filename ($)
750 {
751   my $docu = shift;
752   my ($docu_dir, $docu_name);
753   if ($docu =~ /(.*\/)/) {
754     chop($docu_dir = $1);
755     $docu_name = $docu;
756     $docu_name =~ s/.*\///;
757   } else {
758      $docu_dir = '.';
759      $docu_name = $docu;
760   }
761   $docu_name =~ s/\.te?x(i|info)?$//;
762   return ($docu_dir, $docu_name);
763 }
764
765
766
767
768
769 #############################################################################
770 ###  CSS HANDLING
771 #############################################################################
772
773 # Include our standard CSS file, not hard-coded CSS code directly in the HTML!
774 # For IE, conditionally include the lilypond-ie-fixes.css style sheet
775 sub lilypond_css_lines ($$)
776 {
777   my $import_lines = shift;
778   my $rule_lines = shift;
779   return if (defined($Texi2HTML::THISDOC{'CSS_LINES'}));
780   if (@$rule_lines or @$import_lines)
781   {
782     $Texi2HTML::THISDOC{'CSS_LINES'} = "<style type=\"text/css\">\n<!--\n";
783     $Texi2HTML::THISDOC{'CSS_LINES'} .= join('',@$import_lines) . "\n" if (@$import_lines);
784     $Texi2HTML::THISDOC{'CSS_LINES'} .= join('',@$rule_lines) . "\n" if (@$rule_lines);
785     $Texi2HTML::THISDOC{'CSS_LINES'} .= "-->\n</style>\n";
786   }
787   foreach my $ref (@CSS_REFS)
788   {
789     $Texi2HTML::THISDOC{'CSS_LINES'} .=
790         "<link rel=\"stylesheet\" type=\"text/css\" title=\"$ref->{TITLE}\" href=\"$ref->{FILENAME}\">\n";
791   }
792   foreach my $ref (@Texi2HTML::Config::ALT_CSS_REFS)
793   {
794     $Texi2HTML::THISDOC{'CSS_LINES'} .=
795         "<link rel=\"alternate stylesheet\" type=\"text/css\" href=\"$ref->{FILENAME}\" title=\"$ref->{TITLE}\">\n";
796   }
797
798   # The ie-fixes stylesheet is needed for the docs, but not the website.
799   if (not ($web_manual)) {
800     $Texi2HTML::THISDOC{'CSS_LINES'} .=
801         "<!--[if lte IE 7]>\n<link href=\"lilypond-ie-fixes.css\" rel=\"stylesheet\" type=\"text/css\">\n<![endif]-->\n";
802   }
803
804   if ($ENV{'AJAX_SEARCH'} == 1) {
805     # Add the JavaScript file only if we have an index.
806     # Unfortunately, init_out is called after css_lines, so as a workaround
807     # here we have to check again for the existence of an index...
808     my $ix = main::get_index ("cp");
809     $have_index_entries = (scalar $ix > 0);
810     my $reldir = "";
811     $reldir = "../" unless $bigpage;
812     if ($have_index_entries) {
813       $Texi2HTML::THISDOC{'CSS_LINES'} .= "<script language=\"JavaScript\" src=\"${reldir}lily_search.js\"></script>\n";
814     }
815   }
816 }
817
818
819
820
821
822 #############################################################################
823 ###  SPLITTING BASED ON NUMBERED SECTIONS
824 #############################################################################
825
826 my $lastfilename;
827 my $docnr = 0;
828 my $node_to_filename_map = ();
829 $source_to_translationof_map = ();
830
831
832 # This function makes sure that files are only generated for numbered sections,
833 # but not for unnumbered ones. It is called after texi2html has done its own
834 # splitting and simply returns the filename for the node given as first argument
835 # Nodes with the same filename will be printed out to the same filename, so
836 # this really all we need. Also, make sure that the file names for sections
837 # are derived from the section title. We also might want to name the anchors
838 # according to node titles, which works by simply overriding the id element of
839 # the $element hash.
840 # If an external nodename<=>filename/anchor map file is found (loaded in
841 # the command handler, use the externally created values, otherwise use the
842 # same logic here.
843 sub lilypond_element_file_name($$$)
844 {
845   my $element = shift;
846   my $type = shift;
847   my $docu_name = shift;
848   my $docu_ext = $Texi2HTML::Config::EXTENSION;
849
850   my $node_name = main::remove_texi($element->{'node_ref'}->{'texi'});
851   # the snippets page does not use nodes for the snippets, so in this case
852   # we'll have to use the section name!
853   if ($node_name eq '') {
854     $node_name = main::remove_texi($element->{'texi'});
855   }
856
857   # If we have an entry in the section<=>filename map, use that one, otherwise
858   # generate the filename/anchor here. In the latter case, external manuals
859   # will not be able to retrieve the file name for xrefs!!! Still, I already
860   # had that code, so I'll leave it in in case something goes wrong with the
861   # extract_texi_filenames.py script in the lilypond build process!
862   if (exists ($node_to_filename_map->{$node_name})) {
863     (my $filename, my $anchor) = @{$node_to_filename_map->{$node_name}};
864     $filename .= ".$docu_ext" if (defined($docu_ext));
865     # don't do lc_last here, otherwise the colors are messed up!
866     $filename = lc($filename);
867
868     # unnumbered sections (except those at top-level!) always go to the same
869     # file as the previous numbered section
870     if (not ($web_manual) and not ($element->{number})
871         and not ($lastfilename eq '') and ($element->{level} > 1)) {
872       $filename = $lastfilename;
873     }
874     if (($filename eq $lastfilename)) {
875       $$element{doc_nr} = $docnr;
876     } else {
877       $docnr += 1;
878       $$element{doc_nr} = $docnr;
879       $lastfilename = $filename;
880     }
881     #print STDERR "Output file name: $filename\n";
882     $filename = lc_last($filename);
883     return $filename;
884
885   } elsif ($type eq "top" or $type eq "toc" or $type eq "doc" or
886            $type eq "stoc" or $type eq "foot" or $type eq "about") {
887     return;
888   } else {
889     print STDERR "WARNING: Node '$node_name' was NOT found in the map\n"
890         unless ($node_name eq '') or ($element->{'tag'} eq 'unnumberedsec')
891                or ($node_name =~ /NOT REALLY USED/);
892
893     # Numbered sections will get a filename Node_title, unnumbered sections will use
894     # the file name of the previous numbered section:
895     if (($element->{number}) or ($lastfilename eq '') or ($element->{level} == 1)) {
896       # normalize to the same file name as texinfo
897       if ($element->{translationof}) {
898         $node_name = main::remove_texi($element->{translationof});
899       }
900       my $filename = texinfo_file_name($node_name);
901       $filename .= ".$docu_ext" if (defined($docu_ext));
902       $filename = lc_last($filename);
903       $docnr += 1;
904       $$element{doc_nr} = $docnr;
905       $lastfilename = $filename;
906       print STDERR "File name: $filename\n";
907       return $filename;
908     } else {
909       $$element{doc_nr} = $docnr;
910       $filename = lc_last($filename);
911       print STDERR "File name: $filename\n";
912       return $filename;
913     }
914   }
915
916   return;
917 }
918
919 sub lilypond_normalise_node($)
920 {
921     my $text = shift;
922     my $norm = main::t2h_default_normalise_node($text);
923     if (exists ($source_to_translationof_map->{$text})) {
924         my $original = $source_to_translationof_map->{$text};
925         $norm = main::t2h_default_normalise_node($original);
926     }
927
928     return $norm;
929 }
930
931 # This function produces an anchor.
932 #
933 # arguments:
934 # $name           :   anchor name
935 # $href           :   anchor href
936 # text            :   text displayed
937 # extra_attribs   :   added to anchor attributes list
938 sub lilypond_anchor($;$$$)
939 {
940     my $name = shift;
941     my $href = shift;
942     my $text = shift;
943     my $attributes = shift;
944     $href = remove_unneeded_anchor($href);
945     if (!defined($attributes) or ($attributes !~ /\S/))
946     {
947         $attributes = '';
948     }
949     else
950     {
951         $attributes = ' ' . $attributes;
952     }
953     $name = '' if (!defined($name) or ($name !~ /\S/));
954     $href = '' if (!defined($href) or ($href !~ /\S/));
955     $text = '' if (!defined($text));
956     return $text if (($name eq '') and ($href eq ''));
957     $name = "name=\"$name\"" if ($name ne '');
958     $href = "href=\"$href\"" if ($href ne '');
959     $href = ' ' . $href if (($name ne '') and ($href ne ''));
960     return "<a ${name}${href}${attributes}>$text</a>";
961 }
962
963
964 sub lilypond_element_target_name($$$)
965 {
966   my $element = shift;
967   my $target = shift;
968   my $id = shift;
969   # Target is based on node name (or sec name for secs without node attached)
970   my $node_name = main::remove_texi($element->{'node_ref'}->{'texi'});
971   if ($node_name eq '') {
972     $node_name = main::remove_texi($element->{'texi'});
973   }
974
975   # If we have an entry in the section<=>filename map, use that one, otherwise
976   # generate the anchor here.
977   if (exists ($node_to_filename_map->{$node_name})) {
978     (my $filename, $target) = @{$node_to_filename_map->{$node_name}};
979   } else {
980     my $anchor = $node_name;
981     if ($element->{translationof}) {
982       $anchor = main::remove_texi($element->{translationof});
983     }
984     # normalize to the same file name as texinfo
985     $target = texinfo_file_name($anchor);
986   }
987   # TODO: Once texi2html correctly prints out the target and not the id for
988   #       the sections, change this back to ($id, $target)
989   # I don't understand this comment, so I'm reluctant to delete it -gp
990   $target = lc_last($target);
991   $id = lc($target);
992 # $id =~ s/-1$//i; # remove any trailing "-1"
993   return ($target, $id);
994 }
995
996
997 ## Load the map file for the corrently processed texi file. We do this
998 #  using a command init handler, since texi2html does not have any
999 #  other hooks that are called after THISDOC is filled but before phase 2
1000 #  of the texi2html conversion.
1001 sub lilypond_init_map ()
1002 {
1003     my ($docu_dir, $docu_name) = split_texi_filename ($Texi2HTML::THISDOC{'input_file_name'});
1004     my $map_filename = main::locate_include_file ("${docu_name}.$Texi2HTML::THISDOC{current_lang}.xref-map")
1005         || main::locate_include_file ("${docu_name}.xref-map");
1006     #print STDERR "Map filename is: $map_filename\nDocu name is $docu_name\n";
1007     if ($docu_name eq 'web') {
1008         $web_manual = 1;
1009         web_settings();
1010     }
1011     $node_to_filename_map = load_map_file ($map_filename);
1012 }
1013 push @Texi2HTML::Config::command_handler_init, \&lilypond_init_map;
1014
1015
1016
1017 #############################################################################
1018 ###  CLEANER LINK TITLE FOR EXTERNAL REFS
1019 #############################################################################
1020
1021 # The default formatting of external refs returns e.g.
1022 # "(lilypond-internals)Timing_translator", so we remove all (...) from the
1023 # file_and_node argument. Also, we want only a very simple format, so we don't
1024 # even call the default handler!
1025 sub lilypond_external_ref($$$$$$)
1026 {
1027   my $type = shift;
1028   my $section = shift;
1029   my $book = shift;
1030   my $file_node = shift;
1031   my $href = shift;
1032
1033   $href = lc_last($href);
1034
1035   my $cross_ref = shift;
1036
1037   my $displaytext = '';
1038
1039   # 1) if we have a cross ref name, that's the text to be displayed:
1040   # 2) For the top node, use the (printable) name of the manual, unless we
1041   #    have an explicit cross ref name
1042   # 3) In all other cases use the section name
1043   if ($cross_ref ne '') {
1044     $displaytext = $cross_ref;
1045   } elsif (($section eq '') or ($section eq 'Top')) {
1046     $displaytext = $book;
1047   } else {
1048     $displaytext = $section;
1049   }
1050
1051   $displaytext = &$anchor('', $href, $displaytext) if ($displaytext ne '');
1052   return &$I('%{node_file_href}', { 'node_file_href' => $displaytext });
1053 }
1054
1055
1056
1057
1058
1059 #############################################################################
1060 ###  HANDLING TRANSLATED SECTIONS: handle @translationof, secname<->filename
1061 ###                  map stored on disk, xrefs in other manuals load that map
1062 #############################################################################
1063
1064
1065 # Try to make use of @translationof to generate files according to the original
1066 # English section title...
1067 sub lilypond_unknown($$$$$)
1068 {
1069     my $macro = shift;
1070     my $line = shift;
1071     my $pass = shift;
1072     my $stack = shift;
1073     my $state = shift;
1074
1075     # the @translationof macro provides the original English section title,
1076     # which should be used for file/anchor naming, while the title will be
1077     # translated to each language
1078     # It is already used by extract_texi_filenames.py, so this should not be
1079     # necessary here at all. Still, I'll leave the code in just in case the
1080     # python script messed up ;-)
1081     if ($pass == 1 and $macro eq "translationof") {
1082       if (ref($state->{'element'}) eq 'HASH') {
1083           $state->{'element'}->{'translationof'} = main::normalise_space($line);
1084           my $source = main::normalise_space ($line);
1085           if (ref($state->{'node_ref'}) eq 'HASH') {
1086               my $translationof = $state->{'node_ref'}->{'texi'};
1087               our %source_to_translationof_map;
1088               $source_to_translationof_map->{$source} = $translationof;
1089           }
1090       }
1091       return ('', 1, undef, undef);
1092     } else {
1093       return &$default_unknown($macro, $line, $pass, $stack, $state);
1094     }
1095 }
1096
1097
1098 my %translated_books = ();
1099 # Construct a href to an external source of information.
1100 # node is the node with texinfo @-commands
1101 # node_id is the node transliterated and transformed as explained in the
1102 #         texinfo manual
1103 # node_xhtml_id is the node transformed such that it is unique and can
1104 #     be used to make an html cross ref as explained in the texinfo manual
1105 # file is the file in '(file)node'
1106 sub lilypond_external_href($$$)
1107 {
1108   my $node = shift;
1109   my $node_id = shift;
1110   my $node_xhtml_id = shift;
1111   my $file = shift;
1112
1113   # 1) Keep a hash of book->section_map
1114   # 2) if not file in keys hash => try to load the map (assign empty map if
1115   #    non-existent => will load only once!)
1116   # 3) if node in the section=>(file, anchor) map, replace node_id and
1117   #    node_xhtml_id by the map's values
1118   # 4) call the default_external_href with these values (or the old ones if not found)
1119
1120   if (($node_id ne '') and defined($file) and ($node_id ne 'Top')) {
1121     my $map_name = $file;
1122     $map_name =~ s/-big-page//;
1123
1124     # Load the map if we haven't done so already
1125     if (!exists($translated_books{$map_name})) {
1126       my ($docu_dir, $docu_name) = split_texi_filename ($Texi2HTML::THISDOC{'input_file_name'});
1127       my $map_filename = main::locate_include_file ("${map_name}.$Texi2HTML::THISDOC{current_lang}.xref-map")
1128           || main::locate_include_file ("${map_name}.xref-map");
1129       $translated_books{$map_name} = load_map_file ($map_filename);
1130     }
1131
1132     # look up translation. use these values instead of the old filename/anchor
1133     my $section_name_map = $translated_books{$map_name};
1134     my $node_text = main::remove_texi($node);
1135     if (defined($section_name_map->{$node_text})) {
1136       ($node_id, $node_xhtml_id) = @{$section_name_map->{$node_text}};
1137     } else {
1138       print STDERR "WARNING: Unable to find node '$node_text' in book $map_name.\n";
1139     }
1140   }
1141
1142   if (defined $file) {
1143     $href = &$default_external_href($node, $node_id, $node_xhtml_id, lc_last($file));
1144     $href = remove_unneeded_anchor($href);
1145
1146     # TODO: very yucky, but will be fixed in issue 1004
1147     if ($web_manual) {
1148       my $only_web = $ENV{ONLY_WEB};
1149       if ($only_web) {
1150         $href = "../../doc/v2.13/Documentation/web/".$href;
1151       }
1152     }
1153
1154     return $href;
1155   } else {
1156     $href = &$default_external_href($node, $node_id, $node_xhtml_id);
1157     $href = remove_unneeded_anchor($href);
1158     return $href;
1159   }
1160 }
1161
1162 sub remove_unneeded_anchor($)
1163 {
1164   my $href = shift;
1165   my @hrefsplit = split("/", $href);
1166   for ($i = 0; $i < @hrefsplit; $i++) {
1167     $item = @hrefsplit[$i];
1168     if ($item =~ /#/) {
1169       @splitted = split(".html#", $item);
1170       if (@splitted[0] eq @splitted[1]) {
1171         @hrefsplit[$i] = @splitted[0] . ".html";
1172       }
1173     }
1174   }
1175   $href = join("/", @hrefsplit);
1176   return $href
1177 }
1178
1179
1180
1181 #############################################################################
1182 ###  CUSTOM TOC FOR EACH PAGE (in a frame on the left)
1183 #############################################################################
1184
1185 my $page_toc_depth = 2;
1186 my @default_toc = [];
1187
1188 # Initialize the toc_depth to 1 if the command-line option -D=short_toc is given
1189 sub lilypond_init_toc_depth ()
1190 {
1191   if (exists($main::value{'short_toc'}) and not exists($main::value{'bigpage'})
1192       and not $web_manual) {
1193     $page_toc_depth = 1;
1194   }
1195 }
1196 # Set the TOC-depth (depending on a texinfo variable short_toc) in a
1197 # command-handler, so we have them available when creating the pages
1198 push @Texi2HTML::Config::command_handler_process, \&lilypond_init_toc_depth;
1199
1200
1201
1202 # recursively generate the TOC entries for the element and its children (which
1203 # are only shown up to maxlevel. All ancestors of the current element are also
1204 # shown with their immediate children, irrespective of their level.
1205 # Unnumbered entries are only printed out if they are at top-level or 2nd level
1206 # or their parent element is an ancestor of the currently viewed node.
1207 # The conditions to call this method to print the entry for a child node is:
1208 # -) the parent is an ancestor of the current page node
1209 # -) the parent is a numbered element at top-level toplevel (i.e. show numbered
1210 #    and unnumbered 2nd-level children of numbered nodes)
1211 # -) the child element is a numbered node below level maxlevel
1212 sub generate_ly_toc_entries($$$$$)
1213 {
1214   my $element = shift;
1215   my $element_path = shift;
1216   my $maxlevel = shift;
1217   if ($web_manual) {
1218     $maxlevel = 1;
1219   }
1220   my $child_count = shift;
1221   my $current_element = shift;
1222   # Skip undefined sections, plus all sections generated by index splitting
1223   return() if (not defined($element) or exists($element->{'index_page'}));
1224   my @result = ();
1225   my $level = $element->{'toc_level'};
1226   my $is_parent_of_current = $element->{'id'} && $element_path->{$element->{'id'}};
1227   my $ind = '  ' x $level;
1228   my $this_css_class = " class=\"";
1229   # color indices for the second navigation bar on the website
1230   if ($web_manual) {
1231       my %color_maps = (
1232           'introduction' => [2, 2, 2, 2, 3, 3, 4, 4],
1233           'download' => [2, 2, 2, 3, 3, 4],
1234           'manuals' => [1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4],
1235           'community' => [1, 1, 1, 2, 2, 2, 3, 3],
1236           );
1237       my $addColor = "colorDefault";
1238       while (($top_section, $color_indices) = each %color_maps) {
1239           if (index ($element->{'sectionup'}->{'file'}, $top_section) >= 0) {
1240               $addColor = "color" . $color_indices->[$child_count];
1241           }
1242       }
1243       $this_css_class .= $addColor;
1244   }
1245   $this_css_class .= $is_parent_of_current ? ' toc_current"' : '"';
1246   my $entry = "$ind<li$this_css_class>" .
1247       &$anchor ($element->{'tocid'},
1248                 "$element->{'file'}#$element->{'target'}",
1249                 $element->{'text'});
1250
1251   push (@result, $entry);
1252   my $children = $element->{'section_childs'};
1253   if (defined($children) and (ref($children) eq "ARRAY")) {
1254     my $force_children = $is_parent_of_current or ($level == 1 and $element->{'number'});
1255     my @child_result = ();
1256     my $sub_child_count = 0;
1257     foreach my $c (@$children) {
1258       my $is_numbered_child = defined ($c->{'number'});
1259       my $below_maxlevel = $c->{'toc_level'} le $maxlevel;
1260       if ($force_children or ($is_numbered_child and $below_maxlevel)) {
1261         my @child_res =
1262             generate_ly_toc_entries($c, $element_path, $maxlevel, $sub_child_count, $current_element);
1263         push (@child_result, @child_res);
1264         $sub_child_count += 1;
1265       }
1266     }
1267     # if no child nodes were generated, e.g. for the index, where expanded pages
1268     # are ignored, don't generate a list at all...
1269     if (@child_result) {
1270       push (@result, "\n$ind<ul$NO_BULLET_LIST_ATTRIBUTE>\n");
1271       if ($web_manual) {
1272         push (@result, "$ind<li class=\"colorDefault" .
1273               ($element->{'text'} eq $current_element->{'text'} ?
1274                ' toc_current">' : '">') .
1275               &$anchor ($element->{'tocid'},
1276                         "$element->{'file'}#$element->{'target'}",
1277                         $element->{'text'}) . "</li>\n");
1278       }
1279       push (@result, @child_result);
1280       push (@result, "$ind</ul>\n");
1281     }
1282   }
1283   push (@result, "$ind</li>\n");
1284   return @result;
1285 }
1286
1287
1288 # Print a customized TOC, containing only the first two levels plus the whole
1289 # path to the current page
1290 sub lilypond_generate_page_toc_body($)
1291 {
1292     my $element = shift;
1293     my $current_element = $element;
1294     my %parentelements;
1295     $parentelements{$element->{'id'}} = 1;
1296     # Find the path to the current element
1297     while ( defined($current_element->{'sectionup'}) and
1298            ($current_element->{'sectionup'} ne $current_element) )
1299     {
1300       $parentelements{$current_element->{'sectionup'}->{'id'}} = 1
1301               if ($current_element->{'sectionup'}->{'id'} ne '');
1302       $current_element = $current_element->{'sectionup'};
1303       if ($web_manual) {
1304         if (exists($main::value{'shallow_toc'})) {
1305           last;
1306         }
1307       }
1308     }
1309     return () if not defined($current_element);
1310     # Create the toc entries recursively
1311     my @toc_entries = "";
1312     if ($web_manual) {
1313         @toc_entries = "<ul$NO_BULLET_LIST_ATTRIBUTE>\n";
1314         # FIXME: add link to main page, really hackily.
1315         if ($element->{'sectionup'}) {
1316             # it's not the top element
1317             push (@toc_entries, "<li><a href=\"index.html\">Main</a></li>\n");
1318         } else {
1319             push (@toc_entries,
1320                   "<li class=\"toc_current\"><a href=\"index.html\">Main</a></li>\n");
1321         }
1322     } else {
1323         push (@toc_entries, "<div class=\"contents\">\n");
1324         push (@toc_entries, "<ul$NO_BULLET_LIST_ATTRIBUTE>\n");
1325     }
1326     my $children = $current_element->{'section_childs'};
1327     foreach ( @$children ) {
1328       push (@toc_entries, generate_ly_toc_entries($_, \%parentelements, $page_toc_depth, 0, $element));
1329     }
1330     # search box
1331     #  I'm assuming that we wouldn't keep the google search box? -gp
1332     if (!($ENV{AJAX_SEARCH} == 1)) {
1333       local $/=undef;
1334       my $name = "search-box";
1335       $lang = $Texi2HTML::THISDOC{current_lang};
1336       open FILE, "$ENV{TOP_SRC_DIR}/Documentation/$lang/$name.ihtml" or
1337         open FILE, "$ENV{TOP_SRC_DIR}/Documentation/$name.ihtml"  or
1338         die "no such file: $name.ihtml: $!";
1339       my $search_string = decode ('UTF-8', <FILE>);
1340       $search_string = "<li>\n" . $search_string . "</li>\n";
1341       push (@toc_entries, $search_string);
1342       close FILE;
1343     }
1344
1345     push (@toc_entries, "</ul>\n");
1346     if ($web_manual) {
1347         push (@toc_entries, "\n");
1348     } else {
1349         push (@toc_entries, "</div>\n");
1350     }
1351     return @toc_entries;
1352 }
1353
1354 sub lilypond_print_toc_div ($$)
1355 {
1356   my $fh = shift;
1357   my $tocref = shift;
1358   my @lines = @$tocref;
1359   # use default TOC if no custom lines have been generated
1360   @lines = @default_toc if (not @lines);
1361   if (@lines) {
1362
1363     print $fh "\n\n<div id=\"tocframe\">\n";
1364
1365     # Remove the leading "GNU LilyPond --- " from the manual title
1366     my $topname = $Texi2HTML::NAME{'Top'};
1367     $topname =~ s/^GNU LilyPond(:| &[mn]dash;) //;
1368
1369     # construct the top-level Docs index (relative path and including language!)
1370     my $lang = $Texi2HTML::THISDOC{current_lang};
1371     if ($lang and $lang ne "en") {
1372       $lang .= ".";
1373     } else {
1374       $lang = "";
1375     }
1376     my $reldir = $ENV{DEPTH};
1377     my $uplink = $reldir."/Documentation/web/manuals.${lang}html";
1378
1379     if (not $web_manual) {
1380       print $fh "<p class=\"toc_uplink\"><a href=\"$uplink\"
1381          title=\"Documentation Index\">&lt;&lt; " .
1382          &ly_get_string ('Back to Documentation Index') .
1383          "</a></p>\n";
1384
1385       # AJAX search box, written in JavaScript
1386       if ($ENV{'AJAX_SEARCH'} == 1) {
1387         if ($have_index_entries) {
1388           my ($docu_dir, $docu_name) = split_texi_filename ($Texi2HTML::THISDOC{'input_file_name'});
1389           print $fh '<script language="JavaScript">print_search_field ("' .
1390              $Texi2HTML::THISDOC{current_lang} . '", "' . 
1391              $docu_name . "\", " . $bigpage . ")</script>\n";
1392         }
1393       }
1394
1395       print $fh '<h4 class="toc_header"> ' . &$anchor('',
1396                                     $Texi2HTML::HREF{'Top'},
1397                                     $topname,
1398                                     'title="Start of the manual"'
1399                                    ) . "</h4>\n";
1400     }
1401
1402     foreach my $line (@lines) {
1403       print $fh $line;
1404     }
1405     print $fh "</div>\n\n";
1406   }
1407 }
1408
1409 # Create the custom TOC for this page (partially folded, current page is
1410 # highlighted) and store it in a global variable. The TOC is written out after
1411 # the html contents (but positioned correctly using CSS), so that browsers with
1412 # css turned off still show the contents first.
1413 our @this_page_toc = ();
1414 sub lilypond_print_element_header
1415 {
1416   my $first_in_page = shift;
1417   my $previous_is_top = shift;
1418   if ($first_in_page and not @this_page_toc) {
1419     if (defined($Texi2HTML::THIS_ELEMENT)) {
1420       # Create the TOC for this page
1421       @this_page_toc = lilypond_generate_page_toc_body($Texi2HTML::THIS_ELEMENT);
1422     }
1423   }
1424   return &$default_print_element_header( $first_in_page, $previous_is_top);
1425 }
1426
1427 # Generate the HTML output for the TOC
1428 sub lilypond_toc_body($)
1429 {
1430     my $elements_list = shift;
1431     # Generate a default TOC for pages without THIS_ELEMENT
1432     @default_toc = lilypond_generate_page_toc_body(@$elements_list[0]);
1433     return &$default_toc_body($elements_list);
1434 }
1435
1436 # Print out the TOC in a <div> at the beginning of the page
1437 sub lilypond_print_page_head($)
1438 {
1439     my $fh = shift;
1440     &$default_print_page_head($fh);
1441     print $fh "<div id=\"main\">\n";
1442 }
1443
1444 # Print out the TOC in a <div> at the end of th page, which will be formatted as a
1445 # sidebar mimicking a TOC frame
1446 sub print_lilypond_page_foot($)
1447 {
1448   my $fh = shift;
1449   my $program_string = &$program_string();
1450 #   print $fh "<p><font size='-1'>$program_string</font><br>$PRE_BODY_CLOSE</p>\n";
1451   print $fh "<!-- FOOTER -->\n\n";
1452   print $fh "<!-- end div#main here -->\n</div>\n\n";
1453   if ($web_manual) {
1454     # FIXME: This div and p#languages need to be in div#footer.
1455     #        Should we move this div to postprocess_html.py ?
1456     print $fh "<div id=\"verifier_texinfo\">\n";
1457     print $fh "<h3>Validation</h3>\n";
1458     # FIXME: inlined text substitution, move to ly_get_string as soon as another case is needed
1459     my $webdev_link = "<a href=\"http://www.webdev.nl/\">webdev.nl</a>";
1460     my $lily_site = "<code>lilypond.org</code>";
1461     my $hosting_thanks = &ly_get_string ('<p>Thanks to ${webdev_link} for hosting ${lily_site}.');
1462     # this does the variable substitution ("quoting" in Perlish) after the localization
1463     $hosting_thanks =~ s/(\$\{\w+\})/$1/eeg;
1464     print $fh $hosting_thanks . "\n";
1465     print $fh "<a href=\"http://validator.w3.org/check?uri=referer\">\n";
1466     print $fh "<img src=\"http://www.w3.org/Icons/valid-html401\"\n";
1467     print $fh "     alt=\"Valid HTML 4.01 Transitional\"\n";
1468     print $fh "     height=\"31\" width=\"88\"></a></p>\n";
1469     print $fh "</div>";
1470   }
1471
1472   # Print the TOC frame and reset the TOC:
1473   lilypond_print_toc_div ($fh, \@this_page_toc);
1474   @this_page_toc = ();
1475
1476   # Close the page:
1477   print $fh "</body>\n</html>\n";
1478 }
1479
1480
1481
1482
1483
1484 #############################################################################
1485 ###  NICER / MORE FLEXIBLE NAVIGATION PANELS
1486 #############################################################################
1487
1488 sub get_navigation_text
1489 {
1490   my $button = shift;
1491   my $text = $NAVIGATION_TEXT{$button};
1492   if ( ($button eq 'Back') or ($button eq 'FastBack') ) {
1493     $text = $text . $Texi2HTML::NODE{$button} . "&nbsp;";
1494   } elsif ( ($button eq 'Forward') or ($button eq 'FastForward') ) {
1495     $text = "&nbsp;" . $Texi2HTML::NODE{$button} . $text;
1496   } elsif ( $button eq 'Up' ) {
1497     $text = "&nbsp;".$text.":&nbsp;" . $Texi2HTML::NODE{$button} . "&nbsp;";
1498   }
1499   return $text;
1500 }
1501
1502
1503 # Don't automatically create left-aligned table cells for every link, but
1504 # instead create a <td> only on an appropriate '(left|right|center)-aligned-cell-n'
1505 # button text. It's alignment as well as the colspan will be taken from the
1506 # name of the button. Also, add 'newline' button text to create a new table
1507 # row. The texts of the buttons are generated by get_navigation_text and
1508 # will contain the name of the next/previous section/chapter.
1509 sub lilypond_print_navigation
1510 {
1511     my $buttons = shift;
1512     my $vertical = shift;
1513     my $spacing = 1;
1514     my $result = "<table class=\"nav_table\">\n";
1515
1516     $result .= "<tr>" unless $vertical;
1517     my $beginofline = 1;
1518     foreach my $button (@$buttons)
1519     {
1520         $result .= qq{<tr valign="top" align="left">\n} if $vertical;
1521         # Allow (left|right|center)-aligned-cell and newline as buttons!
1522         if ( $button =~ /^(.*)-aligned-cell-(.*)$/ )
1523         {
1524           $result .= qq{</td>} unless $beginofline;
1525           $result .= qq{<td valign="middle" align="$1" colspan="$2">};
1526           $beginofline = 0;
1527         }
1528         elsif ( $button eq 'newline' )
1529         {
1530           $result .= qq{</td>} unless $beginofline;
1531           $result .= qq{</tr>};
1532           $result .= qq{<tr>};
1533           $beginofline = 1;
1534
1535         }
1536         elsif (ref($button) eq 'CODE')
1537         {
1538             $result .= &$button($vertical);
1539         }
1540         elsif (ref($button) eq 'SCALAR')
1541         {
1542             $result .= "$$button" if defined($$button);
1543         }
1544         elsif (ref($button) eq 'ARRAY')
1545         {
1546             my $text = $button->[1];
1547             my $button_href = $button->[0];
1548             # verify that $button_href is simple text and text is a reference
1549             if (defined($button_href) and !ref($button_href)
1550                and defined($text) and (ref($text) eq 'SCALAR') and defined($$text))
1551             {             # use given text
1552                 if ($Texi2HTML::HREF{$button_href})
1553                 {
1554                   my $anchor_attributes = '';
1555                   if ($USE_ACCESSKEY and (defined($BUTTONS_ACCESSKEY{$button_href})) and
1556                       ($BUTTONS_ACCESSKEY{$button_href} ne ''))
1557                   {
1558                       $anchor_attributes = "accesskey=\"$BUTTONS_ACCESSKEY{$button_href}\"";
1559                   }
1560                   if ($USE_REL_REV and (defined($BUTTONS_REL{$button_href})) and
1561                       ($BUTTONS_REL{$button_href} ne ''))
1562                   {
1563                       $anchor_attributes .= " rel=\"$BUTTONS_REL{$button_href}\"";
1564                   }
1565                   $result .=  "" .
1566                         &$anchor('',
1567                                     $Texi2HTML::HREF{$button_href},
1568                                     get_navigation_text($$text),
1569                                     $anchor_attributes
1570                                    );
1571                 }
1572                 else
1573                 {
1574                   $result .=  get_navigation_text($$text);
1575                 }
1576             }
1577         }
1578         elsif ($button eq ' ')
1579         {                       # handle space button
1580             $result .=
1581                 ($ICONS && $ACTIVE_ICONS{' '}) ?
1582                     &$button_icon_img($BUTTONS_NAME{$button}, $ACTIVE_ICONS{' '}) :
1583                         $NAVIGATION_TEXT{' '};
1584             #next;
1585         }
1586         elsif ($Texi2HTML::HREF{$button})
1587         {                       # button is active
1588             my $btitle = $BUTTONS_GOTO{$button} ?
1589                 'title="' . $BUTTONS_GOTO{$button} . '"' : '';
1590             if ($USE_ACCESSKEY and (defined($BUTTONS_ACCESSKEY{$button})) and
1591                 ($BUTTONS_ACCESSKEY{$button} ne ''))
1592             {
1593                 $btitle .= " accesskey=\"$BUTTONS_ACCESSKEY{$button}\"";
1594             }
1595             if ($USE_REL_REV and (defined($BUTTONS_REL{$button})) and
1596                 ($BUTTONS_REL{$button} ne ''))
1597             {
1598                 $btitle .= " rel=\"$BUTTONS_REL{$button}\"";
1599             }
1600             if ($ICONS && $ACTIVE_ICONS{$button})
1601             {                   # use icon
1602                 $result .= '' .
1603                     &$anchor('',
1604                         $Texi2HTML::HREF{$button},
1605                         &$button_icon_img($BUTTONS_NAME{$button},
1606                                    $ACTIVE_ICONS{$button},
1607                                    $Texi2HTML::SIMPLE_TEXT{$button}),
1608                         $btitle
1609                       );
1610             }
1611             else
1612             {                   # use text
1613                 $result .=
1614                     '[' .
1615                         &$anchor('',
1616                                     $Texi2HTML::HREF{$button},
1617                                     get_navigation_text($button),
1618                                     $btitle
1619                                    ) .
1620                                        ']';
1621             }
1622         }
1623         else
1624         {                       # button is passive
1625             $result .=
1626                 $ICONS && $PASSIVE_ICONS{$button} ?
1627                     &$button_icon_img($BUTTONS_NAME{$button},
1628                                           $PASSIVE_ICONS{$button},
1629                                           $Texi2HTML::SIMPLE_TEXT{$button}) :
1630
1631                                               "[" . get_navigation_text($button) . "]";
1632         }
1633         $result .= "</td>\n" if $vertical;
1634         $result .= "</tr>\n" if $vertical;
1635     }
1636     $result .= "</td>" unless $beginofline;
1637     $result .= "</tr>" unless $vertical;
1638     $result .= "</table>\n";
1639     if ($web_manual) {
1640       return "\n";
1641     } else {
1642       return $result;
1643     }
1644 }
1645
1646
1647 @Texi2HTML::Config::SECTION_BUTTONS =
1648     ('left-aligned-cell-1', 'FastBack',
1649      'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
1650      'right-aligned-cell-1', 'FastForward',
1651      'newline',
1652      'left-aligned-cell-2', 'Back',
1653      'center-aligned-cell-1', 'Up',
1654      'right-aligned-cell-2', 'Forward'
1655     );
1656
1657 # buttons for misc stuff
1658 @Texi2HTML::Config::MISC_BUTTONS = ('center-aligned-cell-3',
1659                                     'Top', 'Contents', 'Index', 'About');
1660
1661 # buttons for chapter file footers
1662 # (and headers but only if SECTION_NAVIGATION is false)
1663 @Texi2HTML::Config::CHAPTER_BUTTONS =
1664     ('left-aligned-cell-1', 'FastBack',
1665      'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
1666      'right-aligned-cell-1', 'FastForward',
1667     );
1668
1669 # buttons for section file footers
1670 @Texi2HTML::Config::SECTION_FOOTER_BUTTONS =
1671     ('left-aligned-cell-1', 'FastBack',
1672      'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
1673      'right-aligned-cell-1', 'FastForward',
1674      'newline',
1675      'left-aligned-cell-2', 'Back',
1676      'center-aligned-cell-1', 'Up',
1677      'right-aligned-cell-2', 'Forward'
1678     );
1679
1680 @Texi2HTML::Config::NODE_FOOTER_BUTTONS =
1681     ('left-aligned-cell-1', 'FastBack',
1682      'center-aligned-cell-3', 'Top', 'Contents', 'Index', 'About',
1683      'right-aligned-cell-1', 'FastForward',
1684      'newline',
1685      'left-aligned-cell-2', 'Back',
1686      'center-aligned-cell-1', 'Up',
1687      'right-aligned-cell-2', 'Forward'
1688     );
1689
1690
1691
1692
1693
1694 #############################################################################
1695 ###  FOOTNOTE FORMATTING
1696 #############################################################################
1697
1698 # Format footnotes in a nicer way: Instead of printing the number in a separate
1699 # (nr) heading line, use the standard way of prepending <sup>nr</sup> immediately
1700 # before the fn text.
1701
1702
1703 # The following code is copied from texi2html's examples/makeinfo.init and
1704 # should be updated when texi2html makes some changes there!
1705
1706 my $makekinfo_like_footnote_absolute_number = 0;
1707
1708 sub makeinfo_like_foot_line_and_ref($$$$$$$$)
1709 {
1710     my $foot_num = shift;
1711     my $relative_num = shift;
1712     my $footid = shift;
1713     my $docid = shift;
1714     my $from_file = shift;
1715     my $footnote_file = shift;
1716     my $lines = shift;
1717     my $state = shift;
1718
1719     $makekinfo_like_footnote_absolute_number++;
1720
1721     # this is a bit obscure, this allows to add an anchor only if formatted
1722     # as part of the document.
1723     $docid = '' if ($state->{'outside_document'} or $state->{'multiple_pass'});
1724
1725     if ($from_file eq $footnote_file)
1726     {
1727         $from_file = $footnote_file = '';
1728     }
1729
1730     my $foot_anchor = "<sup>" .
1731         &$anchor($docid, "$footnote_file#$footid", $relative_num) . "</sup>";
1732     $foot_anchor = &$anchor($docid,
1733                             "$footnote_file#$footid",
1734                             "($relative_num)") if ($state->{'preformatted'});
1735
1736 #    unshift @$lines, "<li>";
1737 #    push @$lines, "</li>\n";
1738     return ($lines, $foot_anchor);
1739 }
1740
1741 sub makeinfo_like_foot_lines($)
1742 {
1743     my $lines = shift;
1744     unshift @$lines, "<hr>\n<h4>$Texi2HTML::I18n::WORDS->{'Footnotes_Title'}</h4>\n";
1745 #<ol type=\"1\">\n";
1746 #    push @$lines, "</ol>";
1747     return $lines;
1748 }
1749
1750 my %makekinfo_like_paragraph_in_footnote_nr;
1751
1752 sub makeinfo_like_paragraph ($$$$$$$$$$$$$)
1753 {
1754     my $text = shift;
1755     my $align = shift;
1756     my $indent = shift;
1757     my $paragraph_command = shift;
1758     my $paragraph_command_formatted = shift;
1759     my $paragraph_number = shift;
1760     my $format = shift;
1761     my $item_nr = shift;
1762     my $enumerate_style = shift;
1763     my $number = shift;
1764     my $command_stack_at_end = shift;
1765     my $command_stack_at_begin = shift;
1766     my $state = shift;
1767 #print STDERR "format: $format\n" if (defined($format));
1768 #print STDERR "paragraph @$command_stack_at_end; @$command_stack_at_begin\n";
1769     $paragraph_command_formatted = '' if (!defined($paragraph_command_formatted) or
1770           exists($special_list_commands{$format}->{$paragraph_command}));
1771     return '' if ($text =~ /^\s*$/);
1772     foreach my $style(t2h_collect_styles($command_stack_at_begin))
1773     {
1774        $text = t2h_begin_style($style, $text);
1775     }
1776     foreach my $style(t2h_collect_styles($command_stack_at_end))
1777     {
1778        $text = t2h_end_style($style, $text);
1779     }
1780     if (defined($paragraph_number) and defined($$paragraph_number))
1781     {
1782          $$paragraph_number++;
1783          return $text  if (($format eq 'itemize' or $format eq 'enumerate') and
1784             ($$paragraph_number == 1));
1785     }
1786     my $open = '<p';
1787     if ($align)
1788     {
1789         $open .= " align=\"$paragraph_style{$align}\"";
1790     }
1791     my $footnote_text = '';
1792     if (defined($command_stack_at_begin->[0]) and $command_stack_at_begin->[0] eq 'footnote')
1793     {
1794         my $state = $Texi2HTML::THISDOC{'state'};
1795         $makekinfo_like_paragraph_in_footnote_nr{$makekinfo_like_footnote_absolute_number}++;
1796         if ($makekinfo_like_paragraph_in_footnote_nr{$makekinfo_like_footnote_absolute_number} <= 1)
1797         {
1798            $open.=' class="footnote"';
1799            my $document_file = $state->{'footnote_document_file'};
1800            if ($document_file eq $state->{'footnote_footnote_file'})
1801            {
1802                $document_file = '';
1803            }
1804            my $docid = $state->{'footnote_place_id'};
1805            my $doc_state = $state->{'footnote_document_state'};
1806            $docid = '' if ($doc_state->{'outside_document'} or $doc_state->{'multiple_pass'});
1807            my $foot_label = &$anchor($state->{'footnote_footnote_id'},
1808                  $document_file . "#$state->{'footnote_place_id'}",
1809                  "$state->{'footnote_number_in_page'}");
1810            $footnote_text = "<small>[${foot_label}]</small> ";
1811         }
1812     }
1813     return $open.'>'.$footnote_text.$text.'</p>';
1814 }
1815
1816
1817 #############################################################################
1818 ###  WRITING OUT THE INDEX FOR THE AJAX SEARCH FIELD
1819 #############################################################################
1820
1821 $Texi2HTML::Config::IDX_SUMMARY   = 1;
1822 $Texi2HTML::Config::init_out                  = \&lilypond_init_out;
1823 $Texi2HTML::Config::finish_out                = \&lilypond_finish_out;
1824 $Texi2HTML::Config::index_summary_file_entry  = \&lilypond_index_summary_file_entry;
1825
1826 my @index_entries;
1827
1828 sub lilypond_init_out ()
1829 {
1830   t2h_default_init_out ();
1831   # Check whether we have an index at all! If not -> don't print out a search box!
1832   my $ix = main::get_index ("cp");
1833   $have_index_entries = (scalar $ix > 0);
1834 }
1835
1836 sub lilypond_index_summary_file_entry ($$$$$$$$$)
1837 {
1838   my $index_name = shift;
1839   my $entry_text = shift;
1840   my $entry_reference = shift;
1841   my $formatted_entry = shift;
1842   my $texi_entry = shift;
1843   my $entry_element_reference = shift;
1844   my $entry_element_header = shift;
1845   my $is_printed = shift;
1846   my $manual_name = shift;
1847
1848   if ($ENV{'AJAX_SEARCH'}==1) {
1849     if ($index_name eq "cp")
1850     {
1851       # The entries in the index file have the form:
1852       # SearchText \t FormattedText \t EntryURL \t SectionText \t SectionURL
1853       push @index_entries, "$entry_text\t$formatted_entry\t$entry_reference\t$entry_element_header\t$entry_element_reference\n";
1854     }
1855   }
1856 }
1857
1858 sub lilypond_finish_out ()
1859 {
1860   if ($ENV{'AJAX_SEARCH'}==1) {
1861     if (((scalar @index_entries) > 0) and $have_index_entries) {
1862       my $lang = $Texi2HTML::THISDOC{current_lang};
1863       my $big = "";
1864       $big = "-big-page" if $bigpage;
1865       my ($docu_dir, $docu_name) = split_texi_filename ($Texi2HTML::THISDOC{'input_file_name'});
1866       my $idx_file = "$docu_dir/$docu_name$big.$lang.idx";
1867       open IDXOUTFILE, ">:utf8", $idx_file;
1868       print IDXOUTFILE @index_entries;
1869       close IDXOUTFILE;
1870     }
1871   }
1872 }
1873
1874
1875
1876 #############################################################################
1877 ###  OTHER SETTINGS
1878 #############################################################################
1879
1880 # For split pages, use index.html as start page!
1881 if ($Texi2HTML::Config::SPLIT eq 'section' or
1882     $Texi2HTML::Config::SPLIT eq 'node') {
1883   $Texi2HTML::Config::TOP_FILE = 'index.html';
1884 }
1885
1886
1887 return 1;