11 Texinfo::OutputUnits


11.1 Texinfo::OutputUnits NAME

Texinfo::OutputUnits - setup and manage Texinfo document output units


11.2 Texinfo::OutputUnits SYNOPSIS

  use Texinfo::OutputUnits qw(split_by_node split_by_section split_pages
    units_directions units_file_directions);

  # $document is a parsed Texinfo::Document document.
  # When customization variables information is needed, it is obtained
  # from the $document by calling the get_conf() method.
  my $identifier_target = $document->labels_information();
  my $output_units;
  if ($split_at_nodes) {
    $output_units = split_by_node($document);
  } else {
    $output_units = split_by_section($document);
  }
  split_pages($output_units, $split);
  units_directions($identifier_target, $output_units,
                   $document->get_conf('DEBUG'));
  units_file_directions($output_units);

11.3 Texinfo::OutputUnits NOTES

The Texinfo Perl module main purpose is to be used in texi2any to convert Texinfo to other formats. There is no promise of API stability.


11.4 Texinfo::OutputUnits DESCRIPTION

You can convert a Texinfo parsed document to an output format in a Converter code by first splitting the nodes and sectioning commands in units and then converting those units. We will call the main unit of output documents an output unit. Usually a node is associated with a following sectioning command, while a sectioning command is associated with a previous node; they both together make up the output unit. Either the node or the sectioning command is considered to be the main element component.

The module provides methods to setup output units associated with node and sectioning commands of a Texinfo parsed document. With split_by_node nodes are used as the main component for the separation of output units, while with split_by_section the sectioning command elements are used to separate output units. The first mode is typical of Info format, while the second corresponds better to a traditional book. Note that the result is different when there are unassociated sectioning commands or nodes, in the usual case of each node being associated with a sectioning command and each sectioning command being associated with a node, splitting by node or by section does not make much difference as each output unit will consist of the node and the associated section in both cases.

Output units are used for conversion to HTML and Info output formats. See Texinfo::Convert::Converter::convert_output_unit for more information on conversion of output units in Converters. Output units are not relevant for all the formats, the Texinfo tree can also be converted directly, see Texinfo::Convert::Converter::output_tree.

The output units may be further grouped in pages, which are not pages as in book pages, but more like web pages, and hold series of output units. The output units may have directions to other output units prepared by units_directions. units_file_directions should also set direction related to files, provided files are associated with output units by the user.


11.5 Texinfo::OutputUnits METHODS

No method is exported in the default case.


11.5.1 Output units creation

Output units are hash references created with the following keys:

type

The type of the output unit. Set to unit for output units associated with nodes and sectioning commands.

unit_command

Main node or sectioning command associated with the output unit.

unit_contents

This array reference holds all the nodes and sectioning commands Texinfo tree elements associated with the output unit (in order). The Texinfo tree nodes and sectioning commands elements have an associated_unit key set that points to the output unit.

tree_unit_directions

Hash reference with next and prev pointing to the previous and the next output unit.

Call one of the following methods to create output units and associate them with nodes and sectioning command Texinfo tree elements:

$output_units = split_by_node($document)

Returns a reference array of output units where a node is associated with the following sectioning commands. Sectioning commands without nodes are also with the previous node, while nodes without sectioning commands are alone in their output units.

Each output unit unit_command key points to the node command associated with the output unit.

$output_units = split_by_section($document)

Similarly with split_by_node, returns an array of output units. This time, lone nodes are associated with the previous sections and lone sections makes up an output unit.

Output units unit_command keys point to the sectioning command associated with the output unit.


11.5.2 Grouping output units in pages

You can call split_pages to group together output units:

split_pages($output_units, $split)

Add the first_in_page key to each output unit in the array reference argument $output_units, set to the first output unit in the group.

The first output unit in the group is based on the value of $split:

chapter

The output units are grouped at chapter or other toplevel sectioning commands.

node

Each output unit is on its own.

section

The output units are grouped at sectioning commands below chapter.

empty string

No splitting, all the output units are together.


11.5.3 Setting output units directions

You can call the following methods to set output units directions:

units_directions($identifier_target, $output_units, $print_debug)

The $identifier_target argument associates identifiers with target elements and is generally obtained from a parsed document, Texinfo::Document::labels_information. Directions are set up for the output units in the array reference $output_units given in argument. The corresponding hash is associated with the directions key. In this hash, keys correspond to directions while values are output units.

$print_debug is optional. If set, some debugging information is printed.

The following directions are set up:

This

The output unit itself.

Forward

Unit next.

Back

Previous output unit.

NodeForward

Following node output unit in reading order. It is the next node unit, or the first in menu or the next of the up node.

NodeBack

Preceding node output unit.

NodeUp
NodeNext
NodePrev

The up, next and previous node output unit.

Up
Next
Prev

The up, next and previous section output unit.

FastBack

For top level output units, the previous top level output unit. For other output units the up top level unit. For example, for a chapter output unit it is the previous chapter output unit, for a subsection output unit it is the chapter output unit that contains the subsection.

FastForward

The next top level output unit.

units_file_directions($output_units)

In the directions reference described above for units_directions, sets the PrevFile and NextFile directions to the output units in previous and following files.

It also sets FirstInFile* directions for all the output units by using the directions of the first output unit in file. So, for example, FirstInFileNodeNext is the output unit associated with the next node of the first output unit node in the file for each output unit in the file.

The API for association of pages/output units to files is not defined yet.


11.6 Texinfo::OutputUnits SEE ALSO

Texinfo manual, Texinfo::Document, Texinfo::Convert::Converter.


11.7 Texinfo::OutputUnits AUTHOR

Patrice Dumas, <pertusus@free.fr>