texinfo-commits
[Top][All Lists]
Advanced

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

texinfo/tp Makefile.am Texinfo/Common.pm Texinf...


From: Patrice Dumas
Subject: texinfo/tp Makefile.am Texinfo/Common.pm Texinf...
Date: Tue, 11 Oct 2011 21:40:30 +0000

CVSROOT:        /sources/texinfo
Module name:    texinfo
Changes by:     Patrice Dumas <pertusus>        11/10/11 21:40:30

Modified files:
        tp             : Makefile.am 
        tp/Texinfo     : Common.pm Parser.pm 
        tp/Texinfo/Convert: HTML.pm 
Added files:
        tp/init        : tex4ht.pm 

Log message:
        Add an example for tex4ht.
        Really use GLOBAL_COMMANDS.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Makefile.am?cvsroot=texinfo&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Common.pm?cvsroot=texinfo&r1=1.74&r2=1.75
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Parser.pm?cvsroot=texinfo&r1=1.311&r2=1.312
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/HTML.pm?cvsroot=texinfo&r1=1.179&r2=1.180
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/init/tex4ht.pm?cvsroot=texinfo&rev=1.1

Patches:
Index: Makefile.am
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Makefile.am,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- Makefile.am 10 Oct 2011 00:07:54 -0000      1.8
+++ Makefile.am 11 Oct 2011 21:40:21 -0000      1.9
@@ -61,7 +61,8 @@
 dist_init_DATA = \
  init/book.pm \
  init/chm.pm \
- init/html32.pm
+ init/html32.pm \
+ init/tex4ht.pm
 
 test_files = \
  t/27float.t \

Index: Texinfo/Common.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Common.pm,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -b -r1.74 -r1.75
--- Texinfo/Common.pm   10 Oct 2011 21:08:44 -0000      1.74
+++ Texinfo/Common.pm   11 Oct 2011 21:40:25 -0000      1.75
@@ -149,7 +149,8 @@
   'DEFAULT_RULE', 'BIG_RULE',
   'MENU_ENTRY_COLON', 'INDEX_ENTRY_COLON', 'MENU_SYMBOL', 'DO_ABOUT',
   'CSS_FILES', 'CSS_REFS', 'BEFORE_OVERVIEW', 'AFTER_OVERVIEW',
-  'BEFORE_TOC_LINES', 'AFTER_TOC_LINES', 'GLOBAL_COMMANDS');
+  'BEFORE_TOC_LINES', 'AFTER_TOC_LINES', 'GLOBAL_COMMANDS',
+  'MAX_HEADER_LEVEL', 'MIN_HEADER_LEVEL');
 
 my %valid_options;
 foreach my $var (@document_settable_at_commands, @document_global_at_commands,

Index: Texinfo/Parser.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Parser.pm,v
retrieving revision 1.311
retrieving revision 1.312
diff -u -b -r1.311 -r1.312
--- Texinfo/Parser.pm   10 Oct 2011 21:08:44 -0000      1.311
+++ Texinfo/Parser.pm   11 Oct 2011 21:40:26 -0000      1.312
@@ -573,6 +573,12 @@
     $parser->{'expanded_formats_hash'}->{$expanded_format} = 1;
   }
 
+  %{$parser->{'global_commands'}} = %global_multiple_commands;
+
+  foreach my $global_command (@{$parser->{'GLOBAL_COMMANDS'}}) {
+    $parser->{'global_commands'}->{$global_command} = 1;
+  }
+
   $parser->Texinfo::Report::new;
 
   return $parser;
@@ -913,7 +919,7 @@
   my $command = shift;
   my $current = shift;
   my $line_nr = shift;
-  if ($global_multiple_commands{$command} and $command ne 'author') {
+  if ($self->{'global_commands'}->{$command} and $command ne 'author') {
     push @{$self->{'extra'}->{$command}}, $current;
     return 1;
   } elsif ($global_unique_commands{$command}) {

Index: Texinfo/Convert/HTML.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/HTML.pm,v
retrieving revision 1.179
retrieving revision 1.180
diff -u -b -r1.179 -r1.180
--- Texinfo/Convert/HTML.pm     10 Oct 2011 21:08:44 -0000      1.179
+++ Texinfo/Convert/HTML.pm     11 Oct 2011 21:40:27 -0000      1.180
@@ -4503,8 +4503,6 @@
   }
   $self->{'css_import_lines'} = address@hidden;
   $self->{'css_rule_lines'} = address@hidden;
-
-  &{$self->{'format_css_lines'}}($self);
 }
 
 sub _node_id_file($$)
@@ -6144,6 +6142,8 @@
 
   $self->run_stage_handlers('structure');
 
+  &{$self->{'format_css_lines'}}($self);
+
   $self->set_conf('BODYTEXT', 'lang="' . $self->get_conf('documentlanguage') 
    . '" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" 
alink="#FF0000"');
 

Index: init/tex4ht.pm
===================================================================
RCS file: init/tex4ht.pm
diff -N init/tex4ht.pm
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ init/tex4ht.pm      11 Oct 2011 21:40:29 -0000      1.1
@@ -0,0 +1,314 @@
+# -*-perl-*-
+
+#+##############################################################################
+#
+# tex4ht.pm: use tex4ht to convert tex to html
+#
+#    Copyright (C) 2005, 2007, 2009 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License,
+# or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+# Originally written by Patrice Dumas.
+#
+#-##############################################################################
+# To customize the command and the options, you could set
+# $Texi2HTML::TeX4HT::STYLE_MATH to latex/tex
+# $Texi2HTML::TeX4HT::STYLE_TEX to latex/texi
+# and/or change
+# $Texi2HTML::TeX4HT::tex4ht_command_math 
+#    and $Texi2HTML::TeX4HT::tex4ht_options_math
+# $Texi2HTML::TeX4HT::tex4ht_command_tex 
+#    and $Texi2HTML::TeX4HT::tex4ht_options_tex
+
+use strict;
+
+my $global_cmds = get_conf('GLOBAL_COMMANDS');
+if (!defined($global_cmds)) {
+  set_from_init_file('GLOBAL_COMMANDS', []);
+  $global_cmds = get_conf('GLOBAL_COMMANDS');
+}
+push @$global_cmds, ('math', 'tex');
+
+texinfo_register_handler('structure', \&tex4ht_prepare);
+texinfo_register_handler('init', \&tex4ht_convert);
+texinfo_register_handler('finish', \&tex4ht_finish);
+
+use vars qw(%commands_conversion);
+
+$commands_conversion{'math'} = \&tex4ht_do_tex;
+$commands_conversion{'tex'} = \&tex4ht_do_tex;
+
+{
+use Cwd;
+
+package Texinfo::TeX4HT;
+
+use vars qw(
+$STYLE_MATH
+$STYLE_TEX
+$tex4ht_command_math
+$tex4ht_command_tex
+$tex4ht_options_math
+$tex4ht_options_tex
+);
+
+$STYLE_MATH = 'texi' if (!defined($STYLE_MATH));
+$STYLE_TEX = 'tex' if (!defined($STYLE_TEX));
+
+if (!defined($tex4ht_command_math)) {
+  $tex4ht_command_math = 'httexi';
+  $tex4ht_command_math = 'htlatex' if ($STYLE_MATH eq 'latex');
+  $tex4ht_command_math = 'httex' if ($STYLE_MATH eq 'tex');
+}
+if (!defined($tex4ht_command_tex)) {
+  $tex4ht_command_tex = 'httex';
+  $tex4ht_command_tex = 'htlatex' if ($STYLE_TEX eq 'latex');
+  $tex4ht_command_tex = 'httexi' if ($STYLE_TEX eq 'texi');
+}
+
+}
+
+my %commands = ();
+
+my $tex4ht_initial_dir;
+my $tex4ht_out_dir;
+
+sub tex4ht_prepare($) {
+  # set file names
+  my $self = shift;
+
+  return if (defined($self->get_conf('OUTFILE'))
+        and $Texinfo::Common::null_device_file{$self->get_conf('OUTFILE')});
+
+  $tex4ht_initial_dir = Cwd::abs_path;
+  $tex4ht_out_dir = $self->{'destination_directory'};
+  $tex4ht_out_dir = './'
+    if (!defined($tex4ht_out_dir) or $tex4ht_out_dir =~ /^\s*$/);
+
+  my $document_name = $self->{'document_name'};
+  my $tex4ht_basename = "${document_name}_tex4ht";
+
+  # this initialization doesn't seems to be needed, but it is cleaner anyway
+  %commands = ();
+  $commands{'math'}->{'style'} = $Texinfo::TeX4HT::STYLE_MATH;
+  $commands{'tex'}->{'style'} = $Texinfo::TeX4HT::STYLE_TEX;
+  $commands{'math'}->{'exec'} = $Texinfo::TeX4HT::tex4ht_command_math;
+  $commands{'tex'}->{'exec'} = $Texinfo::TeX4HT::tex4ht_command_tex;
+  foreach my $command ('math', 'tex') {
+    my $style = $commands{$command}->{'style'};
+    $commands{$command}->{'basename'} = $tex4ht_basename . "_$command";
+    my $suffix = '.tex';
+    $suffix = '.texi' if ($style eq 'texi');
+    $commands{$command}->{'basefile'} = $commands{$command}->{'basename'} . 
$suffix;
+    $commands{$command}->{'html_file'} = $commands{$command}->{'basename'} . 
'.html';
+    $commands{$command}->{'rfile'} = $tex4ht_out_dir . 
$commands{$command}->{'basefile'};
+    my $rfile = $commands{$command}->{'rfile'};
+    $commands{$command}->{'counter'} = 0;
+
+    if ($self->{'extra'}->{$command}) {
+      local *TEX4HT_TEXFILE;
+      unless (open (*TEX4HT_TEXFILE, ">$rfile")) {
+        $self->document_warn ("t2h_tex4ht error opening $rfile: $!");
+        return;
+      }
+      $commands{$command}->{'handle'} = *TEX4HT_TEXFILE;
+
+      my $style = $commands{$command}->{'style'};
+      my $fh = $commands{$command}->{'handle'};
+      my $comment = '@c';
+      $comment = '%' if ($style ne 'texi');
+      $comment .= " Automatically generated\n";
+      if ($style eq 'texi') {
+        print $fh "\\input texinfo
address@hidden $commands{$command}->{'basename'}.info\n";
+        print $fh "$comment";
+      } else {
+        print $fh "$comment";
+        if ($style eq 'latex') {
+          print $fh "\\documentstyle{article}\n\\begin{document}\n";
+        } elsif ($style eq 'tex') {
+          print $fh "\\csname tex4ht\\endcsname\n";
+        }
+      }
+      foreach my $root (@{$self->{'extra'}->{$command}}) {
+        $commands{$command}->{'counter'}++;
+        my $counter = $commands{$command}->{'counter'};
+        my $tree;
+        if ($command eq 'math') {
+          $tree = $root->{'args'}->[0];
+        } else {
+          $tree = {'contents' => $root->{'contents'}};
+        }
+        my $text = Texinfo::Convert::Texinfo::convert($tree);
+        $commands{$command}->{'commands'}->[$counter-1] = $root;
+
+        # write to tex file
+        my ($before_comment_open, $after_comment_open, $before_comment_close,
+            $after_comment_close);
+
+        if ($style eq 'texi') {
+          $before_comment_open = "address@hidden";
+          $after_comment_open = "address@hidden verbatim\n";
+          $before_comment_close = "address@hidden";
+          $after_comment_close = "address@hidden verbatim\n";
+        } else {
+          $before_comment_open = "\\HCode{\\Hnewline \\Hnewline ";
+          $after_comment_open = "\\Hnewline}\n";
+          $before_comment_close = "\\HCode{\\Hnewline ";
+          $after_comment_close = "\\Hnewline \\Hnewline}\n";
+        }
+  
+        my $begin_comment = "<!-- tex4ht_begin 
$commands{$command}->{'basename'} $command $counter -->";
+        print $fh "$before_comment_open$begin_comment$after_comment_open";
+        if ($command eq 'tex') {
+          print $fh $text;
+        } elsif ($command eq 'math') {
+          if ($style eq 'texi') {
+            print $fh '@math{' . $text . "}\n";
+          } else {
+            print $fh "\\IgnorePar \$" . $text . "\$";
+          }
+        }
+        my $end_comment = "<!-- tex4ht_end $commands{$command}->{'basename'} 
$command $counter -->";
+        print $fh "$before_comment_close$end_comment$after_comment_close";
+      }
+      # finish the tex file
+      if ($style eq 'latex') {
+        print $fh "\\end{document}\n";
+      } elsif ($style eq 'tex') {
+        print $fh "\n\\bye\n";
+      } else {
+        print $fh "address@hidden";
+      }
+      close ($fh);
+      # this have to be done during the 'process' phase, in 'output' it is 
+      # too late.
+      push @{$self->{'css_import_lines'}}, 
+         "address@hidden \"$commands{$command}->{'basename'}.css\";\n";
+    }
+  }
+}
+
+sub tex4ht_convert ($)
+{
+  my $self = shift;
+  unless (chdir $tex4ht_out_dir) {
+    $self->document_warn ("t2h_tex4ht chdir to $tex4ht_out_dir failed");
+    return;
+  }
+  print STDERR "cwd($tex4ht_out_dir):" . Cwd::cwd() ."\n" 
+    if ($self->get_conf('VERBOSE'));
+
+  my $errors = 0;
+  foreach my $command (keys(%commands)) {
+    $errors += tex4ht_process_command($self, $command);
+  }
+  unless (chdir $tex4ht_initial_dir) {
+    die "* tex4ht unable to return to the initial dir\n";
+  }
+}
+
+sub tex4ht_process_command ($$) {
+  my $self = shift;
+  my $command = shift;
+  
+  return 0 unless ($commands{$command}->{'counter'});
+
+  $self->document_warn("tex4ht_process_command 
$commands{$command}->{'basefile'} missing") 
+    unless (-f $commands{$command}->{'basefile'});
+  my $style = $commands{$command}->{'style'};
+  # now run tex4ht
+  my $options = '';
+  if ($style eq 'math' and defined($Texinfo::TeX4HT::tex4ht_options_math)) {
+    $options = $Texinfo::TeX4HT::tex4ht_options_math 
+  } elsif ($style eq 'tex' and defined($Texinfo::TeX4HT::tex4ht_options_tex)) {
+    $options = $Texinfo::TeX4HT::tex4ht_options_tex;
+  }
+
+  my $cmd = "$commands{$command}->{'exec'} $commands{$command}->{'basefile'} 
$options";
+  print STDERR "tex4ht command: $cmd\n" if ($self->get_conf('VERBOSE'));
+  if (system($cmd)) {
+    $self->document_warn ("t2h_tex4ht command: $cmd failed");
+    return 1;
+  }
+
+  # extract the html from the file created by tex4ht
+  my $html_basefile = $commands{$command}->{'html_file'};
+  unless (open (TEX4HT_HTMLFILE, $html_basefile)) {
+    $self->document_warn ("t2h_tex4ht error opening $html_basefile: $!");
+    return 1;
+  }
+  my $got_count = 0;
+  my $line;
+  while ($line = <TEX4HT_HTMLFILE>) {
+    #print STDERR "$html_basefile: while $line";
+    if ($line =~ /!-- tex4ht_begin $commands{$command}->{'basename'} (\w+) 
(\d+) --/) {
+      my $command = $1;
+      my $count = $2;
+      my $text = '';
+      my $end_found = 0;
+      while ($line = <TEX4HT_HTMLFILE>) {
+        #print STDERR "while search $command $count $line";
+        if ($line =~ /!-- tex4ht_end $commands{$command}->{'basename'} 
$command $count --/) {
+          $got_count++;
+          chomp($text);
+          
$commands{$command}->{'results'}->{$commands{$command}->{'commands'}->[$count-1]}
 = $text;
+          $end_found = 1;
+          last;
+        } else {
+          $text .= $line;
+        }
+      }
+      unless ($end_found) {
+        $self->document_warn ("tex4ht_process_command: end of $command $count 
not found");
+      }
+    }
+  }
+  if ($got_count != $commands{$command}->{'counter'}) {
+    $self->document_warn ("t2h_tex4ht: got $got_count for 
$commands{$command}->{'counter'} items entered");
+  }
+  close (TEX4HT_HTMLFILE);
+  return 0;
+}
+
+sub tex4ht_do_tex($$$$)
+{
+  my $self = shift;
+  my $cmdname = shift;;
+  my $command = shift;
+  # return the resulting html 
+  if (exists ($commands{$cmdname}->{'results'}->{$command})
+      and defined($commands{$cmdname}->{'results'}->{$command})) {
+     $commands{$cmdname}->{'output_counter'}++;
+     return $commands{$cmdname}->{'results'}->{$command};
+  } else {
+    $self->document_warn ("tex4ht_do_tex: no text for address@hidden 
$command");
+    return '';
+  }
+}
+
+sub tex4ht_finish($)
+{
+  my $self = shift;
+  my $tex4ht_in_counter = 0;
+  if ($self->get_conf('VERBOSE')) {
+    foreach my $command (keys(%commands)) {
+      if ($commands{$command}->{'output_counter'} != 
$commands{$command}->{'counter'}) {
+        $self->line_warn ("tex4ht_finish: address@hidden output counter 
$commands{$command}->{'output_counter'}, counter 
$commands{$command}->{'counter'}");
+      }
+    }
+  }
+}
+
+1;  



reply via email to

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