Hello,
A new version, no functional change, but code could be more clear
like that.
On Mon, Oct 10, 2022 at 09:40:34AM +0200, Patrice Dumas wrote:
> Hello,
>
> The API changed again, for the new API, the attached init file should be
> ok.
>
> --
> Pat
> # Make the output file names consist of the base name followed by a number.
> use strict;
>
> # REMARK: if more than one manual is processed, $file_nr,
> %reference_file_name_file_nr
> # and $after_appendix_printindex should be reset, using a handler
>
> my $file_nr = -1;
>
> my %reference_file_name_file_nr = ();
>
> my $after_appendix_printindex = 0;
>
> sub filename_simple($$$$)
> {
> my $converter = shift;
> my $element = shift;
> my $filename = shift;
> my $filepath = shift;
>
> return ($filename, $filepath) if (defined($filepath));
>
> my $prefix = $converter->get_info('document_name');
> # If we're not splitting, just return the name.
> if (!$converter->get_conf('SPLIT')) {
> return $prefix.'.'.$converter->get_conf('EXTENSION');
> }
> if ($converter->element_is_tree_unit_top($element)) {
> # The table of contents file should be named this.
> return "maxima_toc.html";
> } else {
> if ($after_appendix_printindex) {
> return ($filename, undef);
> } else {
> # FIXME would be more efficient to set it up in a handler (probably
> 'init')
> # once for all
> my $printindex_element = $converter->global_direction_element('Index');
> if (defined($printindex_element) and $printindex_element eq $element) {
> $after_appendix_printindex = 1;
> return ($filename, undef);
> }
> if ($element->{'extra'} and $element->{'extra'}->{'unit_command'}) {
> my $associated_command_element =
> $element->{'extra'}->{'unit_command'};
> my $sectioning_command;
> if ($associated_command_element->{'cmdname'} eq 'node') {
> if ($associated_command_element->{'extra'}
> and
> $associated_command_element->{'extra'}->{'associated_section'}) {
> $sectioning_command
> =
> $associated_command_element->{'extra'}->{'associated_section'}->{'cmdname'};
> }
> } else {
> $sectioning_command = $associated_command_element->{'cmdname'};
> }
> if (defined($sectioning_command) and $sectioning_command =~
> /appendix/) {
> $after_appendix_printindex = 1;
> return ($filename, undef);
> }
> }
> }
> if (defined($reference_file_name_file_nr{$filename})) {
> $file_nr = $reference_file_name_file_nr{$filename};
> } else {
> $file_nr++;
> $reference_file_name_file_nr{$filename} = $file_nr;
> }
> if ($file_nr == 0) {
> return ($prefix.'.'.$converter->get_conf('EXTENSION'), undef);
> } else {
> return ($prefix.'_'.$file_nr.'.'.$converter->get_conf('EXTENSION'),
> undef);
> }
> }
> }
>
> texinfo_register_file_id_setting_function('tree_unit_file_name',
> \&filename_simple);
# Make the output file names consist of the base name followed by a number.
use strict;
# ./texi2any.pl --split=chapter --no-node-files --html -c OUTPUT_ENCODING_NAME=UTF-8 --force -e 10000 --init-file init/examples_init/maxima_file_names.pm --set-customization-variable HTML_MATH=mathjax maxima_init.texi
# REMARK: if more than one manual is processed, $file_nr, %reference_file_name_file_nr
# and $after_appendix_printindex should be reset, using a handler
my $file_nr = -1;
my %reference_file_name_file_nr = ();
my $after_appendix_printindex = 0;
sub filename_simple($$$$)
{
my $converter = shift;
my $element = shift;
my $filename = shift;
my $filepath = shift;
return ($filename, $filepath) if (defined($filepath));
my $prefix = $converter->get_info('document_name');
# If we're not splitting, just return the name. Note that it should
# not happen, as in that case the $filepath should be set and the previous
# condition should also hold.
if (!$converter->get_conf('SPLIT')) {
return ($prefix.'.'.$converter->get_conf('EXTENSION'),
undef);
}
if ($converter->element_is_tree_unit_top($element)) {
# The table of contents file should be named this.
return ("maxima_toc.html", undef);
} else {
if ($after_appendix_printindex) {
return ($filename, undef);
} else {
# FIXME would be more efficient to set it up in a handler (probably 'init')
# once for all
my $printindex_element = $converter->global_direction_element('Index');
if (defined($printindex_element) and $printindex_element eq $element) {
$after_appendix_printindex = 1;
return ($filename, undef);
}
if ($element->{'extra'} and $element->{'extra'}->{'unit_command'}) {
my $associated_command_element = $element->{'extra'}->{'unit_command'};
my $sectioning_command;
if ($associated_command_element->{'cmdname'} eq 'node') {
if ($associated_command_element->{'extra'}
and $associated_command_element->{'extra'}->{'associated_section'}) {
$sectioning_command
= $associated_command_element->{'extra'}->{'associated_section'}->{'cmdname'};
}
} else {
$sectioning_command = $associated_command_element->{'cmdname'};
}
if (defined($sectioning_command) and $sectioning_command =~ /appendix/) {
$after_appendix_printindex = 1;
return ($filename, undef);
}
}
}
if (defined($reference_file_name_file_nr{$filename})) {
$file_nr = $reference_file_name_file_nr{$filename};
} else {
$file_nr++;
$reference_file_name_file_nr{$filename} = $file_nr;
}
if ($file_nr == 0) {
return ($prefix.'.'.$converter->get_conf('EXTENSION'), undef);
} else {
return ($prefix.'_'.$file_nr.'.'.$converter->get_conf('EXTENSION'), undef);
}
}
}
texinfo_register_file_id_setting_function('tree_unit_file_name', \&filename_simple);