[Po4a-commits] po4a/lib/Locale/Po4a TeX.pm,1.52,1.53 LaTeX.pm,1.4,1.5

Nicolas FRAN??OIS po4a-devel@lists.alioth.debian.org
Sun, 03 Apr 2005 22:51:19 +0000


Update of /cvsroot/po4a/po4a/lib/Locale/Po4a
In directory haydn:/tmp/cvs-serv19988/lib/Locale/Po4a

Modified Files:
	TeX.pm LaTeX.pm 
Log Message:
Add a generic way to specify separators in the TeX module.
Use separators for the tabular, enumerate and itemize environment and for
the author and title commands.


Index: LaTeX.pm
===================================================================
RCS file: /cvsroot/po4a/po4a/lib/Locale/Po4a/LaTeX.pm,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- LaTeX.pm	27 Feb 2005 18:04:28 -0000	1.4
+++ LaTeX.pm	3 Apr 2005 22:51:16 -0000	1.5
@@ -81,6 +81,7 @@
             $no_wrap_environments $separated_commands
             %commands             %environments
             %command_categories   %separated
+            %env_separators
             @exclude_include);
 *RE_ESCAPE             = \$Locale::Po4a::TeX::RE_ESCAPE;
 *ESCAPE                = \$Locale::Po4a::TeX::ESCAPE;
@@ -90,6 +91,7 @@
 *environments          = \%Locale::Po4a::TeX::environments;
 *command_categories    = \%Locale::Po4a::TeX::command_categories;
 *separated             = \%Locale::Po4a::TeX::separated;
+*env_separators        = \%Locale::Po4a::TeX::env_separators;
 *exclude_include       = \@Locale::Po4a::TeX::exclude_include;
 
 
@@ -313,7 +315,7 @@
             pushtabs *qquad *quad raggedbottom raggedleft raggedright right rm
             sc scriptsize sf sl small *smallskip *startbreaks *stopbreaks
             *tableofcontents textwidth textheight tiny today tt unitlength
-            vdots verb *vfill *vline fussy sloppy
+            vdots verb *vfill *vline *fussy *sloppy
 
             aleph hbar imath jmath ell wp Re Im prime nabla surd angle forall
             exists partial infty triangle Box Diamond flat natural sharp
@@ -341,5 +343,16 @@
             trivlist verbatim verse wrapfigure)) {
     $environments{$_} = \&push_environment;
 }
+
+
+# Commands and environments with separators.
+
+# & is the cell separator, \\ is the line separator
+# '\' is escaped twice
+$env_separators{'tabular'} = "(?:&|\\\\\\\\)";
+
+$env_separators{'enumerate'} = $env_separators{'itemize'} = "\\\\item";
+
+$env_separators{'author[#1]'} = $env_separators{'title[#1]'} = "\\\\\\\\";
 
 1;

Index: TeX.pm
===================================================================
RCS file: /cvsroot/po4a/po4a/lib/Locale/Po4a/TeX.pm,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -d -r1.52 -r1.53
--- TeX.pm	3 Apr 2005 22:44:31 -0000	1.52
+++ TeX.pm	3 Apr 2005 22:51:16 -0000	1.53
@@ -93,6 +93,8 @@
 # hash to describe the number of parameters and which one have to be
 # translated. Used by generic commands
 our %command_parameters = ();
+# hash to describe the separators of environments.
+our %env_separators =();
 
 # The escape character used to introduce commands.
 our $RE_ESCAPE = "\\\\";
@@ -202,6 +204,24 @@
 
 Indicates that the I<env1> environment should be handled by I<function1>.
 
+=item % po4a: separator <env> "<regex>"
+
+Indicates that an environment should be split according to the given
+regular expression.
+
+The regular expression is delimited by quotes.
+It should not create any backreference.
+You should use (?:) if you need a group.
+It may also need some escapes.  
+
+For example, the LaTeX module uses the "(?:&|\\\\)" regular expression to
+translate separately each cell of a table (lines are separated by '\\' and
+cells by '&'.
+
+The notion of environment is expended to the type displayed in the PO file.
+This can be used to split on "\\\\" in the first mandatory argument of the
+title command.  In this case, the environment is title[#1].
+
 =back
 
 See the B<INTERNAL FUNCTIONS> section for the list of function which could be
@@ -703,6 +723,28 @@
     } while (length($command));
 
     # Now, $buffer is just a block that can be translated.
+
+    # environment specific treatment
+    if (@env and defined $env_separators{$env[-1]}) {
+        my $re_separator = $env_separators{$env[-1]};
+        my $buf_begin = "";
+        while ($buffer =~ m/^(.*?)(\s*$re_separator\s*)(.*)$/s) {
+            my ($begin, $sep, $end) = ($1, $2, $3);
+            $buf_begin .= $begin;
+            if (is_closed($buf_begin)) {
+                my $t = "";
+                ($t, @env) = translate_buffer($self, $buf_begin, @env);
+                $translated_buffer .= $t.$sep;
+                $buf_begin = "";
+            } else {
+                # the command is in a command argument
+                $buf_begin .= $sep;
+            }
+            $buffer = $end;
+        }
+    }
+
+    # finally, translate
     if (length($buffer)) {
         my $wrap = 1;
         my ($e1, $e2);
@@ -940,6 +982,10 @@
                 die "Unknown environment ($1) for $env\n";
             }
         }
+    } elsif ($line =~ /^separator\s+(\w+(?:\[#[0-9]+\]))\s+\"(.*)\"\s*$/) {
+        my $env = $1; # This is not necessarily an environment.
+                      # It can also be smth like 'title[#1]'.
+        $env_separators{$env} = $2
     }
 }
 
@@ -1311,8 +1357,6 @@
 $environments{'verbatim'} = \&push_environment;
 $environments{'document'} = \&push_environment;
 
-# TODO: a tabular environment to translate cells separately
-
 ####################################
 ### INITIALIZATION OF THE PARSER ###
 ####################################
@@ -1400,9 +1444,10 @@
 
 =over 4
 
-=item tabular environment
+=item other categories
 
-A tabular environment would have to translate every cell separately.
+A verbatim category may be needed to indicate that po4a should not attempt
+to rewrap lines, and that percent signs do not introduce any comment.
 
 =item Others