[Tex/LaTex] Fix a .bst file to display “Author et al. (year)” if a .bib entry contains more than 2 authors

bibtex

This question is very related to the question here:

Citation "et al." only for four and more authors with natbib and jf.bst

In the answer to that question Mico has shown how to replace the format.lab.names function in the jf.str so that a .bib entry is displayed as "Author et al. (year)" whenever more than 4 authors are present in the entry. However, this is done for the jf.str version found at nyu.edu's website. I want to be able to do achieve the same behavior with the .str file found here

http://pages.stern.nyu.edu/~dbackus/GE_asset_pricing/BGTZ/jf.bst

which although it has the same name has some modifications to fit Econometrica's bibliography requirements.

So the question is can anyone explain to me why when I replace the FUNCTION {format.lab.names} with

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

I don't get "Author et al. (year)" whenever a .bib entry has more than 2 authors. (I realize this might be something very simple and started reading Tame the Beast at http://www.lsv.ens-cachan.fr/~markey/BibTeX/doc/ttb_en.pdf). Thank you.

Here's a .tex file for testing purposes:

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@article{abd:2007,
  author      = "Torben G. Andersen and Tim Bollerslev and Francis X. Diebold",
  title       = "Roughing it up: {Including} jump components in the
                measurement, modeling and forecasting of return volatility",
  journal     = "Review of Economics and Statistics",
  year        = 2007,
  volume      = 89,
  number      = 4,
  month       = "November",
  pages       = "701--720",
}

@article{abde:2001,
  author      = "Torben G. Andersen and Tim Bollerslev and Francis X. Diebold
                and Heiko Ebens",
  title       = "The distribution of realized stock return volatility",
  journal     = "Journal of Financial Economics",
  year        = 2001,
  volume      = 61,
  number      = 1,
  month       = "July",
  pages       = "43--76",
}

@unpublished{gavazzoni-santacreu-2015,
    Author = {Gavazzoni, Federico and Ana Maria Santacreu},
    Note = {manuscript, December},
    Title = {International R\&D spillovers and Asset prices},
    Year = {2015}
}

@article{segal-shaliastovich-yaron-2013,
    Author = {Gill, Segal and Ivan Shaliastovich and Amir Yaron},
    Journal = {Journal of Financial Economics},
    Title = {Good and bad uncertainty: macroeconomic and financial market implications},
    Volume={117},
    Pages={369-397},
    Year = {2015}
}

\end{filecontents*}
\usepackage[round,authoryear,comma]{natbib}
\bibliographystyle{jf_nyu}  % or: jf3
\begin{document}
Here's the output \\
\cite{abd:2007}\\
\cite{abde:2001}\\
\cite{gavazzoni-santacreu-2015}\\
\cite{segal-shaliastovich-yaron-2013}\\
\bibliography{\jobname}
\end{document}

Best Answer

Now that you pointed us at the correct bib style to modify here is a much shorter replacement for format.lab.names:

FUNCTION {format.lab.names}
{ 's :=
  s num.names$ 'numnames :=
  s #1 "{vv~}{ll}" format.name$
  numnames #1 >
    { s #2 "{vv~}{ll}" format.name$ 't :=
      numnames #2 >
      t "others" =
      or
        { " et~al." * }
        { " and " * t * }
      if$
    }
    'skip$
  if$
}

On your sample file (slightly tidied, see below) it produces

Sample output

The function works as follows. First store the list of authors in s. Store the number of authors in numnames. Format the first (#1) entry and output it. Then if there is more than one name, format the next name and assign it to t. If t was "others" or there actually are more than two authors output et al. others output the second (final) author preceeded by and.

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@article{abd:2007,
  author      = "Torben G. Andersen and Tim Bollerslev and Francis X. Diebold",
  title       = "Roughing it up: {Including} jump components in the
                measurement, modeling and forecasting of return volatility",
  journal     = "Review of Economics and Statistics",
  year        = 2007,
  volume      = 89,
  number      = 4,
  month       = "November",
  pages       = "701--720",
}

@article{abde:2001,
  author      = "Torben G. Andersen and Tim Bollerslev and Francis X. Diebold
                and Heiko Ebens",
  title       = "The distribution of realized stock return volatility",
  journal     = "Journal of Financial Economics",
  year        = 2001,
  volume      = 61,
  number      = 1,
  month       = "July",
  pages       = "43--76",
}

@unpublished{gavazzoni-santacreu-2015,
    Author = {Gavazzoni, Federico and Ana Maria Santacreu},
    Note = {manuscript, December},
    Title = {International R\&D spillovers and Asset prices},
    Year = {2015}
}

@article{segal-shaliastovich-yaron-2013,
    Author = {Gill, Segal and Ivan Shaliastovich and Amir Yaron},
    Journal = {Journal of Financial Economics},
    Title = {Good and bad uncertainty: macroeconomic and financial market implications},
    Volume={117},
    Pages={369-397},
    Year = {2015}
}

\end{filecontents*}
\usepackage[round,authoryear,comma]{natbib}

\bibliographystyle{jf1}  % or: jf3

\begin{document}
Here's the output

\cite{abd:2007}

\cite{abde:2001}

\cite{gavazzoni-santacreu-2015}

\cite{segal-shaliastovich-yaron-2013}

\bibliography{\jobname}

\end{document}