texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: Text for contents for @*ref in section title in L


From: Patrice Dumas
Subject: branch master updated: Text for contents for @*ref in section title in LaTeX
Date: Wed, 27 Jul 2022 17:39:51 -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 f719d222fa Text for contents for @*ref in section title in LaTeX
f719d222fa is described below

commit f719d222fade99221aea5e6465f3055a17b86bc4
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Wed Jul 27 23:39:39 2022 +0200

    Text for contents for @*ref in section title in LaTeX
    
    * tp/Texinfo/Convert/LaTeX.pm (_convert): if in a section heading
    formatting use \texorpdfstring to provide with a textual
    representation of @*ref, instead of \hyperref, which, understandably
    breaks the contents.
---
 ChangeLog                                          |  9 +++++
 tp/TODO                                            |  5 +++
 tp/Texinfo/Convert/LaTeX.pm                        | 43 ++++++++++++++++-----
 tp/t/converters_tests.t                            |  2 +
 .../converters_tests/ref_error_formatting.pl       | 44 ++++++++++++++++++++++
 tp/t/results/converters_tests/ref_in_sectioning.pl | 37 ++++++++++++++++++
 6 files changed, 131 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index f1340838ab..82864ce2bb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2022-07-27  Patrice Dumas  <pertusus@free.fr>
+
+       Text for contents for @*ref in section title in LaTeX
+
+       * tp/Texinfo/Convert/LaTeX.pm (_convert): if in a section heading
+       formatting use \texorpdfstring to provide with a textual
+       representation of @*ref, instead of \hyperref, which, understandably
+       breaks the contents.
+
 2022-07-27  Gavin Smith  <gavinsmith0123@gmail.com>
 
        Document EPUB
diff --git a/tp/TODO b/tp/TODO
index d5ea64aa77..13db31ec43 100644
--- a/tp/TODO
+++ b/tp/TODO
@@ -20,6 +20,11 @@ Before next release
 Bugs
 ====
 
+perl -w t/converters_tests.t top_in_ref
+BUG/TODO assoc
+Not a bug as Top is not associated with a section.  There is no
+section. Maybe check if that happens if there is a section.
+
 HTML API
 ========
 
diff --git a/tp/Texinfo/Convert/LaTeX.pm b/tp/Texinfo/Convert/LaTeX.pm
index 2067de28ad..1526247453 100644
--- a/tp/Texinfo/Convert/LaTeX.pm
+++ b/tp/Texinfo/Convert/LaTeX.pm
@@ -2686,6 +2686,9 @@ sub _convert($$)
                 
$self->{'normalized_nodes_associated_section'}->{$normalized_name}
                   = $section_command;
               } else {
+                # FIXME this can happens for the Top node if not associated 
with
+                # a section command (possibly only when there is no sectioning
+                # command at all)
                 print STDERR "BUG/TODO assoc ".$reference->{'cmdname'}.": 
$normalized_name: ".join("|", sort(keys(%{$reference->{'extra'}})))."\n";
               }
             }
@@ -2702,14 +2705,22 @@ sub _convert($$)
               $float_type = '';
             }
           }
-
+          my $text_representation;
+          if 
($self->{'formatting_context'}->[-1]->{'in_sectioning_command_heading'}) {
+            # hyperref leads, understandably to some errors in a heading for
+            # the table of content.  In that case, setup a text representation.
+            $text_representation = '';
+          }
           # TODO: should translate
+          my $reference_result = '';
           if ($cmdname eq 'xref') {
-            $result .= "See ";
+            $reference_result = "See ";
           } elsif ($cmdname eq 'pxref') {
-            $result .= "see ";
+            $reference_result = "see ";
           } elsif ($cmdname eq 'ref') {
           }
+          $text_representation .= $reference_result
+            if defined($text_representation);
           my $name;
           if (defined($args[2])) {
             $name = $args[2];
@@ -2727,18 +2738,23 @@ sub _convert($$)
           my $name_text;
           if (defined($name)) {
             $name_text = _convert($self, {'contents' => $name});
+            $text_representation .= $name_text if 
(defined($text_representation));
           }
 
           # FIXME translation
           if (defined($float_type)) {
             # no page for float reference in Texinfo TeX
             if (defined($name_text)) {
-              $result .= "\\hyperref[$reference_label]{$name_text}";
+              $reference_result .= "\\hyperref[$reference_label]{$name_text}";
             } else {
               if ($float_type ne '') {
-                $result .= 
"\\hyperref[$reference_label]{$float_type~\\ref*{$reference_label}}";
+                $reference_result
+                  .= 
"\\hyperref[$reference_label]{$float_type~\\ref*{$reference_label}}";
+                $text_representation .= $float_type
+                     if (defined($text_representation));
               } else {
-                $result .= 
"\\hyperref[$reference_label]{\\ref*{$reference_label}}";
+                $reference_result
+                  .= "\\hyperref[$reference_label]{\\ref*{$reference_label}}";
               }
             }
           } else {
@@ -2757,17 +2773,26 @@ sub _convert($$)
                 # not exist in the default case.  it is defined in the 
pagenote package together with
                 # \pagename which is page in the default case, but it is 
unclear if this
                 # can be used as a basis for translations
-                $result .= 
"\\hyperref[$reference_label]{Section~\\ref*{$reference_label} [$name_text], 
page~\\pageref*{$reference_label}}";
+                $reference_result
+                  .= 
"\\hyperref[$reference_label]{Section~\\ref*{$reference_label} [$name_text], 
page~\\pageref*{$reference_label}}";
               } else {
                 # TODO translation
-                $result .= 
"\\hyperref[$reference_label]{\\chaptername~\\ref*{$reference_label} 
[$name_text], page~\\pageref*{$reference_label}}";
+                $reference_result
+                  .= 
"\\hyperref[$reference_label]{\\chaptername~\\ref*{$reference_label} 
[$name_text], page~\\pageref*{$reference_label}}";
               }
             } else {
               # anchor
               # TODO translation
-              $result .= "\\hyperref[$reference_label]{[$name_text], 
page~\\pageref*{$reference_label}}";
+              $reference_result
+                .= "\\hyperref[$reference_label]{[$name_text], 
page~\\pageref*{$reference_label}}";
             }
           }
+          if (not defined($text_representation)) {
+            $result .= $reference_result;
+          } else {
+            $result .= '\texorpdfstring{'.$reference_result.'}{'
+                             .$text_representation.'}';
+          }
           return $result;
         } else {
           # external ref
diff --git a/tp/t/converters_tests.t b/tp/t/converters_tests.t
index 2edda35eae..df646fb605 100644
--- a/tp/t/converters_tests.t
+++ b/tp/t/converters_tests.t
@@ -845,6 +845,8 @@ my %latex_tests = (
   'some_at_commands_in_ref_nodes' => 1,
   'refs_formatting' => 1,
   'top_in_ref' => 1,
+  'ref_error_formatting' => 1,
+  'ref_in_sectioning' => 1,
   'inline' => 1,
   'test_sp' => 1,
   'non_empty_part' => 1,
diff --git a/tp/t/results/converters_tests/ref_error_formatting.pl 
b/tp/t/results/converters_tests/ref_error_formatting.pl
index 98ad580061..834d45d6c5 100644
--- a/tp/t/results/converters_tests/ref_error_formatting.pl
+++ b/tp/t/results/converters_tests/ref_error_formatting.pl
@@ -4596,4 +4596,48 @@ $result_converted{'docbook'}->{'ref_error_formatting'} = 
'
 <literal>@inforef{node,,file name}</literal> See Info file <filename>file 
name</filename>, node &#8216;<literal>node</literal>&#8217;
 </para>';
 
+
+$result_converted{'latex'}->{'ref_error_formatting'} = '
+\\texttt{@ref\\{node\\}} node
+
+\\texttt{@ref\\{,cross ref name\\}} 
+\\texttt{@ref\\{,,title\\}} title
+\\texttt{@ref\\{,,,file name\\}} \\texttt{file name}
+\\texttt{@ref\\{,,,,manual\\}} \\textsl{manual}
+\\texttt{@ref\\{node,cross ref name\\}} node
+\\texttt{@ref\\{node,,title\\}} title
+\\texttt{@ref\\{node,,,file name\\}} Section ``node\'\' in \\texttt{file name}
+\\texttt{@ref\\{node,,,,manual\\}} Section ``node\'\' in \\textsl{manual}
+\\texttt{@ref\\{node,cross ref name,title,\\}} title
+\\texttt{@ref\\{node,cross ref name,,file name\\}} Section ``node\'\' in 
\\texttt{file name}
+\\texttt{@ref\\{node,cross ref name,,,manual\\}} Section ``node\'\' in 
\\textsl{manual}
+\\texttt{@ref\\{node,cross ref name,title,file name\\}} Section ``title\'\' in 
\\texttt{file name}
+\\texttt{@ref\\{node,cross ref name,title,,manual\\}} Section ``title\'\' in 
\\textsl{manual}
+\\texttt{@ref\\{node,cross ref name,title, file name, manual\\}} Section 
``title\'\' in \\textsl{manual}
+\\texttt{@ref\\{node,,title,file name\\}} Section ``title\'\' in \\texttt{file 
name}
+\\texttt{@ref\\{node,,title,,manual\\}} Section ``title\'\' in \\textsl{manual}
+\\texttt{@ref\\{node,,title, file name, manual\\}} Section ``title\'\' in 
\\textsl{manual}
+\\texttt{@ref\\{node,,,file name,manual\\}} Section ``node\'\' in 
\\textsl{manual}
+\\texttt{@ref\\{,cross ref name,title,\\}} title
+\\texttt{@ref\\{,cross ref name,,file name\\}} \\texttt{file name}
+\\texttt{@ref\\{,cross ref name,,,manual\\}} \\textsl{manual}
+\\texttt{@ref\\{,cross ref name,title,file name\\}} Section ``title\'\' in 
\\texttt{file name}
+\\texttt{@ref\\{,cross ref name,title,,manual\\}} Section ``title\'\' in 
\\textsl{manual}
+\\texttt{@ref\\{,cross ref name,title, file name, manual\\}} Section 
``title\'\' in \\textsl{manual}
+\\texttt{@ref\\{,,title,file name\\}} Section ``title\'\' in \\texttt{file 
name}
+\\texttt{@ref\\{,,title,,manual\\}} Section ``title\'\' in \\textsl{manual}
+\\texttt{@ref\\{,,title, file name, manual\\}} Section ``title\'\' in 
\\textsl{manual}
+\\texttt{@ref\\{,,,file name,manual\\}} \\textsl{manual}
+
+\\texttt{@inforef\\{,cross ref name \\}} 
+\\texttt{@inforef\\{,,file name\\}} \\texttt{file name}
+\\texttt{@inforef\\{,cross ref name, file name\\}} \\texttt{file name}
+\\texttt{@inforef\\{\\}} 
+
+\\texttt{@inforef\\{node, cross ref name, file name\\}} Section ``node\'\' in 
\\texttt{file name}
+\\texttt{@inforef\\{node\\}} node
+\\texttt{@inforef\\{node, cross ref name\\}} node
+\\texttt{@inforef\\{node,,file name\\}} Section ``node\'\' in \\texttt{file 
name}
+';
+
 1;
diff --git a/tp/t/results/converters_tests/ref_in_sectioning.pl 
b/tp/t/results/converters_tests/ref_in_sectioning.pl
index d582d4d05b..f90f911639 100644
--- a/tp/t/results/converters_tests/ref_in_sectioning.pl
+++ b/tp/t/results/converters_tests/ref_in_sectioning.pl
@@ -2979,4 +2979,41 @@ $result_converted{'docbook'}->{'ref_in_sectioning'} = 
'<chapter label="1" id="no
 </chapter>
 ';
 
+
+$result_converted{'latex'}->{'ref_in_sectioning'} = '
+\\label{anchor:Top}%
+\\chapter{See Section ``title\'\' in \\textsl{Manual}.}
+\\label{anchor:node}%
+
+\\chapter{\\texorpdfstring{\\hyperref[anchor:node]{\\chaptername~\\ref*{anchor:node}
 [node], page~\\pageref*{anchor:node}}}{node} just node}
+\\label{anchor:chap}%
+
+\\section{for example 
\\texorpdfstring{\\hyperref[anchor:node]{\\chaptername~\\ref*{anchor:node} 
[node], page~\\pageref*{anchor:node}}}{node} (\\texorpdfstring{see 
\\hyperref[anchor:node]{\\chaptername~\\ref*{anchor:node} [node], 
page~\\pageref*{anchor:node}}}{see node}) (see Section ``Top\'\' in 
\\textsl{Manual})}
+
+\\section{\\texorpdfstring{\\hyperref[anchor:node]{\\chaptername~\\ref*{anchor:node}
 [node], page~\\pageref*{anchor:node}}}{node}  node, crossref arg2}
+
+\\section{\\texorpdfstring{\\hyperref[anchor:node]{\\chaptername~\\ref*{anchor:node}
 [`\\texttt{title}\'], page~\\pageref*{anchor:node}}}{`\\texttt{title}\'}  code 
node, samptitle arg3}
+
+\\section{Section ``\\texttt{node}\'\' in \\texttt{file name} code node, file 
name}
+
+\\section{Section ``node\'\' in \\textsl{Manual} node and manual}
+
+\\section{Section ``Top\'\' in \\textsl{Manual} Top and manual}
+
+\\section{\\textsl{Manual} no node just manual}
+
+\\section{\\texttt{file name} no node just file name}
+
+\\section{Section ``a\'\' in \\texttt{c} inforef a b c}
+
+\\section{(see Section ``Top\'\' in \\texttt{file name}) pxref Top file name, 
spaces}
+
+\\section{(see \\texttt{file name}) pxref file name only, spaces}
+
+\\section{See Section ``Top\'\' in \\texttt{filename}, xref Top filename only, 
no spaces}
+
+\\section{See \\texttt{filename}. xref filename only, no spaces}
+
+';
+
 1;



reply via email to

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