]> git.lyx.org Git - features.git/commitdiff
pass $...$ and $$...$$ through reLyX unchanged
authorAngus Leeming <leeming@lyx.org>
Fri, 7 Feb 2003 12:11:58 +0000 (12:11 +0000)
committerAngus Leeming <leeming@lyx.org>
Fri, 7 Feb 2003 12:11:58 +0000 (12:11 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6053 a592a061-630c-0410-9148-cb99ea01b6c8

lib/ChangeLog
lib/reLyX/BasicLyX.pm
lib/reLyX/CleanTeX.pm
lib/reLyX/Verbatim.pm

index 6ea82817cbe4f1e71b8170f7f67e118ae3682f11..4926cbb4d5970599a12ed0ade2a0c4e5e27ca811 100644 (file)
@@ -2,6 +2,9 @@
 
        * lyx2lyx/lyx2lyx: enable the debug level to be set.
 
+       * reLyX/BasicLyX.pm, reLyX/CleanTeX.pm, reLyX/Verbatim.pm: pass
+       $...$ and $$...$$ through reLyX unchanged.
+
 2003-02-04  Joao Luis Meloni Assirati  <assirati@fma.if.usp.br>
 
        * images/math/rbracket.xpm: new file.
index 5e72be223fb691aabebf05f58848a670fd02aac4..7ea9ecc46c9143b38b4e69d149ce6fc9d342fd51 100644 (file)
@@ -290,6 +290,42 @@ sub call_parser {
     return;
 } # end subroutine call_parser
 
+# This is used as a toggle so that we know what to do when basic_lyx is
+# passed a '$' or '$$' token.
+my $inside_math=0;
+
+sub starting_math {
+    my $name = shift;
+
+    if ($name eq '\(' || $name eq '\[' ||
+       # These tokens bound both ends of a math environment so we must check
+       # $inside_math to know what action to take.
+       ($name eq '$' || $name eq '$$') && !$inside_math) {
+
+       $inside_math = 1;
+       return 1;
+    }
+
+    # All other tokens
+    return 0;
+}
+
+sub ending_math {
+    my $name = shift;
+
+    if ($name eq '\)' || $name eq '\]' ||
+       # These tokens bound both ends of a math environment so we must check
+       # $inside_math to know what action to take.
+       ($name eq '$' || $name eq '$$') && $inside_math) {
+
+       $inside_math = 0;
+       return 1;
+    }
+
+    # All other tokens
+    return 0;
+}
+
 ##########################   MAIN TRANSLATOR SUBROUTINE   #####################
 sub basic_lyx {
 # This subroutine is called by Text::TeX::process each time subroutine
@@ -388,7 +424,7 @@ sub basic_lyx {
                              "\n\n\\end_inset \n\n";
 
            # Math -- copy verbatim until you're done
-           } elsif ($name eq '\(' || $name eq '\[') {
+           } elsif (starting_math($name)) {
                print "\nCopying math beginning with '$name'\n" if $debug_on;
                # copy everything until end text
                $dummy = &Verbatim::copy_verbatim($fileobject, $eaten);
@@ -399,7 +435,7 @@ sub basic_lyx {
                print $dummy if $debug_on;
                print OUTFILE $dummy;
 
-           } elsif ($name eq '\)' || $name eq '\]') {
+           } elsif (ending_math($name)) {
                # end math
                print OUTFILE "$name\n\\end_inset \n\n";
                print "\nDone copying math ending with '$name'" if $debug_on;
index 001af0cf70dc077f8d3fa1062e88c52c810d6afc..b40c138c4a575ae980be9dfddf3b752f2a12edcf 100644 (file)
@@ -81,20 +81,6 @@ sub clean_tex {
     my($eaten,$txt) = (shift,shift);
     my ($outstr, $type);
 
-    # Sub translate is given a string and one of the translation tables below.
-    # It returns the translation, or just the string if there's no translation
-    # Translation table for TT::Begin::Group tokens
-    my %begtranstbl = (
-                       '$' => '\(', # LyX math mode doesn't
-                       '$$' => '\[', # understand \$ or $$
-                       );
-
-    # Translation table for TT::End::Group tokens
-    my %endtranstbl = (
-                          '$' => '\)',
-                          '$$' => '\]',
-                      );
-
     # Translation table for TT::Token tokens whose translations should
     #    NOT have whitespace after them! See sub translate...
     #   Note that tokens of type TT::EndLocal are always translated to '}'. So,
@@ -135,8 +121,7 @@ sub clean_tex {
 
           # Handle the end of a local font command - insert a '}'
           if (/EndLocal/) {
-              # we could just say $printstr='}'
-              $printstr = &translate('}', \%endtranstbl);
+              $printstr = '}';
               last SWITCH;
           }
           
@@ -242,13 +227,13 @@ sub clean_tex {
           
           # Handle opening groups, like '{' and '$'.
           if (/Begin::Group$/) {
-              $printstr = &translate($outstr,\%begtranstbl);
+              $printstr = $outstr;
               last SWITCH;
           }
           
           # Handle closing groups, like '}' and '$'.
           if (/End::Group$/) {
-              $printstr = &translate($outstr, \%endtranstbl);
+              $printstr = $outstr;
               last SWITCH;
           }
 
index c03770f07bde124680fd83cfaaf09558ccd0ade9..757a7c211d7e0e1cd37063036ec1088ea0a52285 100644 (file)
@@ -12,6 +12,8 @@
 package Verbatim;
 use strict;
 
+my $debug_on; # package-wide variable set if -d option is given
+
 sub copy_verb {
 # This subroutine handles a \verb token. Text is guaranteed to be on one line.
 # \verb must be followed by a non-letter, then copy anything until the next
@@ -27,6 +29,9 @@ sub copy_verb {
 }
 
 sub copy_verbatim {
+    # Was -d option given?
+    $debug_on = (defined($main::opt_d) && $main::opt_d);
+
 # This subroutine eats text verbatim until a certain text is reached
 # The end text itself is not eaten; this is necessary so that
 #    environments are properly nested (otherwise, TeX.pm complains)
@@ -35,7 +40,10 @@ sub copy_verbatim {
 # Arg 0 is the Text::TeX::OpenFile file object, arg 1 is the beginning token
     my $fileobject = shift;
     my $begin_token = shift;
-    my %endtokentbl = (  '\(' => '\)' , '\[' => '\]'  );
+    my %endtokentbl = (  '\(' => '\)',
+                        '\[' => '\]',
+                        '$'  => '$',
+                        '$$' => '$$' );
 
     my $type = ref($begin_token);
     $type =~ s/^Text::TeX:://o or die "unknown token type $type?!";