texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: LaTeX.pm: convert directly the parser tree, no ne


From: Patrice Dumas
Subject: branch master updated: LaTeX.pm: convert directly the parser tree, no need to determine the structure in any way.
Date: Mon, 16 Aug 2021 18:20:54 -0400

This is an automated email from the git hooks/post-receive script.

pertusus pushed a commit to branch master
in repository texinfo.

The following commit(s) were added to refs/heads/master by this push:
     new ba1ee0d  LaTeX.pm: convert directly the parser tree, no need to 
determine the structure in any way.
ba1ee0d is described below

commit ba1ee0d9b96b22394b5df7d9a77de375ad18e207
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Tue Aug 17 00:20:11 2021 +0200

    LaTeX.pm: convert directly the parser tree, no need to
    determine the structure in any way.
---
 tp/Texinfo/Convert/LaTeX.pm | 115 +++++++++++++-------------------------------
 1 file changed, 34 insertions(+), 81 deletions(-)

diff --git a/tp/Texinfo/Convert/LaTeX.pm b/tp/Texinfo/Convert/LaTeX.pm
index a121619..4603fa0 100644
--- a/tp/Texinfo/Convert/LaTeX.pm
+++ b/tp/Texinfo/Convert/LaTeX.pm
@@ -818,89 +818,42 @@ sub output($$)
     }
   }
 
-  $self->_prepare_conversion();
-
-  my $result = '';
-
-  $result .= $self->_output_text($self->_latex_header(), $fh);
-  #$result .= $self->convert_document_sections($root, $fh);
-  my $elements = Texinfo::Structuring::split_by_section($root);
-  if ($elements) {
-    # Ignore everything between Top node and the next node.  If
-    # at the end mark that Top node is ignored.
-    # After those manipulations, the tree should be incorrect,
-    # as element should point to original sections and sections
-    # to original elements.  This structure is not used in the
-    # LaTeX conversion code, though.
-    my $converted_elements = [];
-    my $current_modified_element;
-    my $in_top_node = 0;
-    foreach my $element (@$elements) {
-      $current_modified_element = undef;
-      if ($in_top_node) {
-        $current_modified_element = {'contents' => []};
-        foreach my $key ($element) {
-          if ($key ne 'contents') {
-            $current_modified_element->{$key} = $element->{$key};
-          }
-        }
-      }
-      foreach my $element_content (@{$element->{'contents'}}) {
-        if ($element_content->{'cmdname'}
-            and $element_content->{'cmdname'} eq 'node') {
-          if ($element_content->{'extra'}->{'normalized'} eq 'Top') {
-            $in_top_node = 1;
-            if (not $current_modified_element) {
-              $current_modified_element = {'contents' => []};
-              foreach my $key ($element) {
-                if ($key ne 'contents') {
-                  $current_modified_element->{$key} = $element->{$key};
-                }
-              }
-              foreach my $previous_element_content (@{$element->{'contents'}}) 
{
-                if ($previous_element_content eq $element_content) {
-                  last;
-                }
-                push @{$current_modified_element->{'contents'}}, 
-                   $previous_element_content;
-              }
-            }
-          } else {
-            if ($in_top_node) {
-              $in_top_node = 0;
-            }
-            if ($current_modified_element) {
-              push @{$current_modified_element->{'contents'}},
-                $element_content;
-            }
-          }
-        } elsif (not $in_top_node) {
-          if ($current_modified_element) {
-            push @{$current_modified_element->{'contents'}},
-              $element_content;
-          }
-        }
-      }
-      if ($current_modified_element) {
-        push @$converted_elements, $current_modified_element;
+  # Ignore everything between Top node and the next node.  If
+  # at the end, mark that Top node is ignored.
+  my $removed_top_node_root = {'contents' => []};
+
+  my $in_top_node = 0;
+  foreach my $element_content (@{$root->{'contents'}}) {
+    if ($element_content->{'cmdname'}
+        and $element_content->{'cmdname'} eq 'node') {
+      if ($element_content->{'extra'}->{'normalized'} eq 'Top') {
+        $in_top_node = 1;
       } else {
-        push @$converted_elements, $element;
+        if ($in_top_node) {
+          $in_top_node = 0;
+        }
+        push @{$removed_top_node_root->{'contents'}},
+          $element_content;
       }
+    } elsif (not $in_top_node) {
+      push @{$removed_top_node_root->{'contents'}},
+        $element_content;
     }
-    if ($in_top_node) {
-      # This is very simple, not in a paragraph, for instance, nor in
-      # a tree piece appearing typically in element such as @node or
-      # sectionning command.
-      push @{$current_modified_element->{'contents'}},
-          {'text' => "\n(`Top' node ignored)\n", 'type' => 'ignored_top_node'};
-    }
-    my $result = '';
-    foreach my $element (@$converted_elements) {
-      $result .= $self->_output_text($self->convert_tree($element), $fh);
-    }
-  } else {
-    $result .= $self->_output_text($self->convert_tree($root), $fh);
   }
+  if ($in_top_node) {
+    # This is very simple, not in a paragraph, for instance, nor in
+    # a tree piece appearing typically in element such as @node or
+    # sectionning command.
+    push @{$removed_top_node_root->{'contents'}},
+        {'text' => "\n(`Top' node ignored)\n", 'type' => 'ignored_top_node'};
+  }
+
+  my $result = '';
+
+  $self->_prepare_conversion();
+
+  $result .= $self->_output_text($self->_latex_header(), $fh);
+  $result .= $self->_output_text($self->convert_tree($removed_top_node_root), 
$fh);
   $result .= $self->_output_text($self->_latex_footer(), $fh);
 
   #print $result;
@@ -911,7 +864,7 @@ sub output($$)
                                     $self->{'output_file'}, $!));
     }
   }
-  return $result
+  return $result;
 }
 
 sub convert($$;$)
@@ -922,7 +875,7 @@ sub convert($$;$)
 
   $self->_prepare_conversion();
   
-  return $self->convert_document_sections($root, $fh);
+  return $self->_convert($root);
 }
 
 sub convert_tree($$)



reply via email to

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