'\LaTeXe' => "LaTeX2e",
'\TeX' => "TeX",
'\LyX' => "LyX",
+ '\lyxarrow' => "\\SpecialChar \\menuseparator\n",
'\hfill' => "\n\\hfill \n",
'\noindent' => "\n\\noindent \n",
'\textbackslash' => "\n\\backslash \n",
'\textgreater' => ">",
'\textless' => "<",
'\textbar' => "|",
+ '\textasciitilde' => "~",
);
# LyX translations of some plain LaTeX text (TeX parser won't recognize it
);
# 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 ";
# This is to handle cases where _ is used, say, in a filename.
# When _ is used in math mode, it'll be copied by the math mode
# copying subs. Here we handle cases where it's used in non-math.
- # Examples are filenames for & citation labels.
+ # Examples are filenames for \include & citation labels.
# (It's illegal to use it in regular LaTeX text.)
if ($name eq "_") {
print OUTFILE $eaten->exact_print;
# 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}) {
# Environments lyx translates to floats
} elsif (exists $FloatEnvTransTable{$env}) {
+ # this really only matters if it's at the very
+ # beginning of the doc.
+ &CheckForNewParagraph;
+
$tok = $fileobject->eatOptionalArgument;
if ($tok && defined ($dummy = $tok->print) && $dummy) {
print "\nIgnoring float placement '$dummy'" if $debug_on;
}
my $command = $FloatEnvTransTable{$env};
- # Open the footnote
+ # Open the table/figure
print OUTFILE "$command";
# table