texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]


From: Patrice Dumas
Date: Thu, 18 Jan 2024 18:44:52 -0500 (EST)

branch: master
commit 2106a59f0392b312e5266d1b31d83120200298a0
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Thu Jan 18 21:42:02 2024 +0100

    * tp/Texinfo/Common.pm (find_parent_root_command),
    tp/Texinfo/Convert/Converter.pm (set_document)
    (determine_files_and_directory, set_global_document_commands),
    tp/Texinfo/Convert/DocBook.pm (output, _convert),
    tp/Texinfo/Convert/HTML.pm (_get_top_unit, get_file_information)
    (%available_converter_info, _convert_insertcopying_command)
    (_default_format_titlepage, _set_heading_commands_targets)
    (_html_get_tree_root_element, _prepare_special_units)
    (_prepare_output_units_global_targets, _prepare_footnotes_targets)
    (_has_contents_or_shortcontents, _prepare_simpletitle)
    (_prepare_converted_output_info), tp/Texinfo/Convert/IXIN.pm,
    tp/Texinfo/Convert/Info.pm (_info_header), tp/Texinfo/Convert/LaTeX.pm
    (_prepare_conversion, _begin_document, _convert),
    tp/Texinfo/Convert/Plaintext.pm (_convert): remove 'global_commands'
    from converter.  The 'document' is used instead to get the global
    commands information.  in HTML.pm, remove 'global_commands' from
    %available_converter_info and add 'document'.
    
    * tp/Texinfo/Common.pm (get_global_document_command): change order of
    ifs.
---
 ChangeLog                       |  23 +++++
 tp/Texinfo/Common.pm            |  51 +++++------
 tp/Texinfo/Convert/Converter.pm |  29 +++++--
 tp/Texinfo/Convert/DocBook.pm   |  52 +++++++-----
 tp/Texinfo/Convert/HTML.pm      | 182 ++++++++++++++++++++++++++--------------
 tp/Texinfo/Convert/IXIN.pm      |  24 +++---
 tp/Texinfo/Convert/Info.pm      |   8 +-
 tp/Texinfo/Convert/LaTeX.pm     |  46 ++++++----
 tp/Texinfo/Convert/Plaintext.pm |  30 ++++---
 9 files changed, 288 insertions(+), 157 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 9ae673b2ee..7152bcc29a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -33,6 +33,29 @@
        * tp/Texinfo/Common.pm (debug_print_tree): Also print 'unit_contents'
        keys to allow printing an "output unit".
 
+2024-01-18  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Common.pm (find_parent_root_command),
+       tp/Texinfo/Convert/Converter.pm (set_document)
+       (determine_files_and_directory, set_global_document_commands),
+       tp/Texinfo/Convert/DocBook.pm (output, _convert),
+       tp/Texinfo/Convert/HTML.pm (_get_top_unit, get_file_information)
+       (%available_converter_info, _convert_insertcopying_command)
+       (_default_format_titlepage, _set_heading_commands_targets)
+       (_html_get_tree_root_element, _prepare_special_units)
+       (_prepare_output_units_global_targets, _prepare_footnotes_targets)
+       (_has_contents_or_shortcontents, _prepare_simpletitle)
+       (_prepare_converted_output_info), tp/Texinfo/Convert/IXIN.pm,
+       tp/Texinfo/Convert/Info.pm (_info_header), tp/Texinfo/Convert/LaTeX.pm
+       (_prepare_conversion, _begin_document, _convert),
+       tp/Texinfo/Convert/Plaintext.pm (_convert): remove 'global_commands'
+       from converter.  The 'document' is used instead to get the global
+       commands information.  in HTML.pm, remove 'global_commands' from
+       %available_converter_info and add 'document'.
+
+       * tp/Texinfo/Common.pm (get_global_document_command): change order of
+       ifs.
+
 2024-01-18  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/Convert/Converter.pm (sort_element_counts): call
diff --git a/tp/Texinfo/Common.pm b/tp/Texinfo/Common.pm
index a2503c780b..565e4acf73 100644
--- a/tp/Texinfo/Common.pm
+++ b/tp/Texinfo/Common.pm
@@ -1282,29 +1282,29 @@ sub get_global_document_command($$$)
 
   my $element;
   if ($global_commands_information
-      and defined($global_commands_information->{$global_command})
-      and ref($global_commands_information->{$global_command}) eq 'ARRAY') {
-    if ($command_location eq 'last') {
-      $element = $global_commands_information->{$global_command}->[-1];
-    } else {
-      if ($command_location eq 'preamble_or_first'
-          and not 
_in_preamble($global_commands_information->{$global_command}->[0])) {
-        $element =
-          $global_commands_information->{$global_command}->[0];
+      and $global_commands_information->{$global_command}) {
+    if (ref($global_commands_information->{$global_command}) eq 'ARRAY') {
+      if ($command_location eq 'last') {
+        $element = $global_commands_information->{$global_command}->[-1];
       } else {
-        foreach my $command_element 
(@{$global_commands_information->{$global_command}}) {
-          if (_in_preamble($command_element)) {
-            $element = $command_element;
-          } else {
-            last;
+        if ($command_location eq 'preamble_or_first'
+            and not 
_in_preamble($global_commands_information->{$global_command}->[0])) {
+          $element =
+            $global_commands_information->{$global_command}->[0];
+        } else {
+          foreach my $command_element 
(@{$global_commands_information->{$global_command}}) {
+            if (_in_preamble($command_element)) {
+              $element = $command_element;
+            } else {
+              last;
+            }
           }
         }
       }
+    } else {
+      # unique command, first, preamble and last are the same
+      $element = $global_commands_information->{$global_command};
     }
-  } elsif ($global_commands_information
-           and defined($global_commands_information->{$global_command})) {
-    # unique command, first, preamble and last are the same
-    $element = $global_commands_information->{$global_command};
   }
   return $element;
 }
@@ -1670,13 +1670,14 @@ sub find_parent_root_command($$)
         return $current;
       } elsif ($Texinfo::Commands::block_commands{$current->{'cmdname'}}
                and $Texinfo::Commands::block_commands{$current->{'cmdname'}} 
eq 'region') {
-        if ($current->{'cmdname'} eq 'copying' and $self
-            and $self->{'global_commands'}
-            and $self->{'global_commands'}->{'insertcopying'}) {
-          foreach my 
$insertcopying(@{$self->{'global_commands'}->{'insertcopying'}}) {
-            my $root_command
-              = find_parent_root_command($self, $insertcopying);
-            return $root_command if (defined($root_command));
+        if ($current->{'cmdname'} eq 'copying' and $self and 
$self->{'document'}) {
+          my $global_commands = 
$self->{'document'}->global_commands_information();
+          if ($global_commands and $global_commands->{'insertcopying'}) {
+            foreach my $insertcopying(@{$global_commands->{'insertcopying'}}) {
+              my $root_command
+                = find_parent_root_command($self, $insertcopying);
+              return $root_command if (defined($root_command));
+            }
           }
         } else {
           return undef;
diff --git a/tp/Texinfo/Convert/Converter.pm b/tp/Texinfo/Convert/Converter.pm
index 25bb12bb0a..5e2d594f38 100644
--- a/tp/Texinfo/Convert/Converter.pm
+++ b/tp/Texinfo/Convert/Converter.pm
@@ -266,8 +266,6 @@ sub set_document($$)
 
   $converter->{'document'} = $document;
   if (defined($document)) {
-    $converter->{'global_commands'}
-     = $document->global_commands_information();
     $converter->{'document_info'} = $document->global_information();
     my $floats = $document->floats_information();
     my $identifier_target = $document->labels_information();
@@ -768,15 +766,20 @@ sub determine_files_and_directory($$)
     $input_basename =~ s/\.te?x(i|info)?$//;
   }
 
+  my $global_commands;
+  if ($self->{'document'}) {
+    $global_commands = $self->{'document'}->global_commands_information();
+  }
+
   my $setfilename;
   if (defined($self->get_conf('setfilename'))) {
     $setfilename = $self->get_conf('setfilename');
-  } elsif ($self->{'global_commands'}
-           and $self->{'global_commands'}->{'setfilename'}
-           and $self->{'global_commands'}->{'setfilename'}->{'extra'}
-           and 
defined($self->{'global_commands'}->{'setfilename'}->{'extra'}->{'text_arg'})) {
+  } elsif ($global_commands
+           and $global_commands->{'setfilename'}
+           and $global_commands->{'setfilename'}->{'extra'}
+           and 
defined($global_commands->{'setfilename'}->{'extra'}->{'text_arg'})) {
     $setfilename
-      = $self->{'global_commands'}->{'setfilename'}->{'extra'}->{'text_arg'};
+      = $global_commands->{'setfilename'}->{'extra'}->{'text_arg'};
   }
 
   my $input_basename_for_outfile = $input_basename;
@@ -1302,12 +1305,20 @@ sub set_global_document_commands($$$)
       # a customization value that is expected to be set early is set in 
$init_conf.
     }
   } else {
+    my $global_commands;
+    if ($self->{'document'}) {
+      $global_commands = $self->{'document'}->global_commands_information();
+    }
     foreach my $global_command (@{$selected_commands}) {
       if ($self->get_conf('DEBUG')) {
         print STDERR "SET_global($commands_location) $global_command\n";
       }
-      my $element = Texinfo::Common::set_global_document_command($self,
-               $self->{'global_commands'}, $global_command, 
$commands_location);
+
+      my $element;
+      if ($global_commands) {
+        $element = Texinfo::Common::set_global_document_command($self,
+                  $global_commands, $global_command, $commands_location);
+      }
       if (not defined($element)) {
         # commands not appearing in the document, this should set the
         # same value, the converter initialization value
diff --git a/tp/Texinfo/Convert/DocBook.pm b/tp/Texinfo/Convert/DocBook.pm
index 5871c161f2..75b11577c8 100644
--- a/tp/Texinfo/Convert/DocBook.pm
+++ b/tp/Texinfo/Convert/DocBook.pm
@@ -418,8 +418,12 @@ sub output($$)
 '. "<book${id} lang=\"$lang\">\n";
 
   my $legalnotice;
-  if ($self->{'global_commands'}->{'copying'}) {
-    my $copying_element = $self->{'global_commands'}->{'copying'};
+  my $global_commands;
+  if ($self->{'document'}) {
+    $global_commands = $self->{'document'}->global_commands_information();
+  }
+  if ($global_commands and $global_commands->{'copying'}) {
+    my $copying_element = $global_commands->{'copying'};
     my $copying_result
      = $self->convert_tree({'contents' => $copying_element->{'contents'}});
     if ($copying_result ne '') {
@@ -428,13 +432,15 @@ sub output($$)
   }
 
   my $fulltitle_command;
-  foreach my $title_cmdname ('title', 'shorttitlepage', 'titlefont') {
-    if ($self->{'global_commands'}->{$title_cmdname}) {
-      my $command = $self->{'global_commands'}->{$title_cmdname};
-      next if (!$command->{'args'} or !$command->{'args'}->[0]
-               or !$command->{'args'}->[0]->{'contents'});
-      $fulltitle_command = $command;
-      last;
+  if ($global_commands) {
+    foreach my $title_cmdname ('title', 'shorttitlepage', 'titlefont') {
+      if ($global_commands->{$title_cmdname}) {
+        my $command = $global_commands->{$title_cmdname};
+        next if (!$command->{'args'} or !$command->{'args'}->[0]
+                 or !$command->{'args'}->[0]->{'contents'});
+        $fulltitle_command = $command;
+        last;
+      }
     }
   }
 
@@ -442,9 +448,9 @@ sub output($$)
   # independently, only author and subtitle are gathered here.
   my $subtitle_info = '';
   my $authors_info = '';
-  if ($self->{'global_commands'}->{'titlepage'}) {
+  if ($global_commands and $global_commands->{'titlepage'}) {
     my $collected_commands = Texinfo::Common::collect_commands_list_in_tree(
-            $self->{'global_commands'}->{'titlepage'}, ['author', 'subtitle']);
+            $global_commands->{'titlepage'}, ['author', 'subtitle']);
 
     my @authors_elements;
     my $subtitle_text = '';
@@ -482,8 +488,8 @@ sub output($$)
   }
 
   my $settitle_command;
-  if ($self->{'global_commands'}->{'settitle'}) {
-    my $command = $self->{'global_commands'}->{'settitle'};
+  if ($global_commands and $global_commands->{'settitle'}) {
+    my $command = $global_commands->{'settitle'};
     $settitle_command = $command
       unless (!$command->{'args'} or !$command->{'args'}->[0]
               or !$command->{'args'}->[0]->{'contents'});
@@ -494,10 +500,11 @@ sub output($$)
     $titleabbrev_command = $settitle_command;
   } elsif ($settitle_command) {
     $fulltitle_command = $settitle_command;
-  } elsif (defined($legalnotice) and $self->{'global_commands'}->{'top'}) {
+  } elsif (defined($legalnotice) and $global_commands
+           and $global_commands->{'top'}) {
     # if there is a legalnotice, we really want to have a title
     # preceding it, so we also use @top
-    my $command = $self->{'global_commands'}->{'top'};
+    my $command = $global_commands->{'top'};
     $fulltitle_command = $command
       unless (!$command->{'args'} or !$command->{'args'}->[0]
               or !$command->{'args'}->[0]->{'contents'});
@@ -1000,13 +1007,16 @@ sub _convert($$;$)
         $result .= "\n";
         return $result;
       } elsif ($element->{'cmdname'} eq 'insertcopying') {
-        if ($self->{'global_commands'}
-           and $self->{'global_commands'}->{'copying'}) {
-         return $self->_convert({'contents'
-            => $self->{'global_commands'}->{'copying'}->{'contents'}});
-        } else {
-          return '';
+        if ($self->{'document'}) {
+          my $global_commands
+            = $self->{'document'}->global_commands_information();
+          if ($global_commands and $global_commands->{'copying'}) {
+            return $self->_convert({'contents'
+              => $global_commands->{'copying'}->{'contents'}});
+          }
         }
+
+        return '';
       } elsif ($element->{'cmdname'} eq 'verbatiminclude') {
         my $verbatim_include_verbatim
           = Texinfo::Convert::Utils::expand_verbatiminclude($self, $element);
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index b0dee10f2c..55d2fd6bc3 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -1862,8 +1862,13 @@ sub _get_top_unit($;$)
   $node_top = $self->{'identifiers_target'}->{'Top'}
                                     if ($self->{'identifiers_target'});
   my $section_top;
-  $section_top = $self->{'global_commands'}->{'top'}
-                                       if ($self->{'global_commands'});
+
+  my $global_commands;
+  if ($self->{'document'}) {
+    $global_commands = $self->{'document'}->global_commands_information();
+  }
+  $section_top = $global_commands->{'top'}
+                                       if ($global_commands);
   if ($section_top) {
     return $section_top->{'associated_unit'};
   } elsif ($node_top) {
@@ -2285,14 +2290,13 @@ sub get_file_information($$;$)
 
 # information from converter available 'read-only', in general set up before
 # really starting the formatting (except for current_filename).
-# 'floats', 'global_commands', 'sections_list' are set up in the generic
+# 'floats', 'sections_list' are set up in the generic
 # converter
 my %available_converter_info;
 foreach my $converter_info ('copying_comment', 'current_filename',
-   'destination_directory', 'document_name', 'documentdescription_string',
-   'expanded_formats',
-   'floats', 'global_commands',
-   'index_entries', 'index_entries_by_letter', 'indices_information',
+   'destination_directory', 'document', 'document_name',
+   'documentdescription_string', 'expanded_formats',
+   'floats', 'index_entries', 'index_entries_by_letter', 'indices_information',
    'jslicenses', 'identifiers_target',
    'line_break_element', 'non_breaking_space', 'paragraph_symbol',
    'sections_list',
@@ -5353,7 +5357,12 @@ sub _convert_insertcopying_command($$$)
   my $cmdname = shift;
   my $command = shift;
 
-  my $global_commands = $self->get_info('global_commands');
+  my $global_commands;
+  my $document = $self->get_info('document');
+  if ($document) {
+    $global_commands = $document->global_commands_information();
+  }
+
   if ($global_commands and $global_commands->{'copying'}) {
     return $self->convert_tree({'contents'
                => $global_commands->{'copying'}->{'contents'}},
@@ -7888,8 +7897,14 @@ sub _default_format_titlepage($)
   my $self = shift;
 
   my $titlepage_text;
-  my $global_commands = $self->get_info('global_commands');
-  if ($global_commands->{'titlepage'}) {
+  my $global_commands;
+
+  my $document = $self->get_info('document');
+  if ($document) {
+    $global_commands = $document->global_commands_information();
+  }
+
+  if ($global_commands and $global_commands->{'titlepage'}) {
     $titlepage_text = $self->convert_tree({'contents'
                => $global_commands->{'titlepage'}->{'contents'}},
                                           'convert titlepage');
@@ -9342,11 +9357,15 @@ sub _set_heading_commands_targets($)
 {
   my $self = shift;
 
-  if ($self->{'global_commands'}) {
+  my $global_commands;
+  if ($self->{'document'}) {
+    $global_commands = $self->{'document'}->global_commands_information();
+  }
+  if ($global_commands) {
     foreach my $cmdname (sort(keys(%sectioning_heading_commands))) {
       if (!$root_commands{$cmdname}
-          and $self->{'global_commands'}->{$cmdname}) {
-        foreach my $command (@{$self->{'global_commands'}->{$cmdname}}) {
+          and $global_commands->{$cmdname}) {
+        foreach my $command (@{$global_commands->{$cmdname}}) {
           $self->_new_sectioning_command_target($command);
         }
       }
@@ -9384,17 +9403,19 @@ sub _html_get_tree_root_element($$;$)
         #print STDERR "CMD ROOT $current->{'cmdname'}\n" if ($debug);
       } elsif ($block_commands{$current->{'cmdname'}}
                and $block_commands{$current->{'cmdname'}} eq 'region') {
-        if ($current->{'cmdname'} eq 'copying'
-            and $self->{'global_commands'}
-            and $self->{'global_commands'}->{'insertcopying'}) {
-          foreach my $insertcopying (@{$self->{'global_commands'}
+        if ($current->{'cmdname'} eq 'copying' and $self->{'document'}) {
+          my $global_commands
+              = $self->{'document'}->global_commands_information();
+          if ($global_commands and $global_commands->{'insertcopying'}) {
+            foreach my $insertcopying (@{$global_commands
                                                         ->{'insertcopying'}}) {
-            #print STDERR "INSERTCOPYING\n" if ($debug);
-            my ($output_unit, $root_command)
-              = $self->_html_get_tree_root_element($insertcopying,
-                                                   $find_container);
-            return ($output_unit, $root_command)
-              if (defined($output_unit) or defined($root_command));
+              #print STDERR "INSERTCOPYING\n" if ($debug);
+              my ($output_unit, $root_command)
+                = $self->_html_get_tree_root_element($insertcopying,
+                                                     $find_container);
+              return ($output_unit, $root_command)
+                if (defined($output_unit) or defined($root_command));
+            }
           }
         } elsif ($current->{'cmdname'} eq 'titlepage'
                  and $self->get_conf('USE_TITLEPAGE_FOR_TITLE')
@@ -9868,6 +9889,11 @@ sub _prepare_special_units($$)
   my $self = shift;
   my $output_units = shift;
 
+  my $global_commands;
+  if ($self->{'document'}) {
+    $global_commands = $self->{'document'}->global_commands_information();
+  }
+
   # for separate special output units
   my %do_special;
   # for associated special output units
@@ -9890,17 +9916,16 @@ sub _prepare_special_units($$)
               next;
             }
           } elsif ($contents_location eq 'after_top') {
-            if ($self->{'global_commands'} and 
$self->{'global_commands'}->{'top'}) {
-              my $section_top = $self->{'global_commands'}->{'top'};
+            if ($global_commands and $global_commands->{'top'}) {
+              my $section_top = $global_commands->{'top'};
               if ($section_top->{'associated_unit'}) {
                 $associated_output_unit = $section_top->{'associated_unit'};
               }
             }
             next unless ($associated_output_unit);
           } elsif ($contents_location eq 'inline') {
-            if ($self->{'global_commands'}
-                and $self->{'global_commands'}->{$cmdname}) {
-              foreach my $command(@{$self->{'global_commands'}->{$cmdname}}) {
+            if ($global_commands and $global_commands->{$cmdname}) {
+              foreach my $command(@{$global_commands->{$cmdname}}) {
                 my $root_command;
                 ($associated_output_unit, $root_command)
                   = $self->_html_get_tree_root_element($command);
@@ -9923,7 +9948,7 @@ sub _prepare_special_units($$)
     }
   }
 
-  if ($self->{'global_commands'}->{'footnote'}
+  if ($global_commands and $global_commands->{'footnote'}
       and $self->get_conf('footnotestyle') eq 'separate'
       and $output_units and scalar(@$output_units) > 1) {
     $do_special{'footnotes'} = 1;
@@ -10120,14 +10145,19 @@ sub _prepare_output_units_global_targets($$$$)
   $self->{'global_units_directions'}->{'Top'}
     = _get_top_unit($self, $output_units);
 
+  my $global_commands;
+  if ($self->{'document'}) {
+    $global_commands = $self->{'document'}->global_commands_information();
+  }
+
   # It is always the first printindex, even if it is not output (for example
   # it is in @copying and @titlepage, which are certainly wrong constructs).
-  if ($self->{'global_commands'} and 
$self->{'global_commands'}->{'printindex'}) {
+  if ($global_commands and $global_commands->{'printindex'}) {
     # Here document_unit can only be a document unit, or maybe undef if there
     # are no document unit at all
     my ($document_unit, $root_command)
      = $self->_html_get_tree_root_element(
-                               
$self->{'global_commands'}->{'printindex'}->[0]);
+                               $global_commands->{'printindex'}->[0]);
     if (defined($document_unit)) {
       if ($root_command and $root_command->{'cmdname'} eq 'node'
           and $root_command->{'extra'}->{'associated_section'}) {
@@ -10268,9 +10298,14 @@ sub _prepare_footnotes_targets($)
   my $footid_base = 'FOOT';
   my $docid_base = 'DOCF';
 
-  if ($self->{'global_commands'}->{'footnote'}) {
+  my $global_commands;
+  if ($self->{'document'}) {
+    $global_commands = $self->{'document'}->global_commands_information();
+  }
+
+  if ($global_commands and $global_commands->{'footnote'}) {
     my $footnote_nr = 0;
-    foreach my $footnote (@{$self->{'global_commands'}->{'footnote'}}) {
+    foreach my $footnote (@{$global_commands->{'footnote'}}) {
       $footnote_nr++;
       my $nr = $footnote_nr;
       # anchor for the footnote text
@@ -11369,7 +11404,13 @@ __("cannot use absolute path or URL `%s' for 
JS_WEBLABELS_FILE when generating w
 sub _has_contents_or_shortcontents($)
 {
   my $self = shift;
-  my $global_commands = $self->get_info('global_commands');
+  my $global_commands;
+
+  my $document = $self->get_info('document');
+  if ($document) {
+    $global_commands = $document->global_commands_information();
+  }
+
   foreach my $cmdname ('contents', 'shortcontents') {
     if ($global_commands and $global_commands->{$cmdname}) {
       return 1;
@@ -11729,15 +11770,20 @@ sub _html_convert_convert($$$$)
 sub _prepare_simpletitle($)
 {
   my $self = shift;
-  foreach my $simpletitle_command ('settitle', 'shorttitlepage') {
-    if ($self->{'global_commands'}->{$simpletitle_command}) {
-      my $command = $self->{'global_commands'}->{$simpletitle_command};
-      next if (!$command->{'args'} or !$command->{'args'}->[0]
-                or !$command->{'args'}->[0]->{'contents'}
-                or !scalar(@{$command->{'args'}->[0]->{'contents'}}));
-      $self->{'simpletitle_tree'} = $command->{'args'}->[0];
-      $self->{'simpletitle_command_name'} = $simpletitle_command;
-      last;
+  if ($self->{'document'}) {
+    my $global_commands = $self->{'document'}->global_commands_information();
+    if ($global_commands) {
+      foreach my $simpletitle_command ('settitle', 'shorttitlepage') {
+        if ($global_commands->{$simpletitle_command}) {
+          my $command = $global_commands->{$simpletitle_command};
+          next if (!$command->{'args'} or !$command->{'args'}->[0]
+                    or !$command->{'args'}->[0]->{'contents'}
+                    or !scalar(@{$command->{'args'}->[0]->{'contents'}}));
+          $self->{'simpletitle_tree'} = $command->{'args'}->[0];
+          $self->{'simpletitle_command_name'} = $simpletitle_command;
+          last;
+        }
+      }
     }
   }
 }
@@ -12068,27 +12114,35 @@ sub _prepare_converted_output_info($)
 
   $self->_prepare_simpletitle();
 
+  my $global_commands;
+  if ($self->{'document'}) {
+    $global_commands = $self->{'document'}->global_commands_information();
+  }
+
   my $fulltitle_tree;
-  foreach my $fulltitle_command('settitle', 'title', 'shorttitlepage', 'top') {
-    if ($self->{'global_commands'}->{$fulltitle_command}) {
-      my $command = $self->{'global_commands'}->{$fulltitle_command};
-      next if (!$command->{'args'} or !$command->{'args'}->[0]
-               or !$command->{'args'}->[0]->{'contents'}
-               or !scalar(@{$command->{'args'}->[0]->{'contents'}}));
-      print STDERR "Using $fulltitle_command as title\n"
-        if ($self->get_conf('DEBUG'));
-      $fulltitle_tree = $command->{'args'}->[0];
-      last;
+  if ($global_commands) {
+    foreach my $fulltitle_command ('settitle', 'title',
+                                   'shorttitlepage', 'top') {
+      if ($global_commands->{$fulltitle_command}) {
+        my $command = $global_commands->{$fulltitle_command};
+        next if (!$command->{'args'} or !$command->{'args'}->[0]
+                 or !$command->{'args'}->[0]->{'contents'}
+                 or !scalar(@{$command->{'args'}->[0]->{'contents'}}));
+        print STDERR "Using $fulltitle_command as title\n"
+          if ($self->get_conf('DEBUG'));
+        $fulltitle_tree = $command->{'args'}->[0];
+        last;
+      }
     }
-  }
-  if (!$fulltitle_tree and $self->{'global_commands'}->{'titlefont'}
-      and $self->{'global_commands'}->{'titlefont'}->[0]->{'args'}
-      and 
defined($self->{'global_commands'}->{'titlefont'}->[0]->{'args'}->[0])
-      and $self->{'global_commands'}->{'titlefont'}->[0]
+    if (!$fulltitle_tree and $global_commands->{'titlefont'}
+        and $global_commands->{'titlefont'}->[0]->{'args'}
+        and defined($global_commands->{'titlefont'}->[0]->{'args'}->[0])
+        and $global_commands->{'titlefont'}->[0]
                                                 ->{'args'}->[0]->{'contents'}
-      and @{$self->{'global_commands'}->{'titlefont'}->[0]
+        and @{$global_commands->{'titlefont'}->[0]
                                                 
->{'args'}->[0]->{'contents'}}) {
-    $fulltitle_tree = $self->{'global_commands'}->{'titlefont'}->[0];
+      $fulltitle_tree = $global_commands->{'titlefont'}->[0];
+    }
   }
 
   my $html_title_string;
@@ -12119,9 +12173,9 @@ sub _prepare_converted_output_info($)
   }
 
   # copying comment
-  if ($self->{'global_commands'}->{'copying'}) {
+  if ($global_commands and $global_commands->{'copying'}) {
     my $copying_comment = Texinfo::Convert::Text::convert_to_text(
-     {'contents' => $self->{'global_commands'}->{'copying'}->{'contents'}},
+     {'contents' => $global_commands->{'copying'}->{'contents'}},
      $self->{'convert_text_options'});
     if ($copying_comment ne '') {
       $self->{'copying_comment'}
@@ -12133,12 +12187,12 @@ sub _prepare_converted_output_info($)
   if (defined($self->get_conf('documentdescription'))) {
     $self->{'documentdescription_string'}
       = $self->get_conf('documentdescription');
-  } elsif ($self->{'global_commands'}->{'documentdescription'}) {
+  } elsif ($global_commands and $global_commands->{'documentdescription'}) {
     $self->{'documentdescription_string'}
       = $self->convert_tree_new_formatting_context(
        {'type' => '_string',
         'contents' =>
-            $self->{'global_commands'}->{'documentdescription'}->{'contents'}},
+            $global_commands->{'documentdescription'}->{'contents'}},
        'documentdescription');
     chomp($self->{'documentdescription_string'});
   }
diff --git a/tp/Texinfo/Convert/IXIN.pm b/tp/Texinfo/Convert/IXIN.pm
index 468c2545cf..d3a1107a8f 100644
--- a/tp/Texinfo/Convert/IXIN.pm
+++ b/tp/Texinfo/Convert/IXIN.pm
@@ -415,17 +415,21 @@ sub output_ixin($$)
   my %setting_commands_defaults;
   # FIXME this code is unclear and probably needs to be fixed if developemnt
   # resumes.  Maybe could be replaced by set_global_document_commands.
-  foreach my $global_command (keys(%{$self->{'global_commands'}})) {
+  my $global_commands;
+  if ($self->{'document'}) {
+    $global_commands = $self->{'document'}->global_commands_information();
+  }
+  foreach my $global_command (keys(%{$global_commands})) {
     if ((($Texinfo::Commands::line_commands{$global_command}
           and $Texinfo::Commands::line_commands{$global_command} eq 'specific')
          or $additional_setting_commands{$global_command})
         and !$global_line_not_setting_commands{$global_command}) {
-      if (ref($self->{'global_commands'}->{$global_command}) eq 'ARRAY') {
+      if (ref($global_commands->{$global_command}) eq 'ARRAY') {
         if 
(defined($Texinfo::Options::multiple_at_command_options{$global_command})) {
           $setting_commands_defaults{$global_command}
             = $Texinfo::Options::multiple_at_command_options{$global_command};
         }
-        foreach my $command (@{$self->{'global_commands'}->{$global_command}}) 
{
+        foreach my $command (@{$global_commands->{$global_command}}) {
           my ($element, $root_command) = _get_element($self, $command);
           # before first node
           if (not $root_command
@@ -440,7 +444,7 @@ sub output_ixin($$)
           #print STDERR "$element $root_command->{'extra'} $global_command\n";
         }
       } else {
-        $setting_commands{$global_command} = 
$self->{'global_commands'}->{$global_command};
+        $setting_commands{$global_command} = 
$global_commands->{$global_command};
       }
     }
   }
@@ -480,8 +484,8 @@ sub output_ixin($$)
   $result .= $self->ixin_close_element('settings');
 
   foreach my $region ('copying', 'titlepage') {
-    if ($self->{'global_commands'}->{$region}) {
-      $result .= $self->convert_tree($self->{'global_commands'}->{$region});
+    if ($global_commands->{$region}) {
+      $result .= $self->convert_tree($global_commands->{$region});
     } else {
       $result .= $self->ixin_none_element($region);
     }
@@ -733,8 +737,8 @@ sub output_ixin($$)
   }
 
   # Gather information on printindex @-commands associated node id
-  if ($self->{'global_commands'}->{'printindex'}) {
-    foreach my $command (@{$self->{'global_commands'}->{'printindex'}}) {
+  if ($global_commands->{'printindex'}) {
+    foreach my $command (@{$global_commands->{'printindex'}}) {
       my $associated_node_id = $self->_associated_node_id($command,
                                                    \%node_label_number);
       if ($command->{'extra'} and $command->{'extra'}->{'misc_args'}
@@ -788,8 +792,8 @@ sub output_ixin($$)
   }
 
   # collect listoffloats information
-  if ($self->{'global_commands'}->{'listoffloats'}) {
-    foreach my $listoffloats_element 
(@{$self->{'global_commands'}->{'listoffloats'}}) {
+  if ($global_commands and $global_commands->{'listoffloats'}) {
+    foreach my $listoffloats_element (@{$global_commands->{'listoffloats'}}) {
       my $associated_node_id = 
$self->_associated_node_id($listoffloats_element,
                                                      \%node_label_number);
       my $float_type = $listoffloats_element->{'extra'}->{'float_type'};
diff --git a/tp/Texinfo/Convert/Info.pm b/tp/Texinfo/Convert/Info.pm
index 99967d5f11..0e68ef4ea8 100644
--- a/tp/Texinfo/Convert/Info.pm
+++ b/tp/Texinfo/Convert/Info.pm
@@ -404,14 +404,18 @@ sub _info_header($$$)
   $self->{'empty_lines_count'} = 1;
   $self->_stream_output($paragraph, $result);
 
+  my $global_commands;
+  if ($self->{'document'}) {
+    $global_commands = $self->{'document'}->global_commands_information();
+  }
   # format @copying using the last value of the preamble.
   my @informative_global_commands = $self->get_informative_global_commands();
   $self->set_global_document_commands('preamble', 
\@informative_global_commands);
-  if ($self->{'global_commands'} and $self->{'global_commands'}->{'copying'}) {
+  if ($global_commands and $global_commands->{'copying'}) {
     print STDERR "COPYING HEADER\n" if ($self->get_conf('DEBUG'));
     $self->{'in_copying_header'} = 1;
     my $copying = $self->convert_tree({'contents' =>
-          $self->{'global_commands'}->{'copying'}->{'contents'}});
+          $global_commands->{'copying'}->{'contents'}});
     $self->_stream_output_encoded($copying);
     $self->process_footnotes();
     delete $self->{'in_copying_header'};
diff --git a/tp/Texinfo/Convert/LaTeX.pm b/tp/Texinfo/Convert/LaTeX.pm
index d39b6222f2..f3f82148f9 100644
--- a/tp/Texinfo/Convert/LaTeX.pm
+++ b/tp/Texinfo/Convert/LaTeX.pm
@@ -986,12 +986,17 @@ sub _prepare_conversion($;$)
   delete($self->{'custom_heading'});
   delete($self->{'index_entries'});
 
+  my $global_commands;
+  if ($self->{'document'}) {
+    $global_commands = $self->{'document'}->global_commands_information();
+  }
+
   if (defined($root)) {
     $self->_associate_other_nodes_to_sections($root);
   }
 
-  if ($self->{'global_commands'}->{'settitle'}) {
-    my $settitle_root = $self->{'global_commands'}->{'settitle'};
+  if ($global_commands and $global_commands->{'settitle'}) {
+    my $settitle_root = $global_commands->{'settitle'};
     if ($settitle_root->{'args'}->[0]
         and $settitle_root->{'args'}->[0]->{'contents'}) {
       $self->{'settitle_tree'} =
@@ -1796,14 +1801,20 @@ sub _begin_document($)
   my $result = '';
   $result .= '\begin{document}
 ';
-  if (exists($self->{'global_commands'}->{'titlepage'})
-      or exists($self->{'global_commands'}->{'shorttitlepage'})) {
+  my $global_commands;
+  if ($self->{'document'}) {
+    $global_commands = $self->{'document'}->global_commands_information();
+  }
+
+  if ($global_commands
+      and ($global_commands->{'titlepage'}
+           or $global_commands->{'shorttitlepage'})) {
     $result .= "\n";
     $result .= $front_main_matter_definitions{$documentclass}->{'front'}."\n";
     $result .= _set_headings($self, 'off');
 
-    if (exists($self->{'global_commands'}->{'titlepage'})) {
-      my $element = $self->{'global_commands'}->{'titlepage'};
+    if ($global_commands->{'titlepage'}) {
+      my $element = $global_commands->{'titlepage'};
       # Start a group such that the changes are forgotten when front cover
       # is done.
       # Define glues dimensions that are used in front cover formatting.
@@ -1823,7 +1834,7 @@ sub _begin_document($)
       $result .= _finish_front_cover_page($self);
       $result .= "\\end{titlepage}\n";
     } else {
-      my $element = $self->{'global_commands'}->{'shorttitlepage'};
+      my $element = $global_commands->{'shorttitlepage'};
       my $title_text = _title_font($self, $element);
       $result .= "\\begin{titlepage}\n";
       $result .= "{\\raggedright $title_text}\n";
@@ -1834,19 +1845,20 @@ sub _begin_document($)
     }
   }
 
-  if (exists($self->{'global_commands'}->{'contents'})
+  if ($global_commands and $global_commands->{'contents'}
       and $self->{'sections_list'}
       and not (defined($self->get_conf('CONTENTS_OUTPUT_LOCATION'))
                and $self->get_conf('CONTENTS_OUTPUT_LOCATION') eq 'inline')) {
-    if (exists($self->{'global_commands'}->{'titlepage'})
-        or exists($self->{'global_commands'}->{'shorttitlepage'})) {
+    if ($global_commands->{'titlepage'}
+        or $global_commands->{'shorttitlepage'}) {
       $result .= _set_headings($self, 'pagenum');
     }
     $result .= "\\tableofcontents\\newpage\n";
   }
 
-  if (exists($self->{'global_commands'}->{'titlepage'})
-      or exists($self->{'global_commands'}->{'shorttitlepage'})) {
+  if ($global_commands
+      and ($global_commands->{'titlepage'}
+           or $global_commands->{'shorttitlepage'})) {
     $result .= $front_main_matter_definitions{$documentclass}->{'main'}."\n";
     $result .= _set_headings($self, $self->get_conf('headings'));
   }
@@ -3866,10 +3878,14 @@ sub _convert($$)
         if ($expansion);
       return $result;
     } elsif ($cmdname eq 'insertcopying') {
-      if ($self->{'global_commands'}
-          and $self->{'global_commands'}->{'copying'}) {
+      my $global_commands;
+      if ($self->{'document'}) {
+        $global_commands = $self->{'document'}->global_commands_information();
+      }
+
+      if ($global_commands and $global_commands->{'copying'}) {
         unshift @{$self->{'current_contents'}->[-1]},
-           {'contents' => 
$self->{'global_commands'}->{'copying'}->{'contents'}};
+           {'contents' => $global_commands->{'copying'}->{'contents'}};
       }
       return $result;
     } elsif ($cmdname eq 'printindex') {
diff --git a/tp/Texinfo/Convert/Plaintext.pm b/tp/Texinfo/Convert/Plaintext.pm
index 330170049f..015d9b819e 100644
--- a/tp/Texinfo/Convert/Plaintext.pm
+++ b/tp/Texinfo/Convert/Plaintext.pm
@@ -3010,16 +3010,21 @@ sub _convert($$)
           and @{$element->{'args'}->[0]->{'contents'}}
           and $command ne 'part') {
         $heading_element = $element->{'args'}->[0];
-      } elsif ($command eq 'top'
-          and $self->{'global_commands'}->{'settitle'}
-          and $self->{'global_commands'}->{'settitle'}->{'args'}
-          and @{$self->{'global_commands'}->{'settitle'}->{'args'}}
-          and $self->{'global_commands'}->{'settitle'}
+      } elsif ($command eq 'top') {
+        my $global_commands;
+        if ($self->{'document'}) {
+          $global_commands = 
$self->{'document'}->global_commands_information();
+        }
+        if ($global_commands and $global_commands->{'settitle'}
+            and $global_commands->{'settitle'}->{'args'}
+            and scalar(@{$global_commands->{'settitle'}->{'args'}})
+            and $global_commands->{'settitle'}
                                                  ->{'args'}->[0]->{'contents'}
-          and scalar(@{$self->{'global_commands'}->{'settitle'}
+            and scalar(@{$global_commands->{'settitle'}
                                               ->{'args'}->[0]->{'contents'}})) 
{
-        $heading_element =
-           $self->{'global_commands'}->{'settitle'}->{'args'}->[0];
+          $heading_element
+            = $global_commands->{'settitle'}->{'args'}->[0];
+        }
       }
 
       if ($heading_element) {
@@ -3162,10 +3167,13 @@ sub _convert($$)
       _convert($self, $expansion) if (defined($expansion));
       return;
     } elsif ($command eq 'insertcopying') {
-      if ($self->{'global_commands'}
-          and $self->{'global_commands'}->{'copying'}) {
+      my $global_commands;
+      if ($self->{'document'}) {
+        $global_commands = $self->{'document'}->global_commands_information();
+      }
+      if ($global_commands and $global_commands->{'copying'}) {
         my $inserted =
-         {'contents' => $self->{'global_commands'}->{'copying'}->{'contents'}};
+         {'contents' => $global_commands->{'copying'}->{'contents'}};
         _convert($self, $inserted);
       }
       return;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]