17.1 Setting Global Directions From Document Information

Global directions may be added or modified before any conversion takes place (see Adding Text And Global Output Units Directions). It is also possible to associate a global output unit direction with a node name Texinfo code using the converted document information, by registering a user-defined function (see Init File Calling at Different Stages) to call set_global_direction on the converter at the ‘setup’ stage. The direction needs to be a default global direction, or to have been registered previously, this function cannot be used to add a new direction, only to set the association to a node. It is not a real limitation, as a new direction needs to be registered early such that associated direction strings can be set.

Function: $converter->set_global_direction ($direction, $texinfo_node_name)

$direction is a global direction (see Directions), $texinfo_node_name is an optional node name Texinfo code. The $direction will point to the output unit associated to the $texinfo_node_name node name, if set and the node exists in the Texinfo document.

For example, to associate the first @appendix command to the ‘Appendix’ direction by using section and node relations (see Tree Elements and Document Structure):

use Texinfo::Common;
use Texinfo::Convert::Texinfo;

texinfo_register_global_direction ('Appendix');

texinfo_register_direction_string_info (...)
...

sub _set_appendix_direction_node_name {
  my ($self, $document, $stage) = @_;

  my $sections_list = $document->sections_list();

  if (!defined($sections_list) or !scalar(@{$sections_list})) {
    return 0;
  }

  foreach my $section_relations (@{$sections_list}) {
    my $section = $section_relations->{'element'};
    if ($section->{'cmdname'} eq 'appendix') {
      if (exists($section_relations->{'associated_node'})) {
        my $node_relations = $section_relations->{'associated_node'};
        my $node = $node_relations->{'element'};
        my $label_element = Texinfo::Common::get_label_element($node);
        if (defined($label_element)) {
          my $node_name = Texinfo::Convert::Texinfo::convert_to_texinfo(
                         {'contents' => $label_element->{'contents'}});
          $self->set_global_direction('Appendix', $node_name);
        }
      }
      last;
    }
  }

  return 0;
}

texinfo_register_handler('setup',
            \&_set_appendix_direction_node_name);