Fixes the mess in syntax.default.

-- 
Angus
? build-qt
? build-xforms
? relyx-accents.diff
? relyx-natbib-test.lyx
? relyx-natbib-test.tex
? relyx-natbib.diff
? relyx-starredmath-test.tex
? relyx-starredmath.diff
? relyx-table-test.tex
? relyx-table.diff
Index: status.13x
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/Attic/status.13x,v
retrieving revision 1.1.2.8
diff -u -p -r1.1.2.8 status.13x
--- status.13x	7 Feb 2003 16:49:19 -0000	1.1.2.8
+++ status.13x	10 Feb 2003 20:01:38 -0000
@@ -27,6 +27,8 @@ What's new
 
 - new "polski" keymap, useful for entering Polish on a QWERTY keyboard
 
+- enable reLyX to handle natbib citations
+
 ** Bug fixes
 
 - fix bug where opening the tabular dialog would mark the document as 
@@ -41,4 +43,4 @@ What's new
 
 - fix strerror() build problem with some gcc/glibc versions [bug #874]
 
-lyx2lyx: enable the debug level to be set.
+- enable the lyx2lyx debug level to be set
Index: lib/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/ChangeLog,v
retrieving revision 1.363.2.2
diff -u -p -r1.363.2.2 ChangeLog
--- lib/ChangeLog	7 Feb 2003 16:14:34 -0000	1.363.2.2
+++ lib/ChangeLog	10 Feb 2003 20:01:42 -0000
@@ -1,3 +1,12 @@
+2003-02-07  Angus Leeming  <[EMAIL PROTECTED]>
+  
+	* 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  Tomasz Luczak  <[EMAIL PROTECTED]>
 
 	* kbd/polski.kmap: new keymap, which assumes that you have a
Index: lib/reLyX/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
--- lib/reLyX/BasicLyX.pm	7 Jan 2003 14:30:52 -0000	1.5
+++ lib/reLyX/BasicLyX.pm	10 Feb 2003 20:01:48 -0000
@@ -218,6 +218,32 @@ my $MathEnvironments = "(math|displaymat
 # 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
@@ -381,7 +407,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,
@@ -537,7 +564,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 ";
@@ -772,7 +799,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: lib/reLyX/MakePreamble.pm
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/reLyX/MakePreamble.pm,v
retrieving revision 1.8
diff -u -p -r1.8 MakePreamble.pm
--- lib/reLyX/MakePreamble.pm	15 Jan 2003 14:31:34 -0000	1.8
+++ lib/reLyX/MakePreamble.pm	10 Feb 2003 20:01:49 -0000
@@ -299,6 +299,14 @@ sub translate_preamble {
 	}
     }
 
+    # Natbib is a little more complex than that.
+    if ($Latex_Preamble =~ s/\\usepackage(.*)\{natbib\}\s*//) {
+	$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: lib/reLyX/syntax.default
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/reLyX/syntax.default,v
retrieving revision 1.3
diff -u -p -r1.3 syntax.default
--- lib/reLyX/syntax.default	28 Oct 2002 09:52:39 -0000	1.3
+++ lib/reLyX/syntax.default	10 Feb 2003 20:01:50 -0000
@@ -69,6 +69,37 @@ $$
 \bibliographystyle{}
 \c{}
 \cite[]{}
+
+% Natbib citations can usually have two optional args, but LyX currently
+% supports only one.
+\citet[]{}
+\Citet[]{}
+\citet*[]{}
+\Citet*[]{}
+
+\citealt[][{}
+\Citealt[]{}
+\citealt*[]{}
+\Citealt*[]{}
+
+\citep[]{}
+\Citep[]{}
+\citep*[]{}
+\Citep*[]{}
+
+\citealp[]{}
+\Citealp[]{}
+\citealp*[]{}
+\Citealp*[]{}
+
+\citeauthor[]{}
+\Citeauthor[]{}
+\citeauthor*[]{}
+\Citeauthor*[]{}
+
+\citeyear[]{}
+\citeyearpar[]{}
+
 \cline{ - }
 \d{}
 \documentclass[]{}[]


Reply via email to