It doesn't cure the $a=b$$b=c$ problem (which appears to be a fundamental limitation of TeX.pm) but it does appear to work otherwise.
André, I would be honoured if you'd try it out on some of your math-heavy stuff ;-) One slight pain: you have to apply it from $LYXTOP/lib/reLyX. -- Angus
Index: BasicLyX.pm =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/reLyX/BasicLyX.pm,v retrieving revision 1.5 diff -u -p -r1.5 BasicLyX.pm --- BasicLyX.pm 7 Jan 2003 14:30:52 -0000 1.5 +++ BasicLyX.pm 3 Feb 2003 17:25:43 -0000 @@ -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: CleanTeX.pm =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/reLyX/CleanTeX.pm,v retrieving revision 1.2 diff -u -p -r1.2 CleanTeX.pm --- CleanTeX.pm 29 Mar 2000 23:02:36 -0000 1.2 +++ CleanTeX.pm 3 Feb 2003 17:25:44 -0000 @@ -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: Verbatim.pm =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/reLyX/Verbatim.pm,v retrieving revision 1.1.1.1 diff -u -p -r1.1.1.1 Verbatim.pm --- Verbatim.pm 27 Sep 1999 18:44:34 -0000 1.1.1.1 +++ Verbatim.pm 3 Feb 2003 17:25:50 -0000 @@ -35,7 +35,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?!";