Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

BibTeX: how to force et al. for long author lists?

14,932 views
Skip to first unread message

kj

unread,
Apr 28, 2009, 10:22:53 AM4/28/09
to


Hi. I'm working on a manuscript for which I'm using natbib as my
bibliographystyle. For many of my citations the author lists are
very long, and I'd like them to show in the bibliography as first
author + "et al.". How can I achieve this?

TIA!

kynn

--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.

Joseph Wright

unread,
Apr 30, 2009, 3:23:50 PM4/30/09
to
kj wrote:
> Hi. I'm working on a manuscript for which I'm using natbib as my
> bibliographystyle. For many of my citations the author lists are
> very long, and I'd like them to show in the bibliography as first
> author + "et al.". How can I achieve this?

Has to be done in the BibTeX style. Which one do you use, and do you
want a flexible number for truncation (this can be done using a trick
from IEEEtrans)?
--
Joseph Wright

kj

unread,
May 2, 2009, 4:13:55 PM5/2/09
to
In <3VmKl.123$se...@newsfe30.ams2> Joseph Wright <joseph...@morningstar2.co.uk> writes:

>kj wrote:
>> Hi. I'm working on a manuscript for which I'm using natbib as my
>> bibliographystyle. For many of my citations the author lists are
>> very long, and I'd like them to show in the bibliography as first
>> author + "et al.". How can I achieve this?

>Has to be done in the BibTeX style. Which one do you use...

I'm a bit confused by your question. Do you mean something other
than natbib? (I.e. natbib.bst.)

>, and do you
>want a flexible number for truncation (this can be done using a trick
>from IEEEtrans)?

I want the truncation to happen for any author list that contains
more than, say, 5 authors. (I'll probably tweak this number,
depending on how the final layout turns out, but in any case it
will be a fixed limit.)

Joseph Wright

unread,
May 2, 2009, 4:18:21 PM5/2/09
to
kj wrote:
> In <3VmKl.123$se...@newsfe30.ams2> Joseph Wright <joseph...@morningstar2.co.uk> writes:
>
>> kj wrote:
>>> Hi. I'm working on a manuscript for which I'm using natbib as my
>>> bibliographystyle. For many of my citations the author lists are
>>> very long, and I'd like them to show in the bibliography as first
>>> author + "et al.". How can I achieve this?
>
>> Has to be done in the BibTeX style. Which one do you use...
>
> I'm a bit confused by your question. Do you mean something other
> than natbib? (I.e. natbib.bst.)

natbib is not a bst file. You should have a line reading:

\bibliographystyle{<something>}

What is the <something>?


--
Joseph Wright

Robin Fairbairns

unread,
May 2, 2009, 5:21:45 PM5/2/09
to
In article <9U1Ll.2622$_e5....@newsfe21.ams2>,

Joseph Wright <joseph...@morningstar2.co.uk> writes:
>kj wrote:
>> In <3VmKl.123$se...@newsfe30.ams2> Joseph Wright <joseph...@morningstar2.co.uk> writes:
>>
>>> kj wrote:
>>>> Hi. I'm working on a manuscript for which I'm using natbib as my
>>>> bibliographystyle. For many of my citations the author lists are
>>>> very long, and I'd like them to show in the bibliography as first
>>>> author + "et al.". How can I achieve this?
>>
>>> Has to be done in the BibTeX style. Which one do you use...
>>
>> I'm a bit confused by your question. Do you mean something other
>> than natbib? (I.e. natbib.bst.)
>
>natbib is not a bst file. You should have a line reading:

it used to be. in the current (v8.3) natbib readme file, we find,
under "changes for v6.0":

Note: the bib style file provided in previous releases (natbib.bst)
is no longer provided, since it only meant to be an example. It is now
replaced by plainnat.bst and others.

so natbib.bst has been defunct for some time now, but some people keep
these things around...
--
Robin Fairbairns, Cambridge

Joseph Wright

unread,
May 2, 2009, 5:35:41 PM5/2/09
to
Robin Fairbairns wrote:

> it used to be. in the current (v8.3) natbib readme file, we find,
> under "changes for v6.0":
>
> Note: the bib style file provided in previous releases (natbib.bst)
> is no longer provided, since it only meant to be an example. It is now
> replaced by plainnat.bst and others.
>
> so natbib.bst has been defunct for some time now, but some people keep
> these things around...

Okay, this I've never seen (I've always used <name>nat.bst). You still
need a \bibliographystyle command, though.
--
Joseph Wright

Joris

unread,
May 2, 2009, 8:01:03 PM5/2/09
to
On May 2, 5:35 pm, Joseph Wright <joseph.wri...@morningstar2.co.uk>
wrote:

I'd be interested in the answer to the original post for
econometrica.bst

Joseph Wright

unread,
May 3, 2009, 3:22:53 AM5/3/09
to
Joris wrote:
> I'd be interested in the answer to the original post for
> econometrica.bst

Okay, the reason for asking for the bst name is so that I can can a
simple "copy paste" answer. So I'll give two, one for plainnat.bst and
one for econometrica.bst.

In either case, start by making a copy of the original with a new name
(let's say plainnat-abbr.bst or econometrica-abbr.bst). This will need
to go in your working directory. In the plainnat.bst case, there is
only one function to alter: format.names. Find that function and replac
it with:

FUNCTION {format.names}
{ 's :=
#1 'nameptr :=
s num.names$ 'numnames :=
numnames 'namesleft :=
numnames 5 >
{ s #1 "{ff~}{vv~}{ll}{, jj}" format.name$
" et~al." * }
{
{ namesleft #0 > }
{ s nameptr "{ff~}{vv~}{ll}{, jj}" format.name$ 't :=
nameptr #1 >
{ namesleft #1 >
{ ", " * t * }
{ numnames #2 >
{ "," * }
'skip$
if$
t "others" =
{ " et~al." * }
{ " and " * t * }
if$
}
if$
}
't
if$
nameptr #1 + 'nameptr :=
namesleft #1 - 'namesleft :=
}
while$
}
if$
}

In the case of econometrica-abbr.bst, there are two formatting
functions, one for authors and one for editors. The change is the same
in both cases, but to save you working it out:

FUNCTION {format.names}
{ 's :=
#1 'nameptr :=
s num.names$ 'numnames :=
numnames 'namesleft :=
numnames 5 >
{ s #1 "{vv~}{ll}{, jj}{, f.}" format.name$
" et~al." * }
{
{ namesleft #0 > }
{ nameptr #1 >
{ s nameptr "{f.~}{vv~}{ll}{, jj}" format.name$ 't := }
{ s nameptr "{vv~}{ll}{, jj}{, f.}" format.name$ 't := }
if$
nameptr #1 >
{
namesleft #1 >
{ ", " * t * }
{
", " *
t "others" =
{ " et~al." * }
{ " {\small and} " * t * } %%%KCB: added \small
if$
}
if$
}
't
if$
nameptr #1 + 'nameptr :=
namesleft #1 - 'namesleft :=
}
while$
}
if$
}


FUNCTION {format.names.ed}
{ 's :=
#1 'nameptr :=
s num.names$ 'numnames :=
numnames 'namesleft :=
numnames 5 >
{ s #1 "{f.~}{vv~}{ll}{, jj}" format.name$
" et~al." * }
{
{ namesleft #0 > }
{ s nameptr
"{f.~}{vv~}{ll}{, jj}"
format.name$ 't :=
nameptr #1 >
{
namesleft #1 >
{ ", " * t * }
{
", " *
t "others" =
{ " et~al." * }
{ " {\small and} " * t * } %%%KCB: added \small
if$
}
if$
}
't
if$
nameptr #1 + 'nameptr :=
namesleft #1 - 'namesleft :=
}
while$
}
if$
}

In each case, the line "numnames 5 >" sets the maximum number of names
before the "First Name et al." methods takes over. You can do more
sophisticated things (such as have this variable without needing to edit
the file), but unless you want to make a version for public use this is
probably not worth it.
--
Joseph Wright

Joris

unread,
May 3, 2009, 7:52:42 AM5/3/09
to
On May 3, 3:22 am, Joseph Wright <joseph.wri...@morningstar2.co.uk>
wrote:

WOW, thanks!

kj

unread,
May 4, 2009, 9:47:33 AM5/4/09
to
In <aDbLl.8026$Oi7....@newsfe23.ams2> Joseph Wright <joseph...@morningstar2.co.uk> writes:

>Joris wrote:
> > I'd be interested in the answer to the original post for
>> econometrica.bst

>Okay, the reason for asking for the bst name is so that I can can a
>simple "copy paste" answer. So I'll give two, one for plainnat.bst and
>one for econometrica.bst.

>In either case, start by making a copy of the original with a new name
>(let's say plainnat-abbr.bst or econometrica-abbr.bst). This will need
>to go in your working directory. In the plainnat.bst case, there is
>only one function to alter: format.names. Find that function and replac
>it with:


Many thanks! I tried what you suggested, but it did not work; the
bibliography still shows long lists of authors rather than "et
al.".

Here are possible reasons why.

The documentclass I must use is bioinfo, and the file bioinfo.cls,
which is supplied by the publisher, contains the directive

\RequirePackage{natbib}

The file natbib.sty gets fetched from

/usr/share/texmf-tetex/tex/latex/natbib/natbib.sty

When I run bibtex, I get many error messages of the form:

"" is a string literal, not an integer, for entry jones07
while executing---line 1314 of file natbib-ea.bst

natbib-ea.bst is the file I created according to your instructions;
the line mentioned in the error message is shown below:

1310 EXECUTE {begin.bib}
1311
1312 EXECUTE {init.state.consts}
1313
* 1314 ITERATE {call.type$}
1315
1316 FUNCTION {end.bib}
1317 { newline$
1318 "\end{thebibliography}" write$ newline$
1319 }

BTW, I'm pretty comfortable with programming (in fact, I do it for
a living!), but I find the code in these *.bst files utterly
mystifying. What a crazy-looking language! It looks like nothing
I've ever programmed in. Is there a good book to learn to program
in this language, whatever it is?

kj

unread,
May 4, 2009, 9:53:15 AM5/4/09
to

>\RequirePackage{natbib}

>/usr/share/texmf-tetex/tex/latex/natbib/natbib.sty

Actually, that's not accurate. I followed your instructions, except
that I used the file natbit.bst as the starting point, rather than
plainnat.bst. That's probably the cause of the problem. I think
that this is the file I should start out with, but probably I need
to modify your format.names function so that it can work in that
context. Unfortunately, I can't follow the code in natbib.bst, so
I don't know exactly how to proceed. Hence my question about where
to learn about the language used in these files.

kj

unread,
May 4, 2009, 10:13:53 AM5/4/09
to
In <aDbLl.8026$Oi7....@newsfe23.ams2> Joseph Wright <joseph...@morningstar2.co.uk> writes:

>Joris wrote:
> > I'd be interested in the answer to the original post for
>> econometrica.bst

>Okay, the reason for asking for the bst name is so that I can can a
>simple "copy paste" answer. So I'll give two, one for plainnat.bst and
>one for econometrica.bst.

>In either case, start by making a copy of the original with a new name
>(let's say plainnat-abbr.bst or econometrica-abbr.bst). This will need
>to go in your working directory. In the plainnat.bst case, there is
>only one function to alter: format.names. Find that function and replac
>it with:

>FUNCTION {format.names}
>{ 's :=
> #1 'nameptr :=
> s num.names$ 'numnames :=
> numnames 'namesleft :=
> numnames 5 >

I figured it out! When I changed the last line above to

numnames #5 >

it worked beautifully. I'm so proud of myself :-)

Many thanks!!!

Joseph Wright

unread,
May 4, 2009, 10:15:37 AM5/4/09
to
On May 4, 3:13 pm, kj <so...@987jk.com.invalid> wrote:

Opps, sorry about that. My source uses variables rather than literals
here, and I forgot to alter them.
--
Joseph Wright

Joseph Wright

unread,
May 4, 2009, 1:11:30 PM5/4/09
to
On May 4, 2:53 pm, kj <so...@987jk.com.invalid> wrote:

> Actually, that's not accurate.  I followed your instructions, except
> that I used the file natbit.bst as the starting point, rather than
> plainnat.bst.  That's probably the cause of the problem.  I think
> that this is the file I should start out with, but probably I need
> to modify your format.names function so that it can work in that
> context.  Unfortunately, I can't follow the code in natbib.bst, so
> I don't know exactly how to proceed.  Hence my question about where
> to learn about the language used in these files.

To learn the language you've got three things to go on, really:

- The BibTeX Manual
- "Tame the BeaST" (available on CTAN)
- The "merlin" file from custom-bib (shows what can be done)

Of these, Tame the BeaST is really the only one aimed at users. Key
things to remember:

- There are very few primitive functions, all of which end with $,
such as num.names$

- To use a variable, just use its name, but to assign to it you have
to precede the name by '.

- BibTeX uses a stack language, where things are added then taken off.
This means that to compare two values, they both have to be added to
the stack _before_ the comparison. The comparison takes them off the
stack and leaves a number, which is then used by a logical function.
But everything for the logical function has to come before it (because
of the stack nature of the language). For example:

#1 my.variable < % tests is my.variable is greater than one
{ } % Command(s) if true
{ } % Command(s) if false
if$ % The if$ here applies to things before it, not after!

- Braces are used as in LaTeX to delimit things, with % the comment
character

- A single command can be used in place of a group only if it is
"quoted" by preceding it with '. Following the above example:

#1 my.variable < %
'skip$ % skip$ is the "do nothing" operation, here used as the
% entire TRUE branch
{ } % Command(s) if false
if$ %

- Literal numbers have to be preceded by #, as in my example.

- To see what is on the stack at any point, a simple recipe is :
duplicate$ top$

This will duplicate the last thing added to the stack, then write
the top thing "the duplicate" to the log. The original item stays on
the stack. To see the last two, you also need swap$:

duplicate$ top$ swap$ duplicate$ top$ swap$

- Using an item from the stack in any way removes it. This includes
comparisons and writing to the log. Hence the need for duplicate$ a
lot!

- New function or variable names can be anything, but have to be
declared before the first use. This is why the files almost always
start with things like add.comma, then things like format.names, then
the functions for database types (article, ... ) and finally the
actual "do stuff" parts (iterate$ and so on).

You could also look at the biblatex.bst file, which is designed to
work very differently from anything else for BibTeX but which is one
of the few not just based on the original BibTeX styles plus
modification.

Hope this provides at least a little help.
--
Joseph Wright

kj

unread,
May 4, 2009, 2:15:03 PM5/4/09
to
In <3a657e7b-6c68-4ee3...@v17g2000vbb.googlegroups.com> Joseph Wright <joseph...@morningstar2.co.uk> writes:

<snip>

>Hope this provides at least a little help.

Yes, incredibly helpful. Thanks!

santia...@gmail.com

unread,
Apr 3, 2013, 7:09:53 PM4/3/13
to
Thanks a lot, with both tips it also worked perfectly fine for me!

It would be nice to pass this number as a variable from inside Lyx, that would make things easier for many people.
0 new messages