texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Texinfo/Convert/LaTeX.pm (%Latex_no_arg_brac


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/Convert/LaTeX.pm (%Latex_no_arg_brace_commands, %LaTeX_text_only_no_arg_brace_commands, _latex_header, _convert): use LaTeX commands for @-commands with braces and no argument. * tp/Texinfo/Convert/LaTeX.pm (_latex_header, %LaTeX_encoding_names_map): use OUTPUT_ENCODING_NAME to determine output encoding. * tp/Texinfo/Convert/LaTeX.pm (%defaults): set EXTENSION to tex. * tp/Texinfo/Convert/LaTeX.pm (output, convert, convert_tree): make output() more general, add convert() and c [...]
Date: Sun, 08 Aug 2021 12:42:02 -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 4fe7915  * tp/Texinfo/Convert/LaTeX.pm (%Latex_no_arg_brace_commands, 
%LaTeX_text_only_no_arg_brace_commands, _latex_header, _convert): use LaTeX 
commands for @-commands with braces and no argument. * 
tp/Texinfo/Convert/LaTeX.pm (_latex_header, %LaTeX_encoding_names_map): use 
OUTPUT_ENCODING_NAME to determine output encoding. * 
tp/Texinfo/Convert/LaTeX.pm (%defaults): set EXTENSION to tex. * 
tp/Texinfo/Convert/LaTeX.pm (output, convert, convert_tree): make output() more 
general,  [...]
4fe7915 is described below

commit 4fe7915ecae2a3e64f8b1445d99819c11a4a8b29
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Aug 8 18:41:50 2021 +0200

    * tp/Texinfo/Convert/LaTeX.pm (%Latex_no_arg_brace_commands,
    %LaTeX_text_only_no_arg_brace_commands, _latex_header, _convert):
    use LaTeX commands for @-commands with braces and no argument.
    * tp/Texinfo/Convert/LaTeX.pm (_latex_header,
    %LaTeX_encoding_names_map): use OUTPUT_ENCODING_NAME to determine
    output encoding.
    * tp/Texinfo/Convert/LaTeX.pm (%defaults): set EXTENSION to tex.
    * tp/Texinfo/Convert/LaTeX.pm (output, convert, convert_tree):
    make output() more general, add convert() and convert_tree().
---
 ChangeLog                   |  12 +++
 tp/Texinfo/Convert/LaTeX.pm | 221 +++++++++++++++++++++++++++++++++++++-------
 2 files changed, 201 insertions(+), 32 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 99fd4c8..b18f096 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2021-08-08  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Convert/LaTeX.pm (%Latex_no_arg_brace_commands,
+       %LaTeX_text_only_no_arg_brace_commands, _latex_header, _convert):
+       use LaTeX commands for @-commands with braces and no argument.
+       * tp/Texinfo/Convert/LaTeX.pm (_latex_header, 
+       %LaTeX_encoding_names_map): use OUTPUT_ENCODING_NAME to determine
+       output encoding.
+       * tp/Texinfo/Convert/LaTeX.pm (%defaults): set EXTENSION to tex.
+       * tp/Texinfo/Convert/LaTeX.pm (output, convert, convert_tree):
+       make output() more general, add convert() and convert_tree().
+
 2021-08-07  Patrice Dumas  <pertusus@free.fr>
 
        * tp/tests/layout/list-of-tests,
diff --git a/tp/Texinfo/Convert/LaTeX.pm b/tp/Texinfo/Convert/LaTeX.pm
index 39434a9..b4e1079 100644
--- a/tp/Texinfo/Convert/LaTeX.pm
+++ b/tp/Texinfo/Convert/LaTeX.pm
@@ -126,6 +126,106 @@ foreach my $misc_command (keys(%misc_commands)) {
     unless ($formatting_misc_commands{$misc_command});
 }
 
+my %Latex_no_arg_brace_commands = (
+   # textmode
+  'text' => {
+    'TeX' => '\TeX{}',
+    'LaTeX' => '\LaTeX{}',
+    'bullet' => '\textbullet{}',
+    'copyright' => '\copyright{}',
+    'registeredsymbol' => '\circledR{}',
+    'dots' => '\dots{}\@',
+    'enddots' => '\dots{}',
+    'equiv' => '$\equiv{}$',
+    'error' => '\fbox{error}',
+    'expansion' => '$\mapsto{}$',
+    'arrow' => '$\rightarrow{}$',
+    'minus' => '-',
+    'point' => '$\star{}$',
+    'print' => '$\dashv{}$',
+    'result' => '$\Rightarrow{}$',
+    'pounds' => '\textsterling{}',
+    'atchar', => '@',
+    'lbracechar' => '\{',
+    'rbracechar' => '\}',
+    'backslashchar' => '\textbackslash{}',
+    'hashchar' => '\#',
+    'comma' => ',',
+    'ampchar' => '\&',
+    'euro' => '\euro{}',
+    'geq' => '$\geq{}$',
+    'leq' => '$\leq{}$',
+    'textdegree' => '\textdegree{}',
+    'tie' => '\hbox{}',
+  },
+  'math' => {
+    'TeX' => 'TeX',
+    'LaTeX' => 'LaTeX',
+    'bullet' => '\bullet{}',
+    'copyright' => '\copyright{}',
+    'registeredsymbol' => '\circledR{}',
+    'dots' => '\dots{}',
+    'enddots' => '\dots{}',
+    'equiv' => '\equiv{}',
+    'error' => '\fbox{error}',
+    'expansion' => '\mapsto{}',
+    'arrow' => '\rightarrow{}',
+    'minus' => '-',
+    'point' => '\star{}',
+    'print' => '\dashv{}',
+    'result' => '\Rightarrow{}',
+    'pounds' => '\mathsterling{}',
+    'atchar', => '@',
+    'lbracechar' => '\{',
+    'rbracechar' => '\}',
+    'backslashchar' => '\backslash{}',
+    'hashchar' => '\#',
+    'comma' => ',',
+    'ampchar' => '\&',
+    'euro' => '\euro{}',
+    'geq' => '\geq{}',
+    'leq' => '\leq{}',
+    'textdegree' => '^{\circ{}}',
+    'tie' => '\hbox{}',
+  }
+);
+# TODO check 'click'
+
+my %LaTeX_text_only_no_arg_brace_commands = (
+  'exclamdown' => 'textexclamdown',
+  'questiondown' => 'textquestiondown',
+  'ordf' => 'textordfeminine',
+  'ordm' => 'textordmasculine',
+  'quotedblleft' => 'textquotedblleft',
+  'quotedblright' => 'textquotedblright',
+  'quoteleft' => 'textquoteleft',
+  'quoteright' => 'textquoteright',
+  'quotedblbase' => 'quotedblbase',
+  'quotesinglbase' => 'quotesinglbase',
+  'guillemetleft', => 'guillemotleft',
+  'guillemetright' => 'guillemotright',
+  'guillemotleft' => 'guillemotleft',
+  'guillemotright' => 'guillemotright',
+  'guilsinglleft' => 'guilsinglleft',
+  'guilsinglright' => 'guilsinglright',
+);
+
+foreach my $letter_no_arg_command ('aa','AA','ae','oe','AE','OE','o','O',
+                                   'ss','l','L','DH','dh','TH','th') {
+  $LaTeX_text_only_no_arg_brace_commands{$letter_no_arg_command}
+   = $letter_no_arg_command;
+}
+
+foreach my $text_only_no_arg_brace_command
+     (keys(%LaTeX_text_only_no_arg_brace_commands)) {
+  my $LaTeX_command =
+    
"\\$LaTeX_text_only_no_arg_brace_commands{$text_only_no_arg_brace_command}\{\}";
+  $Latex_no_arg_brace_commands{'text'}->{$text_only_no_arg_brace_command} 
+    = $LaTeX_command;
+  $Latex_no_arg_brace_commands{'math'}->{$text_only_no_arg_brace_command}
+    = '\mathord{\text{'.$LaTeX_command.'}}';
+}
+
 my %ignored_commands = %ignored_misc_commands;
 foreach my $ignored_brace_commands ('caption', 'shortcaption', 
   'hyphenation', 'sortas') {
@@ -163,6 +263,13 @@ foreach my $format_context_command (keys(%menu_commands), 
'verbatim',
   $default_format_context_commands{$format_context_command} = 1;
 }
 
+# environments existing in LaTeX
+# 'flushleft' => 'flushleft',
+# 'flushright' => 'flushright',
+#
+# for a linebreak for @*?
+# \linebreak[4]
+
 my %flush_commands = (
   'flushleft'  => 1,
   'flushright' => 1
@@ -173,11 +280,6 @@ foreach my $ignored_block_commands ('ignore', 'macro', 
'rmacro', 'copying',
   $ignored_commands{$ignored_block_commands} = 1;
 }
 
-my %punctuation_no_arg_commands;
-foreach my $punctuation_command('enddots', 'exclamdown', 'questiondown') {
-  $punctuation_no_arg_commands{$punctuation_command} = 1;
-}
-
 my %upper_case_commands = (
  'sc' => 1,
  'var' => 1
@@ -213,6 +315,10 @@ foreach my $command (keys(%style_map)) {
   $style_map{$command} = [$style_map{$command}, $style_map{$command}];
 }
 
+# verb exists in latex.  'extra' => {
+#            'delimiter' => '*'
+
+
 # math is special
 my @asis_commands = ('asis', 'w', 'b', 'i', 'sc', 't', 'r',
   'slanted', 'sansserif', 'var', 'verb', 'clicksequence',
@@ -262,7 +368,7 @@ my %defaults = (
   'ENABLE_ENCODING'      => 1,
   'FORMAT_MENU'          => 'nomenu',
   #'EXTENSION'            => 'info',
-  'EXTENSION'            => 'txt',
+  'EXTENSION'            => 'tex',
   #'USE_SETFILENAME_EXTENSION' => 1,
   'INFO_SPECIAL_CHARS_WARNING' => 1,
 
@@ -361,13 +467,41 @@ sub converter_initialize($)
   return $self;
 }
 
+my %LaTeX_encoding_names_map = (
+  'utf-8' => 'utf8',
+);
+
+# ellipsis leaves less spacing after \dots in case it is followed
+# by punctuation. It does not seem to fix the @dots verusus @enddots issue
+# to be loaded after Babel if you are using the French option
+# FIXME use it anyway?
+# \usepackage{ellipsis}
 
 sub _latex_header {
-  return
+  my $self = shift;
+  # amsfonts for \circledR
+  # T1 fontenc for \DH, \guillemotleft
+  # eurosym for \euro
+  my $header = 
 '\documentclass{book}
 \usepackage{makeidx}\makeindex
-\begin{document}
+\usepackage{amsfonts}
+\usepackage[gen]{eurosym}
+\usepackage[T1]{fontenc}
+';
+  if ($self->get_conf('OUTPUT_ENCODING_NAME')) {
+    my $encoding = $self->get_conf('OUTPUT_ENCODING_NAME');
+    if (defined($LaTeX_encoding_names_map{$encoding})) {
+      $encoding = $LaTeX_encoding_names_map{$encoding};
+    }# else {
+      # FIXME Warn?
+    #}
+    $header .= "\\usepackage[$encoding]{inputenc}\n";
+  }
+  $header .= 
+'\begin{document}
 ';
+  return $header;
 }
 
 sub _latex_footer {
@@ -380,16 +514,55 @@ sub output($$)
 {
   my ($self, $root) = @_;
 
+  $self->_set_outfile();
+  return undef unless $self->_create_destination_directory();
+
+  my $fh;
+  if (! $self->{'output_file'} eq '') {
+    $fh = $self->Texinfo::Common::open_out ($self->{'output_file'});
+    if (!$fh) {
+      $self->document_error(sprintf(__("could not open %s for writing: %s"),
+                                    $self->{'output_file'}, $!));
+      return undef;
+    }
+  }
+
+  $self->_set_global_multiple_commands(-1);
+
   my $result = '';
 
-  $result .= $self->_latex_header();
-  $result .= $self->_convert($root);
-  $result .= $self->_latex_footer();
+  $result .= $self->_output_text($self->_latex_header(), $fh);
+  $result .= $self->convert_document_sections($root, $fh);
+  $result .= $self->_output_text($self->_latex_footer(), $fh);
 
-  print $result;
+  #print $result;
+  if ($fh and $self->{'output_file'} ne '-') {
+    $self->register_close_file($self->{'output_file'});
+    if (!close ($fh)) {
+      $self->document_error(sprintf(__("error on closing %s: %s"),
+                                    $self->{'output_file'}, $!));
+    }
+  }
+  return $result
 }
 
+sub convert($$;$)
+{
+  my $self = shift;
+  my $root = shift;
+  my $fh = shift;
+
+  $self->_set_global_multiple_commands(-1);
+  return $self->convert_document_sections($root, $fh);
+}
 
+sub convert_tree($$)
+{
+  my $self = shift;
+  my $root = shift;
+
+  return $self->_convert($root);
+}
 
 sub convert_line($$;$)
 {
@@ -638,30 +811,14 @@ sub _convert($$)
       my $today = $self->Texinfo::Common::expand_today();
       unshift @{$self->{'current_contents'}->[-1]}, $today;
     } elsif (exists($brace_no_arg_commands{$command})) {
-      my $text;
-      
-      if ($command eq 'dots' or $command eq 'enddots') {
-        # Don't use Unicode ellipsis character.
-        $text = '...';
+      if (exists($Latex_no_arg_brace_commands{'text'}->{$command})) {
+        $result .= $Latex_no_arg_brace_commands{'text'}->{$command};
       } else {
-        $text = Texinfo::Convert::Text::brace_no_arg_command($root, 
+        my $text = Texinfo::Convert::Text::brace_no_arg_command($root, 
                                            $self->{'convert_text_options'});
-      }
-
-      if ($punctuation_no_arg_commands{$command}) {
-        $result .= _protect_text($text);
-        # should have an end sentence space after @enddots
-      } elsif ($command eq 'tie') {
-        $result .= '\hbox{';
         $result .= _protect_text($text);
-        $result .= '}';
-      } else {
-        $result .= _protect_text($text);
-
-        if ($command eq 'dots') {
-          $result .= '\\@';
-        }
       }
+
       return $result;
     # commands with braces
     } elsif ($accent_commands{$command}) {



reply via email to

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