10.4.3 Conversion to Plain Text

The conversion to plain text can be achieved by using the Texinfo::Text converter convert_to_text function (see (texi2any_internals)Texinfo::Convert::Text).

convert_to_text requires a conversion options argument to determine how the conversion to text should be done, specifying, for instance, the encoding or the formatting context. Such options are available in $converter->{'convert_text_options'}.

For example, to convert the Texinfo tree element $element to plain text:

my $plain_text = Texinfo::Convert::Text::convert_to_text($element,
                                  $converter->{'convert_text_options'});

Conversion to plain text is often used for strings that are to be formatted in code context. Code context can be set and reset by using Texinfo::Convert::Text::set_options_code and Texinfo::Convert::Text::reset_options_code:

Texinfo::Convert::Text::set_options_code(
               $converter->{'convert_text_options'});
my $code_string = Texinfo::Convert::Text::convert_to_text($element,
                            $converter->{'convert_text_options'});
Texinfo::Convert::Text::reset_options_code(
               $converter->{'convert_text_options'});

If encoded characters should be used irrespective of the specified document encoding, a possibility relevant, in general, for file names, Texinfo::Convert::Text::set_options_encoding_if_not_ascii should be called before the conversion and the original options should be reset afterwards by calling Texinfo::Convert::Text::reset_options_encoding:

Texinfo::Convert::Text::set_options_code(
               $converter->{'convert_text_options'});
Texinfo::Convert::Text::set_options_encoding_if_not_ascii($converter,
                             $converter->{'convert_text_options'});
my $file_name = Texinfo::Convert::Text::convert_to_text($element,
                            $converter->{'convert_text_options'});
Texinfo::Convert::Text::reset_options_code(
               $converter->{'convert_text_options'});
Texinfo::Convert::Text::reset_options_encoding(
               $converter->{'convert_text_options'});