);
# Math environments are copied verbatim
-my $MathEnvironments = "(math|equation|displaymath|eqnarray(\\*)?)";
+my $MathEnvironments = "(math|displaymath|xxalignat|(equation|eqnarray|align|alignat|xalignat|multline|gather)(\\*)?)";
# ListLayouts may have standard paragraphs nested inside them.
my $ListLayouts = "Itemize|Enumerate|Description";
+# passed a string and an array
+# returns true if the string is an element of the array.
+sub foundIn {
+ my $name = shift;
+ return grep {$_ eq $name} @_;
+}
+
+my @NatbibCommands = map {"\\$_"} qw(citet citealt citep citealp citeauthor);
+
+# passed a string.
+# returns true if it is a valid natbib citation
+sub isNatbibCitation {
+ my $name = shift;
+
+ # These two have a single form
+ return 1 if ($name eq '\citeyear' or $name eq '\citeyearpar');
+
+ # Natbib citations can start with a 'C' or a 'c'
+ $name =~ s/^\\C/\\c/;
+ # The can end with a '*'
+ $name =~ s/\*$//;
+ # Is this doctored string found in the list of valid commands?
+ return foundIn($name, @NatbibCommands);
+
+}
+
##################### PARSER INVOCATION ##################################
sub call_parser {
# This subroutine calls the TeX parser & translator
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
} # end special handling for \@
# Handle tokens that LyX translates as a "LatexCommand" inset
- } elsif (grep {$_ eq $name} @LatexCommands) {
+ } elsif (foundIn($name, @LatexCommands) ||
+ isNatbibCitation($name)){
&CheckForNewParagraph; #Start new paragraph if necessary
print OUTFILE "$pre_space\n\\begin_inset LatexCommand ",
$name,
"\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);
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;
$thistable->nextcol;
} else {warn "& is illegal outside a table!"}
- } elsif ($name eq '\\\\' || $name eq '\\newline') {
+ } elsif ($name eq '\\\\' || $name eq '\\newline' || $name eq "\\tabularnewline") {
&CheckForNewParagraph; # could be at beginning of par?
print OUTFILE "\n\\newline \n";
print "$name" if $debug_on;
# Handle things that LyX translates as a "LatexCommand" inset
- if (grep {$_ eq $name} @LatexCommands) {
+ if (foundIn($name, @LatexCommands) || isNatbibCitation($name)){
&CheckForNewParagraph; #Start new paragraph if necessary
print OUTFILE "$pre_space\n\\begin_inset LatexCommand ";
# Handle things that LyX translates as a "LatexCommand" inset
# or "Include" insets
- if (grep {$_ eq $name} @LatexCommands, @IncludeCommands) {
+ if (foundIn($name, @LatexCommands, @IncludeCommands) ||
+ isNatbibCitation($name)){
print OUTFILE "\}\n\n\\end_inset \n\n";
} elsif (exists $ReadCommands::ToLayout->{$name}) {