texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: @r resets the code context in LaTeX to have -- an


From: Patrice Dumas
Subject: branch master updated: @r resets the code context in LaTeX to have -- and --- as ligature
Date: Sun, 31 Jul 2022 12:04:30 -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 277fa17a09 @r resets the code context in LaTeX to have -- and --- as 
ligature
277fa17a09 is described below

commit 277fa17a09f947446c482f306577c6ab84c6b250
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Jul 31 18:04:19 2022 +0200

    @r resets the code context in LaTeX to have -- and --- as ligature
    
    * tp/Texinfo/Convert/LaTeX.pm (_push_new_context, _convert):
    turn 'code' context to an array, such that @r can reset the state
    by pushing on the array.
---
 ChangeLog                                          |  8 +++++
 tp/Texinfo/Convert/LaTeX.pm                        | 40 +++++++++++++---------
 .../res_latex/definition_commands.tex              | 14 ++++----
 .../res_parser/formatting_latex/formatting.tex     |  2 +-
 4 files changed, 39 insertions(+), 25 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 1cf14a2896..af7bea5a2a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2022-07-31  Patrice Dumas  <pertusus@free.fr>
+
+       @r resets the code context in LaTeX to have -- and --- as ligature
+
+       * tp/Texinfo/Convert/LaTeX.pm (_push_new_context, _convert):
+       turn 'code' context to an array, such that @r can reset the state
+       by pushing on the array.
+
 2022-07-31  Gavin Smith  <gavinsmith0123@gmail.com>
 
        * doc/texinfo.tex (\r): Output -- and --- as ligature even if in code.
diff --git a/tp/Texinfo/Convert/LaTeX.pm b/tp/Texinfo/Convert/LaTeX.pm
index 9bab935c23..5ad894b747 100644
--- a/tp/Texinfo/Convert/LaTeX.pm
+++ b/tp/Texinfo/Convert/LaTeX.pm
@@ -1548,6 +1548,7 @@ sub _latex_footer {
 ';
 }
 
+# all the new contexts should be created with that function
 sub _push_new_context($$)
 {
   my $self = shift;
@@ -1558,7 +1559,8 @@ sub _push_new_context($$)
        'text_context' => ['text'],
        'preformatted_context' => [],
        'math_style' => [],
-       'code' => 0,
+       # an array such that @r can reset the state by pushing on the array
+       'code' => [0],
        'dot_not_end_sentence' => 0,
        'in_quotation' => 0,
        'type' => $context_name,
@@ -1638,7 +1640,7 @@ sub _protect_text($$)
     if ($self->{'formatting_context'}->[-1]->{'index'}) {
       $text = _protect_index_text($text);
     }
-    if ($self->{'formatting_context'}->[-1]->{'code'}) {
+    if ($self->{'formatting_context'}->[-1]->{'code'}->[-1]) {
       $text =~ s/---/{-}{-}{-}/g;
       $text =~ s/--/{-}{-}/g;
     }
@@ -1838,7 +1840,7 @@ sub _open_preformatted($$)
   my $command = 
$self->{'formatting_context'}->[-1]->{'preformatted_context'}->[-1];
 
   if ($preformatted_code_commands{$command}) {
-    $self->{'formatting_context'}->[-1]->{'code'} += 1;
+    $self->{'formatting_context'}->[-1]->{'code'}->[-1] += 1;
   }
 
   # no preformatted formatting if in a @table item, it leads
@@ -1868,7 +1870,7 @@ sub _close_preformatted($$)
 
   my $command = 
$self->{'formatting_context'}->[-1]->{'preformatted_context'}->[-1];
   if ($preformatted_code_commands{$command}) {
-    $self->{'formatting_context'}->[-1]->{'code'} -= 1;
+    $self->{'formatting_context'}->[-1]->{'code'}->[-1] -= 1;
   }
   return ''
    if 
(scalar(@{$self->{'formatting_context'}->[-1]->{'nr_table_items_context'}}));
@@ -2096,11 +2098,11 @@ sub _index_entry($$)
       my $sortas;
       my ($subentry, $subentry_sortas) = @$subentry_entry_and_sortas;
       if ($in_code) {
-        $self->{'formatting_context'}->[-1]->{'code'} += 1;
+        $self->{'formatting_context'}->[-1]->{'code'}->[-1] += 1;
       }
       my $index_entry = _convert($self, $subentry);
       if ($in_code) {
-        $self->{'formatting_context'}->[-1]->{'code'} -= 1;
+        $self->{'formatting_context'}->[-1]->{'code'}->[-1] -= 1;
         # always setup a string to sort with code as we use a command
         $sortas = Texinfo::Structuring::index_entry_sort_string($entry,
                                  $subentry, $subentry_sortas, $options);
@@ -2421,11 +2423,13 @@ sub _convert($$)
         $result .= $self->{'quotes_map'}->{$cmdname}->[0];
       }
       if ($code_style_commands{$cmdname}) {
-        $self->{'formatting_context'}->[-1]->{'code'} += 1;
+        $self->{'formatting_context'}->[-1]->{'code'}->[-1] += 1;
+      } elsif ($cmdname eq 'r') {
+        push @{$self->{'formatting_context'}->[-1]->{'code'}}, 0;
       }
       # specific macro for typewriter + other style
       my $formatting_context = $command_context;
-      if ($self->{'formatting_context'}->[-1]->{'code'}
+      if ($self->{'formatting_context'}->[-1]->{'code'}->[-1]
           and $command_context eq 'text'
           and $LaTeX_style_brace_commands{$code_text_context}->{$cmdname}) {
         $formatting_context = $code_text_context;
@@ -2457,7 +2461,9 @@ sub _convert($$)
         $result .= '}';
       }
       if ($code_style_commands{$cmdname}) {
-        $self->{'formatting_context'}->[-1]->{'code'} -= 1;
+        $self->{'formatting_context'}->[-1]->{'code'}->[-1] -= 1;
+      } elsif ($cmdname eq 'r') {
+        pop @{$self->{'formatting_context'}->[-1]->{'code'}};
       }
       if ($self->{'quotes_map'}->{$cmdname}) {
         $result .= $self->{'quotes_map'}->{$cmdname}->[1];
@@ -2480,9 +2486,9 @@ sub _convert($$)
         $result .= "{$kbd_formatting_latex\{";
       }
       if ($element->{'args'}) {
-        $self->{'formatting_context'}->[-1]->{'code'} += 1;
+        $self->{'formatting_context'}->[-1]->{'code'}->[-1] += 1;
         $result .= _convert($self, $element->{'args'}->[0]);
-        $self->{'formatting_context'}->[-1]->{'code'} -= 1;
+        $self->{'formatting_context'}->[-1]->{'code'}->[-1] -= 1;
       }
       if ($code_font) {
         if ($LaTeX_style_brace_commands{$command_context}->{'code'}) {
@@ -2690,9 +2696,9 @@ sub _convert($$)
         }
         my $filename = '';
         if ($file_contents) {
-          $self->{'formatting_context'}->[-1]->{'code'} += 1;
+          $self->{'formatting_context'}->[-1]->{'code'}->[-1] += 1;
           $filename = _convert($self, {'contents' => $file_contents});
-          $self->{'formatting_context'}->[-1]->{'code'} -= 1;
+          $self->{'formatting_context'}->[-1]->{'code'}->[-1] -= 1;
         }
         
         if ($cmdname ne 'inforef' and $book eq '' and $filename eq ''
@@ -3214,11 +3220,11 @@ sub _convert($$)
           }
         }
         if ($code_style) {
-          $self->{'formatting_context'}->[-1]->{'code'} += 1;
+          $self->{'formatting_context'}->[-1]->{'code'}->[-1] += 1;
         }
         my $converted_arg = _convert($self, $element->{'args'}->[0]);
         if ($code_style) {
-          $self->{'formatting_context'}->[-1]->{'code'} -= 1;
+          $self->{'formatting_context'}->[-1]->{'code'}->[-1] -= 1;
         }
         $self->{'formatting_context'}->[-1]->{'nr_table_items_context'}->[-1] 
-= 1;
         my $description_format_command
@@ -3529,7 +3535,7 @@ sub _convert($$)
 
         $result .= '\noindent\texttt{';
         # the def* line except for the category is converted in code context
-        $self->{'formatting_context'}->[-1]->{'code'} += 1;
+        $self->{'formatting_context'}->[-1]->{'code'}->[-1] += 1;
 
         if ($element->{'extra'}->{'def_parsed_hash'}->{'type'}) {
           $result .=  _convert($self,
@@ -3570,7 +3576,7 @@ sub _convert($$)
           }
         }
 
-        $self->{'formatting_context'}->[-1]->{'code'} -= 1;
+        $self->{'formatting_context'}->[-1]->{'code'}->[-1] -= 1;
         $result .= '}'; # \texttt
 
         my $category;
diff --git 
a/tp/t/results/converters_tests/definition_commands/res_latex/definition_commands.tex
 
b/tp/t/results/converters_tests/definition_commands/res_latex/definition_commands.tex
index a7f3c9b521..f61d75fe0e 100644
--- 
a/tp/t/results/converters_tests/definition_commands/res_latex/definition_commands.tex
+++ 
b/tp/t/results/converters_tests/definition_commands/res_latex/definition_commands.tex
@@ -85,7 +85,7 @@ deffn no var for \textsl{a---rg1} and \textsl{a--rg2}
 \index[fn]{fname@\texttt{fname}}%
 deffn explict var for \textsl{a---rg1} and \textsl{a--rg2}
 
-\noindent\texttt{fname 
\EmbracOn{}\textsl{\EmbracOff{}\textnormal{\textsl{a{-}{-}{-}rg1}}\EmbracOn{} 
\EmbracOff{}\textnormal{\textsl{a{-}{-}rg2}}\EmbracOn{}}\EmbracOff{}}\hfill[Func]
+\noindent\texttt{fname 
\EmbracOn{}\textsl{\EmbracOff{}\textnormal{\textsl{a---rg1}}\EmbracOn{} 
\EmbracOff{}\textnormal{\textsl{a--rg2}}\EmbracOn{}}\EmbracOff{}}\hfill[Func]
 
 
 
@@ -156,7 +156,7 @@ separators
 
 
 \index[fn]{foobar@\texttt{foobar}}%
-\noindent\texttt{foobar 
\EmbracOn{}\textsl{\EmbracOff{}\textnormal{va{-}{-}{-}riable}\EmbracOn{} 
r}\EmbracOff{}}\hfill[Special Form]
+\noindent\texttt{foobar 
\EmbracOn{}\textsl{\EmbracOff{}\textnormal{va---riable}\EmbracOn{} 
r}\EmbracOff{}}\hfill[Special Form]
 
 
 
@@ -188,12 +188,12 @@ separators
 
\cs_undefine:N{\embrac_texttt:nn}\cs_undefine:N{\embrac_orig_texttt:n}\cs_undefine:N{\__embrac_texttt:n}%
 \ExplSyntaxOff%
 \index[fn]{foobar@\texttt{foobar}}%
-\noindent\texttt{foobar 
\EmbracOn{}\textsl{\EmbracOff{}\textnormal{\textsl{va{-}{-}{-}riable}}\EmbracOn{}
 r:var}\EmbracOff{}}\hfill[Special Form]
+\noindent\texttt{foobar 
\EmbracOn{}\textsl{\EmbracOff{}\textnormal{\textsl{va---riable}}\EmbracOn{} 
r:var}\EmbracOff{}}\hfill[Special Form]
 
 
 
 \index[fn]{foobar@\texttt{foobar}}%
-\noindent\texttt{foobar 
\EmbracOn{}\textsl{\EmbracOff{}\textnormal{\textsl{va{-}{-}{-}riable}}\EmbracOn{}
 r:slanted}\EmbracOff{}}\hfill[Special Form]
+\noindent\texttt{foobar 
\EmbracOn{}\textsl{\EmbracOff{}\textnormal{\textsl{va---riable}}\EmbracOn{} 
r:slanted}\EmbracOff{}}\hfill[Special Form]
 
 
 
@@ -264,7 +264,7 @@ test formatting of separators
 \index[fn]{foobar@\texttt{foobar}}%
 \dots{}\@ with var for \textsl{f---oo} and \textsl{b--ar}
 
-\noindent\texttt{int foobar (int \textnormal{\textsl{f{-}{-}{-}oo}}, float 
\textnormal{\textsl{b{-}{-}ar}})}\hfill[Library Function]
+\noindent\texttt{int foobar (int \textnormal{\textsl{f---oo}}, float 
\textnormal{\textsl{b--ar}})}\hfill[Library Function]
 
 
 
@@ -370,7 +370,7 @@ separators
 
 
 \index[fn]{foobar@\texttt{foobar}}%
-\noindent\texttt{int foobar (\textnormal{i{-}{-}nt} \textsl{f{-}{-}{-}oo}[, 
float \textsl{b{-}{-}ar}]) r}\hfill[Library Function]
+\noindent\texttt{int foobar (\textnormal{i--nt} \textsl{f{-}{-}{-}oo}[, float 
\textsl{b{-}{-}ar}]) r}\hfill[Library Function]
 
 
 
@@ -395,7 +395,7 @@ separators
 
 
 \index[fn]{foobar@\texttt{foobar}}%
-\noindent\texttt{int foobar (\textnormal{\textsl{i{-}{-}nt}} 
\textsl{f{-}{-}{-}oo}[, float \textsl{b{-}{-}ar}]) r:slanted}\hfill[Library 
Function]
+\noindent\texttt{int foobar (\textnormal{\textsl{i--nt}} 
\textsl{f{-}{-}{-}oo}[, float \textsl{b{-}{-}ar}]) r:slanted}\hfill[Library 
Function]
 
 
 
diff --git a/tp/tests/layout/res_parser/formatting_latex/formatting.tex 
b/tp/tests/layout/res_parser/formatting_latex/formatting.tex
index a438c65180..eea7672797 100644
--- a/tp/tests/layout/res_parser/formatting_latex/formatting.tex
+++ b/tp/tests/layout/res_parser/formatting_latex/formatting.tex
@@ -5594,7 +5594,7 @@ but , ,\@
 \texttt{@key\{{-}{-}a\}} \texttt{{-}{-}a}
 \texttt{@math\{{-}{-}a \{\textbackslash{}frac\{1\}\{2\}\} @minus\{\}\}} $--a 
{\frac{1}{2}} -$
 \texttt{@option\{{-}{-}a\}} \texttt{{-}{-}a}
-\texttt{@r\{{-}{-}a\}} \textnormal{{-}{-}a}
+\texttt{@r\{{-}{-}a\}} \textnormal{--a}
 \texttt{@samp\{{-}{-}a\}} `\texttt{{-}{-}a}'
 \texttt{@sc\{{-}{-}a\}} \textsc{{-}{-}a}
 \texttt{@strong\{{-}{-}a\}} \textbf{{-}{-}a}



reply via email to

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