10.3.2 Conversion in Preformatted Context

Conversion and formatting functions should test if in preformatted context to convert accordingly. See Init File Expansion Contexts: Normal, Preformatted, Code, String, Math.

To determine if in preformatted context, the functions is in_preformatted_context:

Function: $in_preformatted = $converter->in_preformatted_context ()

Return true if in preformatted context.

Another function tells if within a preformatted command:

Function: $inside_preformatted = $converter->inside_preformatted ()

Return true if within a preformatted block command such as @preformatted, @format.

It is not exactly the same as preformatted context, for instance menu comments are in preformatted context even if not in a preformatted block command.

If in preformatted context, it is possible to get preformatted @-commands and preformatted types nesting with preformatted_classes_stack:

Function: \@preformatted_nesting = $converter->preformatted_classes_stack ()

Returns an reference on an array containing the block preformatted @-commands such as @example, @display or @menu names without the leading @ and the HTML attribute class preformatted container names, in order of appearance.

The %Texinfo::Commands::preformatted_code_commands hash can be used to determine if a preformatted command is to be formatted as code (see (texi2any_internals)Texinfo::Commands %preformatted_code_commands).

my $pre_classes = $converter->preformatted_classes_stack();
foreach my $pre_class (@$pre_classes) {
  if ($Texinfo::Commands::preformatted_code_commands{$pre_class}) {
    $result = '<var>' .$result. '</var>';
    last;
  }
}

See Simple Customization of Containers on customizing containers preformatted class.