From: Angus Leeming Date: Fri, 7 Feb 2003 22:11:06 +0000 (+0000) Subject: enable reLyX to recognise natbib citations X-Git-Tag: 1.6.10~17586 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=a17cf1b3f423e679fd61a52840857a2dca65d50b;p=features.git enable reLyX to recognise natbib citations git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6071 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/lib/ChangeLog b/lib/ChangeLog index 47bddf6d90..324a34e5d2 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -3,6 +3,15 @@ * kbd/polski.kmap: new keymap, which assumes that you have a non-Polish keyboard. +2003-02-07 Angus Leeming + + * 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 * lyx2lyx/lyx2lyx: enable the debug level to be set. diff --git a/lib/reLyX/BasicLyX.pm b/lib/reLyX/BasicLyX.pm index 7ea9ecc46c..d704c34db0 100644 --- a/lib/reLyX/BasicLyX.pm +++ b/lib/reLyX/BasicLyX.pm @@ -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}) { diff --git a/lib/reLyX/MakePreamble.pm b/lib/reLyX/MakePreamble.pm index 5568c78627..ef06a496d3 100644 --- a/lib/reLyX/MakePreamble.pm +++ b/lib/reLyX/MakePreamble.pm @@ -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 =( diff --git a/lib/reLyX/syntax.default b/lib/reLyX/syntax.default index 0ff000ab48..6f25d65891 100644 --- a/lib/reLyX/syntax.default +++ b/lib/reLyX/syntax.default @@ -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[]{}[]