Jean-Marc, I've applied this to 1.4.x already. Here's a patch for 1.3.x
together with a test .tex file for you to try it out with. The reLyX
support for this package is now exactly the same as LyX's.
Rgds,
--
Angus
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 7 Feb 2003 22:26:09 -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 7 Feb 2003 22:26:13 -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 7 Feb 2003 22:26:17 -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 7 Feb 2003 22:26:17 -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 7 Feb 2003 22:26:18 -0000
@@ -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[]{}[]
\documentclass{article}
\usepackage{natbib}
%\usepackage[numbers]{natbib}
\begin{document}
citet:
\begin{itemize}
\item \citet[optional]{leeming}
\item \Citet[optional]{leeming}
\item \citet*[optional]{leeming}
\item \Citet*[optional]{leeming}
\end{itemize}
citep
\begin{itemize}
\item \citep[optional]{leeming}
\item \Citep[optional]{leeming}
\item \citep*[optional]{leeming}
\item \Citep*[optional]{leeming}
\end{itemize}
citealt
\begin{itemize}
\item \citealt[optional]{leeming}
\item \Citealt[optional]{leeming}
\item \citealt*[optional]{leeming}
\item \Citealt*[optional]{leeming}
\end{itemize}
citealp
\begin{itemize}
\item \citealp[optional]{leeming}
\item \Citealp[optional]{leeming}
\item \citealp*[optional]{leeming}
\item \Citealp*[optional]{leeming}
\end{itemize}
citeauthor
\begin{itemize}
\item \citeauthor[optional]{leeming}
\item \Citeauthor[optional]{leeming}
\item \citeauthor*[optional]{leeming}
\item \Citeauthor*[optional]{leeming}
\end{itemize}
citeyear*
\begin{itemize}
\item \citeyear[optional]{leeming}
\item \citeyearpar[optional]{leeming}
\end{itemize}
\begin{thebibliography}{foo}
\bibitem[Leeming (2003)]{leeming}Leeming, A.D., ``modifying reLyX'', 2003.
\end{thebibliography}
\end{document}