+ my $displaytext = '';
+
+ # 1) if we have a cross ref name, that's the text to be displayed:
+ # 2) For the top node, use the (printable) name of the manual, unless we
+ # have an explicit cross ref name
+ # 3) In all other cases use the section name
+ if ($cross_ref ne '') {
+ $displaytext = $cross_ref;
+ } elsif (($section eq '') or ($section eq 'Top')) {
+ $displaytext = $book;
+ } else {
+ $displaytext = $section;
+ }
+
+ $displaytext = &$anchor('', $href, $displaytext) if ($displaytext ne '');
+ return &$I('%{node_file_href}', { 'node_file_href' => $displaytext });
+
+# Default: format as "see <a ..>NODE</a> section 'SECTION' in BOOK". We don't want this!
+# return t2h_default_external_ref($type, $section, $book, $file_node, $href, $cross_ref);
+}
+
+
+
+
+
+#############################################################################
+### HANDLING TRANSLATED SECTIONS: handle @translationof, secname<->filename
+### map stored on disk, xrefs in other manuals load that map
+#############################################################################
+
+
+# Try to make use of @translationof to generate files according to the original
+# English section title...
+sub lilypond_unknown($$$$$)
+{
+ my $macro = shift;
+ my $line = shift;
+ my $pass = shift;
+ my $stack = shift;
+ my $state = shift;
+
+ # the @translationof macro provides the original English section title,
+ # which should be used for file/anchor naming, while the title will be
+ # translated to each language
+ # It is already used by extract_texi_filenames.py, so this should not be
+ # necessary here at all. Still, I'll leave the code in just in case the
+ # python script messed up ;-)
+ if ($pass == 1 and $macro eq "translationof") {
+ if (ref($state->{'element'}) eq 'HASH') {
+ $state->{'element'}->{'translationof'} = main::normalise_space($line);
+ }
+ return ('', 1, undef, undef);
+ } else {
+ return t2h_default_unknown($macro, $line, $pass, $stack, $state);
+ }
+}
+
+
+
+
+my %translated_books = ();
+# Construct a href to an external source of information.
+# node is the node with texinfo @-commands
+# node_id is the node transliterated and transformed as explained in the
+# texinfo manual
+# node_xhtml_id is the node transformed such that it is unique and can
+# be used to make an html cross ref as explained in the texinfo manual
+# file is the file in '(file)node'
+sub lilypond_external_href($$$)
+{
+ my $node = shift;
+ my $node_id = shift;
+ my $node_hxmlt_id = shift;
+ my $file = shift;
+ my $original_func = \&t2h_default_external_href;
+
+ # 1) Keep a hash of book->section_map
+ # 2) if not file in keys hash => try to load the map (assign empty map if
+ # non-existent => will load only once!)
+ # 3) if node in the section=>(file, anchor) map, replace node_id and
+ # node_xhtml_id by the map's values
+ # 4) call the t2h_default_external_href with these values (or the old ones if not found)
+
+ if (($node_id ne '') and defined($file) and ($node_id ne 'Top')) {
+ my $map_name = $file;
+ $map_name =~ s/-big-page//;
+
+ # Load the map if we haven't done so already
+ if (!exists($translated_books{$map_name})) {
+ my ($docu_dir, $docu_name) = split_texi_filename ($Texi2HTML::THISDOC{'input_file_name'});
+ my $map_filename = main::locate_include_file ("${map_name}.$Texi2HTML::THISDOC{current_lang}.xref-map")
+ || main::locate_include_file ("${map_name}.xref-map");
+ $translated_books{$map_name} = load_map_file ($map_filename);
+ }
+
+ # look up translation. use these values instead of the old filename/anchor
+ my $section_name_map = $translated_books{$map_name};
+ my $node_text = main::remove_texi($node);
+ if (defined($section_name_map->{$node_text})) {
+ ($node_id, $node_hxmlt_id) = @{$section_name_map->{$node_text}};
+ } else {
+ print STDERR "WARNING: Unable to find node '$node_text' in book $map_name.\n";
+ }
+ }
+
+ if (defined $file) {
+ return &$original_func($node, $node_id, $node_hxmlt_id, $file);
+ } else {
+ return &$original_func($node, $node_id, $node_hxmlt_id);
+ }