texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Gavin D. Smith
Date: Sat, 12 Nov 2022 17:25:46 -0500 (EST)

branch: release/7.0
commit 0b9660080f17ea7f05394cddce07a02f78ab3543
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sat Nov 12 21:51:37 2022 +0000

    * tp/Texinfo/Convert/LaTeX.pm (_prepare_conversion, _title_font)
    (_convert): convert only if contents are defined.
---
 ChangeLog                                      |   5 +
 tp/Texinfo/Convert/LaTeX.pm                    | 121 +++++++++++++++----------
 tp/t/results/coverage_braces/empty_commands.pl |   2 +-
 3 files changed, 79 insertions(+), 49 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 3b3e0392eb..0c6dba4c0a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2022-11-08  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Convert/LaTeX.pm (_prepare_conversion, _title_font)
+       (_convert): convert only if contents are defined.
+
 2022-11-08  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/Convert/HTML.pm: avoid formatting when contents
diff --git a/tp/Texinfo/Convert/LaTeX.pm b/tp/Texinfo/Convert/LaTeX.pm
index 6e049b35f1..a432320a2f 100644
--- a/tp/Texinfo/Convert/LaTeX.pm
+++ b/tp/Texinfo/Convert/LaTeX.pm
@@ -959,8 +959,10 @@ sub _prepare_conversion($;$)
 
   if ($self->{'global_commands'}->{'settitle'}) {
     my $settitle_root = $self->{'global_commands'}->{'settitle'};
-    if (not ($settitle_root->{'extra'}
-             and $settitle_root->{'extra'}->{'missing_argument'})) {
+    if ($settitle_root->{'args'}->[0]
+        and $settitle_root->{'args'}->[0]->{'contents'}
+        and not ($settitle_root->{'extra'}
+                 and $settitle_root->{'extra'}->{'missing_argument'})) {
       $self->{'settitle_tree'} =
          {'contents' => $settitle_root->{'args'}->[0]->{'contents'}};
     }
@@ -2015,11 +2017,15 @@ sub _title_font($$)
 {
   my $self = shift;
   my $element = shift;
-  # in Texinfo TeX seems a bit smaller, but LARGE seems too small
-  my $result = "{\\huge \\bfseries ";
-  $result .= _convert($self, {'contents' => 
$element->{'args'}->[0]->{'contents'}});
-  $result .= '}';
-  return $result;
+
+  if ($element->{'args'}->[0] and $element->{'args'}->[0]->{'contents'}) {
+    # in Texinfo TeX seems a bit smaller, but LARGE seems too small
+    my $result = "{\\huge \\bfseries ";
+    $result .= _convert($self, {'contents' => 
$element->{'args'}->[0]->{'contents'}});
+    $result .= '}';
+    return $result;
+  }
+  return '';
 }
 
 sub _set_environment_options($$$)
@@ -2725,10 +2731,12 @@ sub _convert($$)
       if ($element->{'args'}) {
         if (scalar(@{$element->{'args'}}) == 3
              and defined($element->{'args'}->[2])
+             and $element->{'args'}->[2]->{'contents'}
              and @{$element->{'args'}->[2]->{'contents'}}) {
           unshift @{$self->{'current_contents'}->[-1]},
             {'contents' => $element->{'args'}->[2]->{'contents'}};
-        } elsif ($element->{'args'}->[0]->{'contents'}
+        } elsif ($element->{'args'}->[0]
+                 and $element->{'args'}->[0]->{'contents'}
                  and @{$element->{'args'}->[0]->{'contents'}}) {
           my $url_content = $element->{'args'}->[0]->{'contents'};
           my $url_text = $self->_protect_url(
@@ -2736,9 +2744,9 @@ sub _convert($$)
                {'contents' => $url_content},
                {'code' => 1, %{$self->{'convert_text_options'}}}));
           if (scalar(@{$element->{'args'}}) == 2
-             and defined($element->{'args'}->[1])
-             and $element->{'args'}->[1]->{'contents'}
-             and @{$element->{'args'}->[1]->{'contents'}}) {
+              and defined($element->{'args'}->[1])
+              and $element->{'args'}->[1]->{'contents'}
+              and @{$element->{'args'}->[1]->{'contents'}}) {
             my $description = _convert($self, {'contents',
                                    $element->{'args'}->[1]->{'contents'}});
             my $text = $self->gdt('{text} ({url})',
@@ -2752,6 +2760,7 @@ sub _convert($$)
           }
         } elsif (scalar(@{$element->{'args'}}) == 2
                  and defined($element->{'args'}->[1])
+                 and $element->{'args'}->[1]->{'contents'}
                  and @{$element->{'args'}->[1]->{'contents'}}) {
           unshift @{$self->{'current_contents'}->[-1]},
             {'contents' => $element->{'args'}->[1]->{'contents'}};
@@ -3033,6 +3042,7 @@ sub _convert($$)
         }
         if (scalar (@{$element->{'args'}}) == 2
             and defined($element->{'args'}->[-1])
+            and $element->{'args'}->[-1]->{'contents'}
             and @{$element->{'args'}->[-1]->{'contents'}}) {
           my $prepended = $self->gdt('{abbr_or_acronym} ({explanation})',
                            {'abbr_or_acronym' => $argument,
@@ -3111,17 +3121,21 @@ sub _convert($$)
           $shortcaption = $float->{'extra'}->{'shortcaption'};
         }
       }
-      _push_new_context($self, 'latex_caption');
-      my $caption_text = _convert($self,
-         {'contents' => $element->{'args'}->[0]->{'contents'}});
-      _pop_context($self);
+      my $caption_text = '';
+      if ($element->{'args'}->[0]->{'contents'}) {
+        _push_new_context($self, 'latex_caption');
+         $caption_text = _convert($self,
+           {'contents' => $element->{'args'}->[0]->{'contents'}});
+        _pop_context($self);
+      }
       
       $result .= '\caption';
 
-      if (defined($shortcaption)) {
+      if (defined($shortcaption)
+          and $shortcaption->{'args'}->[0]->{'contents'}) {
         _push_new_context($self, 'latex_shortcaption');
         my $shortcaption_text = _convert($self,
-                       {'contents' => 
$shortcaption->{'args'}->[0]->{'contents'}});
+                 {'contents' => $shortcaption->{'args'}->[0]->{'contents'}});
         _pop_context($self);
         $result .= '['.$shortcaption_text.']';
       }
@@ -3374,19 +3388,24 @@ sub _convert($$)
       # nothing to do here.  The condition ensures that the commands are not
       # considered as unknown commands in the else below.
     } elsif ($cmdname eq 'center') {
-      $result .= "\\begin{center}\n";
-      $result .= $self->_convert (
+      if ($element->{'args'}->[0]->{'contents'}) {
+        $result .= "\\begin{center}\n";
+        $result .= $self->_convert (
                        {'contents' => $element->{'args'}->[0]->{'contents'}});
-      $result .= "\n\\end{center}\n";
+        $result .= "\n\\end{center}\n";
+      }
       return $result;
     } elsif ($cmdname eq 'exdent') {
-      # FIXME \leavevmode{} is added to avoid
-      # ! LaTeX Error: There's no line here to end.
-      # but it is not clearly correct
-      $result .= "\\leavevmode{}\\\\\n";
-      $result .= "\\hbox{\\kern -\\leftmargin}%\n";
-      $result .= $self->_convert({'contents' => 
$element->{'args'}->[0]->{'contents'}})."\n";
-      $result .= "\\\\\n";
+      if ($element->{'args'}->[0]->{'contents'}) {
+        # FIXME \leavevmode{} is added to avoid
+        # ! LaTeX Error: There's no line here to end.
+        # but it is not clearly correct
+        $result .= "\\leavevmode{}\\\\\n";
+        $result .= "\\hbox{\\kern -\\leftmargin}%\n";
+        $result .= $self->_convert(
+                   {'contents' => $element->{'args'}->[0]->{'contents'}})."\n";
+        $result .= "\\\\\n";
+      }
       return $result;
     } elsif ($cmdname eq 'verbatiminclude') {
       my $expansion = Texinfo::Convert::Utils::expand_verbatiminclude($self,
@@ -3484,31 +3503,35 @@ sub _convert($$)
       $self->{'titlepage_formatting'}->{'title'} = 1
          if ($self->{'titlepage_formatting'});
     } elsif ($cmdname eq 'subtitle') {
-      my $subtitle_text = _convert($self,
+      if ($element->{'args'}->[0]->{'contents'}) {
+        my $subtitle_text = _convert($self,
                {'contents' => $element->{'args'}->[0]->{'contents'}});
-      # too much vertical spacing with flushright environment
-      #$result .= "\\begin{flushright}\n";
-      #$result .= $subtitle_text."\n";
-      #$result .= "\\end{flushright}\n";
-      $result .= "\\rightline{$subtitle_text}\n";
+        # too much vertical spacing with flushright environment
+        #$result .= "\\begin{flushright}\n";
+        #$result .= $subtitle_text."\n";
+        #$result .= "\\end{flushright}\n";
+        $result .= "\\rightline{$subtitle_text}\n";
+      }
     } elsif ($cmdname eq 'author') {
       if (not $self->{'formatting_context'}->[-1]->{'in_quotation'}) {
-        my $author_name = _convert($self,
+        if ($element->{'args'}->[0]->{'contents'}) {
+          my $author_name = _convert($self,
                        {'contents' => $element->{'args'}->[0]->{'contents'}});
-        if ($self->{'titlepage_formatting'}
-            and $self->{'titlepage_formatting'}->{'in_front_cover'}) {
-          if (not $self->{'titlepage_formatting'}->{'author'}) {
-            # first author, add space before
-            $self->{'titlepage_formatting'}->{'author'} = 1;
-            $result .= "\\vskip 0pt plus 1filll\n";
+          if ($self->{'titlepage_formatting'}
+              and $self->{'titlepage_formatting'}->{'in_front_cover'}) {
+            if (not $self->{'titlepage_formatting'}->{'author'}) {
+              # first author, add space before
+              $self->{'titlepage_formatting'}->{'author'} = 1;
+              $result .= "\\vskip 0pt plus 1filll\n";
+            }
+            # use \leftline as in Texinfo TeX
+            # FIXME In Texinfo TeX the interline space between @author lines
+            # seems better
+            $result .= "\\leftline{\\Large \\bfseries $author_name}%\n";
+          } else {
+            # author in regular text.  Should not happen
+            $result .= "{\\bfseries $author_name}%\n";
           }
-          # use \leftline as in Texinfo TeX
-          # FIXME In Texinfo TeX the interline space between @author lines
-          # seems better
-          $result .= "\\leftline{\\Large \\bfseries $author_name}%\n";
-        } else {
-          # author in regular text.  Should not happen
-          $result .= "{\\bfseries $author_name}%\n";
         }
         return $result;
       }
@@ -3965,9 +3988,11 @@ sub _convert($$)
         # we are not in a preformatted type here, such that the conversion
         # does not take into account the preformatted environment.  Probably 
best.
         foreach my $author (@{$element->{'extra'}->{'authors'}}) {
-          $result .= _convert($self,
+          if ($author->{'args'}->[0]->{'contents'}) {
+            $result .= _convert($self,
                  $self->gdt('@center --- @emph{{author}}',
                     {'author' => $author->{'args'}->[0]->{'contents'}}));
+          }
         }
       }
       $self->{'formatting_context'}->[-1]->{'in_quotation'} -= 1;
diff --git a/tp/t/results/coverage_braces/empty_commands.pl 
b/tp/t/results/coverage_braces/empty_commands.pl
index 3c0c8568f6..a15f296366 100644
--- a/tp/t/results/coverage_braces/empty_commands.pl
+++ b/tp/t/results/coverage_braces/empty_commands.pl
@@ -222,7 +222,7 @@ $result_converted{'html_text'}->{'empty_commands'} = '
 ';
 
 
-$result_converted{'latex_text'}->{'empty_commands'} = '{\\huge \\bfseries }
+$result_converted{'latex_text'}->{'empty_commands'} = '
 
    \\texttt{}\\footnote{} \\~{}  \\verb;;
 ';



reply via email to

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