labels in bibliography with natbib's authoryear mode

by Stefan Rank » Tue, 15 Jul 2008 16:11:38 GMT



Hi,

natbib in numbers mode puts [1] in front of the entries in the
bibliography. In authoryear mode there is no label.

I'd like to have authoryear citations, but with a label in front of the
bibitems (the one that I would get with \citep{} in the text).

I can get *some* label by redefining NAT@biblabel::

\makeatletter \renewcommand\NAT@biblabel[1]{[#1]} \makeatother

However, the argument #1 is only the sequence number of the bibitem AFAIK.

Did anybody do something like that already?
Or does anybody have an idea how to get from that argument to the
authoryear-type label?

cheers,
stefan



Re: labels in bibliography with natbib's authoryear mode

by vojta » Tue, 15 Jul 2008 18:46:54 GMT



In article < XXXX@XXXXX.COM >,



Try \bibliographystyle{abbrvnat}

See, for example, page 27 of:

http://amath.colorado.edu/documentation/LaTeX/reference/faq/bibstyles.pdf

--Paul Vojta, XXXX@XXXXX.COM



Re: labels in bibliography with natbib's authoryear mode

by Stefan Rank » Tue, 15 Jul 2008 19:42:37 GMT



on 15.07.2008 12:46 Paul Vojta said the following:


Thanks for the tip. But that does not achieve what I aim for.
abbrvnat still has no label at the beginning of the bibitem if used with
the authoryear option for natbib.

BTW, the bibstyles.pdf messes up the labels for nearly all the
authoryear styles, see:

http://keizai.xrea.jp/latex/bib/sample/sample-abbrvnat.pdf

for what abbrvnat looks like.

cheers,
stefan



Re: labels in bibliography with natbib's authoryear mode

by Ulrike Fischer » Tue, 15 Jul 2008 23:16:51 GMT



Am Tue, 15 Jul 2008 10:11:38 +0200 schrieb Stefan Rank:


No. But perhaps this does what you want:

\makeatletter
\def\@lbibitem[#1]#2{%
\if\relax\@extra@b@citeb\relax\else
\@ifundefined{br@#2\@extra@b@citeb}{}{%
\@namedef{br@#2}{\@nameuse{br@#2\@extra@b@citeb}}}\fi
\@ifundefined{b@#2\@extra@b@citeb}{\def\NAT@num{}}{\NAT@parse{#2}}%
\item[\hfil\hyper@natanchorstart{#2\@extra@b@citeb}{[#1]}%
\hyper@natanchorend]%
\NAT@ifcmd#1(@)(@)\@nil{#2}}
\makeatother

As you didn't provide a minimal example (which would e.g. have showed
what options and bibstyle you are using) this is completly untested.



--
Ulrike Fischer



Re: labels in bibliography with natbib's authoryear mode

by Stefan Rank » Wed, 16 Jul 2008 03:49:56 GMT



Hi,

on 15.07.2008 17:16 Ulrike Fischer said the following:
<snip>
<snip>

yet it works. Thanks for that, it's nearly what I want.
Below is a minimal example. The [#1] results in the full natbib
authoryear info:
[Walrus et al.(2004)Walrus, Humpty, Queen, and Cat].
I'd like to reduce that to the output that \citep produces:
[Walrus et al. 2004].
I tried to find the relevant code in natbib.sty but I am lost in the
definition of \NAT@citex

I would be grateful for any suggestions.

cheers,
stefan

----------8<---------8<------------

\documentclass{article}

\usepackage[sort]{natbib}
\setcitestyle{authoryear,square,semicolon,aysep={},yysep={,}}

\makeatletter
\def\@lbibitem[#1]#2{%
\if\relax\@extra@b@citeb\relax\else
\@ifundefined{br@#2\@extra@b@citeb}{}{%
\@namedef{br@#2}{\@nameuse{br@#2\@extra@b@citeb}}}\fi
\@ifundefined{b@#2\@extra@b@citeb}{\def\NAT@num{}}{\NAT@parse{#2}}%
\item[\hfil\hyper@natanchorstart{#2\@extra@b@citeb}{[#1]}%
\hyper@natanchorend]%
\NAT@ifcmd#1(@)(@)\@nil{#2}}
\makeatother

\begin{document}

test citation: \citep{WalrusETAL2004}

\begin{thebibliography}{28}

\bibitem[Walrus et~al.(2004)Walrus, Humpty, Queen, and Cat]{WalrusETAL2004}
The Walrus, Dumpty Humpty, Red Queen, and Cheshire Cat.
\newblock What is in a classic, 2004.

\end{thebibliography}


\end{document}




Re: labels in bibliography with natbib's authoryear mode

by Ulrike Fischer » Wed, 16 Jul 2008 16:04:14 GMT



Am Tue, 15 Jul 2008 21:49:56 +0200 schrieb Stefan Rank:



natbib obviously splits the string with \NAT@parse and \NAT@split. But
it is difficult to find out what argument they exactly expect. You can
try to write your own splitting command:

\makeatletter

\def\mysplit#1)#2\@nil{%
\def\@mysecondoftwo{#2}%
\ifthenelse{\equal{@@arg}{#1}}
{% no year, take everything
\def\@mycitep{#1}}
{% take the part until and including year
\def\mycitep{#1)}}}

\def\@lbibitem[#1]#2{%
\mysplit#1)@@arg\@nil
\if\relax\@extra@b@citeb\relax\else
\@ifundefined{br@#2\@extra@b@citeb}{}{%
\@namedef{br@#2}{\@nameuse{br@#2\@extra@b@citeb}}}\fi
\@ifundefined{b@#2\@extra@b@citeb}{\def\NAT@num{}}{\NAT@parse{#2}}%
\item[\hfil\hyper@natanchorstart{#2\@extra@b@citeb}{[{\mycitep}]}%
\hyper@natanchorend]%
\NAT@ifcmd#1(@)(@)\@nil{#2}}
\makeatother


--
Ulrike Fischer



Re: labels in bibliography with natbib's authoryear mode

by Stefan Rank » Wed, 16 Jul 2008 17:44:35 GMT



on 16.07.2008 10:04 Ulrike Fischer said the following:
<snip>
<snip>

Thanks again, I experimented a bit, and went with a simple version of
using \citep{#2} iself in the bibitem, see below.
This has the unfortunate side-effect that, if you use hyperref, the
label is a link to itself (not too bad) and there is an additional not
very helpful back reference if you use pagebackref=true (rather bad).

stefan

----------

\documentclass{article}
\usepackage[pagebackref=true]{hyperref}
\usepackage[sort]{natbib}
\setcitestyle{authoryear,square,semicolon,aysep={},yysep={,}}

% the following redefines natbib internals to add a \citep like label
% for authoryear citations in the bibliography, as a side-effect the
% labels are links to themselves if hyperref is used.
\makeatletter
\def\@lbibitem[#1]#2{%
\if\relax\@extra@b@citeb\relax\else
\@ifundefined{br@#2\@extra@b@citeb}{}{%
\@namedef{br@#2}{\@nameuse{br@#2\@extra@b@citeb}}}\fi
\@ifundefined{b@#2\@extra@b@citeb}{\def\NAT@num{}}{\NAT@parse{#2}}%
\item[\hfil\hyper@natanchorstart{#2\@extra@b@citeb}\citep{#2}%
\hyper@natanchorend]%
\NAT@ifcmd#1(@)(@)\@nil{#2}}
\makeatother

\begin{document}

test citation: \citep{WalrusETAL2004}

\clearpage % for demonstrating the problem with pagebackref

\begin{thebibliography}{28}

\bibitem[Walrus et~al.(2004)Walrus, Humpty, Queen, and Cat]{WalrusETAL2004}
The Walrus, Dumpty Humpty, Red Queen, and Cheshire Cat.
\newblock What is in a classic, 2004.

\end{thebibliography}

\end{document}



Similar Threads

1. comp.text.tex >> natbib and label format in bibliography
Hi, I recently switched from named to natbib (better compatibility with hyperref) and still have one issue which I couldn't solve with the help of manuals or newsgroup-search. I use: \usepackage[authoryear]{natbib} ... \bibliographystyle{plainnat} \bibliography{thesis} and my citations look like: "... closed-world assumption [Reiter, 1978] is acknowledged as ..." So far so good. Now in the bibliography, instead of Raymond Reiter. On Closed World Data Bases. In Herve Gallaire and Jack Minker, editors, Logic and Data Bases, pages 119--140. Plenum Press, New York, 1978.

2. comp.text.tex >> natbib in authoryear, problems "compressing" refs with same first author and year
I am using natbib, and would like references in authoryear style. If I have a few references in my .bib file, eg: {Able2008 Author = {Able, A. and Brown, A. and Clark, A. and Dixon, A. and Engl, A.}, ... Year = (2008} } {Able2009_1 Author = {Able, A. and Brown, A. and Clark, A. and Dixon, A. and Engl, A.}, ... Year = (2009} } {Able2009_2 Author = {Able, A. and Brown, A. and Clark, A. and Engl, A. and Dixon, A. }, ... Year = (2009} } and type in my TeX doc: ... some text \citep{Able2008, Able2009_1, Able2009_2} some more text .....

3. comp.text.tex >> BibTex query: sorting of references in authoryear style with "natbib" package
Hi, I'm using BibTex to generate a bibliography. Let's call the bibliography mybib. I use the "natbib" package and want the references displayed in "authoryear" style. When I run Latex and BibTex and then Latex again (twice) on my .tex source file (let's call it Main.tex), I get this problem: All the books get listed first by year of publication, All the articles and miscellaneous other entries get listed afterwards (by year). To clarify: the sorting order for the books seems to be the year of publication (not author's name).

4. comp.text.tex >> Biblatex [Was: Merge authoryear-ibid and authoryear-comp]
Sorry, the subject was incomplete. jpg Jean-Philippe Georget < XXXX@XXXXX.COM > wrote:

5. comp.text.tex >> Merge authoryear-ibid and authoryear-comp
Hi! Is there a (simple?) way to merge the functionalities of the authoryear-ibid and authoryear-comp citation styles? For example, with The first citation is \parencite{name1_2004,name1_2005) and the second citation is \parencite{name1_2004). I want to obtain something like : The first citation is (Name1,2004,2005) and the second citation is (ibid., 2004). Thanx in advance for your help! jpg jpg -- XXXX@XXXXX.COM ^^^^year

6. [hyperref, pdftex, natbib] www link in the bibliography

7. HELP! Natbib bibliography with date after author

8. HELP! Natbib bibliography with date after author

9. natbib -- how to add unreferenced paper to bibliography?

10. Hacking natbib to have page reference in the bibliography entries


Post a new topic