]> git.lyx.org Git - features.git/commitdiff
enable reLyX to recognise natbib citations
authorAngus Leeming <leeming@lyx.org>
Fri, 7 Feb 2003 22:11:06 +0000 (22:11 +0000)
committerAngus Leeming <leeming@lyx.org>
Fri, 7 Feb 2003 22:11:06 +0000 (22:11 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6071 a592a061-630c-0410-9148-cb99ea01b6c8

lib/ChangeLog
lib/reLyX/BasicLyX.pm
lib/reLyX/MakePreamble.pm
lib/reLyX/syntax.default

index 47bddf6d90a34884fccae1b75a34723d1c9277e4..324a34e5d2c7f8242a3f98812e16d6561d86e787 100644 (file)
@@ -3,6 +3,15 @@
        * kbd/polski.kmap: new keymap, which assumes that you have a
        non-Polish keyboard. 
 
+2003-02-07  Angus Leeming  <leeming@lyx.org>
+
+       * BasicLyX.pm: enable reLyX to recognise natbib citations.
+
+       * MakePreamble.pm: if '\usepackage{natbib}' is found, activate
+       LyX's natbib support.
+
+       * reLyX/syntax.default: add natbib citation commands.
+
 2003-02-07  Angus Leeming  <leeming@lyx.org>
 
        * lyx2lyx/lyx2lyx: enable the debug level to be set.
index 7ea9ecc46c9143b38b4e69d149ce6fc9d342fd51..d704c34db07ddf31df12b3a4e62b7cc7674015a6 100644 (file)
@@ -218,6 +218,32 @@ my $MathEnvironments = "(math|displaymath|xxalignat|(equation|eqnarray|align|ali
 # 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
@@ -417,7 +443,8 @@ sub basic_lyx {
                } # 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,
@@ -573,7 +600,7 @@ sub basic_lyx {
            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 ";
@@ -808,7 +835,8 @@ sub basic_lyx {
 
            # 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}) {
index 5568c78627fc429922807ad0cf9f42edd54aa43f..ef06a496d3e4e7b6eacc4cee34ef882d65809ab1 100644 (file)
@@ -294,11 +294,22 @@ sub translate_preamble {
     my $up;
     foreach $up (keys %Usepackage_Table) {
        $Latex_Preamble =~ s/\\usepackage\{$up\}\s*// && do {
-           $LyX_Preamble .= "$Usepackage_Table{$up}";
-           $LyX_Preamble .= "\n" unless ($Usepackage_Table{$up} eq "");
+           my $tmp = $Usepackage_Table{$up};
+           $LyX_Preamble .= join($tmp, "\n") unless ($tmp eq '');
+           #$LyX_Preamble .= "$Usepackage_Table{$up}";
+           #$LyX_Preamble .= "\n" unless ($Usepackage_Table{$up} eq "");
        }
     }
 
+    # Natbib is a little more complex than that.
+    if ($Latex_Preamble =~ s/\\usepackage(.*)\{natbib\}\s*//) {
+       print "matched it!\n";
+       $LyX_Preamble .= "\\use_natbib 1\n\\use_numerical_citations ";
+       $LyX_Preamble .= ($1 =~ /numbers/) ? "1\n" : "0\n";
+    } else {
+       $LyX_Preamble .= "\\use_natbib 0\n\\use_numerical_citations 0\n";
+    }
+
     ## Handle geometry options
     ## The custom paper missing from the options list since it involves two parameters
     my %Geometry_Options =(
index 0ff000ab48631d4a9e696c64c7de857e967c5a88..6f25d658914a22d22dc6abec56534f4c8444bf98 100644 (file)
@@ -69,6 +69,54 @@ $$
 \bibliographystyle{}
 \c{}
 \cite[]{}
+
+% Natbib citations can usually have two optional args, but LyX currently
+% supports only one.
+\citet[]{}
+\Citet[]{}
+\citet*[]{}
+\Citet*[]{}
+%\citet[][]{}
+%\Citet[][]{}
+%\citet*[][]{}
+%\Citet*[][]{}
+
+\citealt[][]{}
+\Citealt[][]{}
+\citealt*[][]{}
+\Citealt*[][]{}
+%\citealt[][{}
+%\Citealt[]{}
+%\citealt*[]{}
+%\Citealt*[]{}
+
+\citep[][]{}
+\Citep[][]{}
+\citep*[][]{}
+\Citep*[][]{}
+%\citep[]{}
+%\Citep[]{}
+%\citep*[]{}
+%\Citep*[]{}
+
+\citealp[]{}
+\Citealp[]{}
+\citealp*[]{}
+\Citealp*[]{}
+%\citealp[][]{}
+%\Citealp[][]{}
+%\citealp*[][]{}
+%\Citealp*[][]{}
+
+\citeauthor[]{}
+\Citeauthor[]{}
+\citeauthor*[]{}
+\Citeauthor*[]{}
+
+\citeyear[]{}
+\citeyearpar[]{}
+%\citeyearpar[][]{}
+
 \cline{ - }
 \d{}
 \documentclass[]{}[]