Re: [patch 13x]: reLyX natbib citations try 2

2003-02-11 Thread Jean-Marc Lasgouttes
 Angus == Angus Leeming [EMAIL PROTECTED] writes:

Angus Fixes the mess in syntax.default. -- Angus

This one does not look right:
+\citealt[][{}

Once this is fixed, you can apply it to 1.3.x.

JMarc




Re: [patch 13x]: reLyX natbib citations try 2

2003-02-11 Thread Angus Leeming
Jean-Marc Lasgouttes wrote:

 Angus == Angus Leeming [EMAIL PROTECTED] writes:
 
 Angus Fixes the mess in syntax.default. -- Angus
 
 This one does not look right:
 +\citealt[][{}
 
 Once this is fixed, you can apply it to 1.3.x.
 
 JMarc

What would I do without you? ;-)

-- 
Angus




Re: [patch 13x]: reLyX natbib citations try 2

2003-02-11 Thread Jean-Marc Lasgouttes
 Angus == Angus Leeming [EMAIL PROTECTED] writes:

Angus What would I do without you? ;-)

Apply patches faster :)

JMarc



Re: [patch 13x]: reLyX && natbib citations try 2

2003-02-11 Thread Jean-Marc Lasgouttes
> "Angus" == Angus Leeming <[EMAIL PROTECTED]> writes:

Angus> Fixes the mess in syntax.default. -- Angus

This one does not look right:
+\citealt[][{}

Once this is fixed, you can apply it to 1.3.x.

JMarc




Re: [patch 13x]: reLyX && natbib citations try 2

2003-02-11 Thread Angus Leeming
Jean-Marc Lasgouttes wrote:

>> "Angus" == Angus Leeming <[EMAIL PROTECTED]> writes:
> 
> Angus> Fixes the mess in syntax.default. -- Angus
> 
> This one does not look right:
> +\citealt[][{}
> 
> Once this is fixed, you can apply it to 1.3.x.
> 
> JMarc

What would I do without you? ;-)

-- 
Angus




Re: [patch 13x]: reLyX && natbib citations try 2

2003-02-11 Thread Jean-Marc Lasgouttes
> "Angus" == Angus Leeming <[EMAIL PROTECTED]> writes:

Angus> What would I do without you? ;-)

Apply patches faster :)

JMarc



[patch 13x]: reLyX natbib citations try 2

2003-02-10 Thread Angus Leeming
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 -	1.1.2.8
+++ status.13x	10 Feb 2003 20:01:38 -
@@ -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 -	1.363.2.2
+++ lib/ChangeLog	10 Feb 2003 20:01:42 -
@@ -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 -	1.5
+++ lib/reLyX/BasicLyX.pm	10 Feb 2003 20:01:48 -
@@ -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 -	1.8
+++ lib/reLyX/MakePreamble.pm	10 Feb 2003 20:01:49 -
@@ -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;
+}
+
 ## 

[patch 13x]: reLyX && natbib citations try 2

2003-02-10 Thread Angus Leeming
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 -	1.1.2.8
+++ status.13x	10 Feb 2003 20:01:38 -
@@ -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 -	1.363.2.2
+++ lib/ChangeLog	10 Feb 2003 20:01:42 -
@@ -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 -	1.5
+++ lib/reLyX/BasicLyX.pm	10 Feb 2003 20:01:48 -
@@ -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)){
 		 #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)){
 		 #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 -	1.8
+++ lib/reLyX/MakePreamble.pm	10 Feb 2003 20:01:49 -
@@ -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