8

Suppose that I have a bib file that includes, for all entries, the last name and the first name of each author. Some journals ask that for the first citation of a reference the first name is added, e.g. John Q. Smith (1972) instead of just Smith(1972). I am currently a bibtex user and I have looked around without finding anything. I would also consider a biblatex solution, if needed.

I include a MWEB, that, obviously does not give what I want.

\documentclass[12pt]{article}
\usepackage[a4paper]{geometry}
\usepackage{natbib}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
   @book{Gnus,
    author = {David A. Zoo},
    title = {Gnats of the world},
    publisher = {Epic},
    Year = {2018},
    }
\end{filecontents}
\begin{document}
The first citation \citet{Gnus} and some text.
Here I cite \citet{Gnus} for the second time. 
I would like the two citations to be different.
\bibliography{\jobname}
\bibliographystyle{plainnat}
\end{document}
7

With biblatex there are two solutions.

The easy solution prints the full name the first time any work is cited.

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}

\usepackage[style=authoryear, backend=biber, citetracker=true]{biblatex}

\addbibresource{biblatex-examples.bib}

\DeclareNameFormat{labelname}{%
  \ifciteseen
    {\ifcase\value{uniquename}%
       \usebibmacro{name:family}
         {\namepartfamily}
         {\namepartgiven}
         {\namepartprefix}
         {\namepartsuffix}%
     \or
       \ifuseprefix
         {\usebibmacro{name:given-family}
           {\namepartfamily}
           {\namepartgiveni}
           {\namepartprefix}
           {\namepartsuffixi}}
         {\usebibmacro{name:given-family}
           {\namepartfamily}
           {\namepartgiveni}
           {\namepartprefixi}
           {\namepartsuffixi}}%
     \or
       \usebibmacro{name:given-family}
         {\namepartfamily}
         {\namepartgiven}
         {\namepartprefix}
         {\namepartsuffix}%
     \fi}
    {\usebibmacro{name:given-family}
       {\namepartfamily}
       {\namepartgiven}
       {\namepartprefix}
       {\namepartsuffix}}
    \usebibmacro{name:andothers}}

\begin{document}
\cite{sigfridsson}

\cite{knuth:ct:a}

\cite{sigfridsson}

\cite{knuth:ct:b}

\cite{vizedom:related}

\cite{knuth:ct:a}

\cite{vizedom:related}

\cite{knuth:ct:b}

\printbibliography
\end{document}

The second solution prints each name in full only the first time it appears. This is more complicated since names need to be tracked and not the entries. The code implements a new option nametracker. If set to context names will be tracked separately for the text and footnotes, if set to global (alias true) names will not be tracked separately. nametracker=off disables name tracking. This idea is based on Citing author's full name in biblatex the first time it appears, Automatically cite author's name in full the first time it appears and https://github.com/LukasCBossert/biblatex-archaeologie/pull/124

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}

\usepackage[style=authoryear, backend=biber]{biblatex}

\addbibresource{biblatex-examples.bib}

\makeatletter
\newrobustcmd*{\cbx@nametracker@global}[1]{%
  \xifinlistcs{#1}{cbx@bseen@names@\the\c@refsection}
    {}
    {\listcsxadd{cbx@bseen@names@\the\c@refsection}{#1}}}

\newrobustcmd*{\cbx@nametracker@context}[1]{%
  \iftoggle{blx@footnote}
    {\xifinlistcs{#1}{cbx@fseen@names@\the\c@refsection}
       {}
       {\listcsxadd{cbx@fseen@names@\the\c@refsection}{#1}}}
    {\xifinlistcs{#1}{cbx@bseen@names@\the\c@refsection}
       {}
       {\listcsxadd{cbx@bseen@names@\the\c@refsection}{#1}}}}

\newrobustcmd*{\cbx@ifnameseen@global}[1]{%
  \xifinlistcs{#1}{cbx@bseen@names@\the\c@refsection}}

\newrobustcmd*{\cbx@ifnameseen@context}[1]{%
  \iftoggle{blx@footnote}%
    {\xifinlistcs{#1}{cbx@fseen@names@\the\c@refsection}}%
    {\xifinlistcs{#1}{cbx@bseen@names@\the\c@refsection}}}

\DeclareBibliographyOption[string]{nametracker}[true]{%
  \ifcsdef{blx@opt@nametracker@#1}
    {\csuse{blx@opt@nametracker@#1}}
    {\blx@err@invopt{nametracker=#1}{}}}

\def\blx@opt@nametracker@global{%
  \let\cbx@ifnameseen\cbx@ifnameseen@global
  \let\cbx@nametracker\cbx@nametracker@global}

\let\blx@opt@nametracker@true\blx@opt@nametracker@global

\def\blx@opt@nametracker@false{%
  \protected\long\def\cbx@ifnameseen##1##2##3{##3}%
  \let\cbx@nametracker\relax}

\def\blx@opt@nametracker@context{%
  \let\cbx@ifnameseen\cbx@ifnameseen@context
  \let\cbx@nametracker\cbx@nametracker@context}

\appto\blx@secinit{%
  \ifcsundef{cbx@bseen@names@\the\c@refsection}
    {\global\cslet{cbx@bseen@names@\the\c@refsection}\@empty}
    {}%
  \ifcsundef{cbx@fseen@names@\the\c@refsection}
    {\global\cslet{cbx@fseen@names@\the\c@refsection}\@empty}
    {}}

\InitializeCitationStyle{%
  \global\cslet{cbx@bseen@names@\the\c@refsection}\@empty
  \global\cslet{cbx@fseen@names@\the\c@refsection}\@empty}

\ExecuteBibliographyOptions{nametracker=context}

\DeclareNameFormat{labelname}{%
  \cbx@ifnameseen{\thefield{hash}}
    {\ifcase\value{uniquename}%
       \usebibmacro{name:family}
         {\namepartfamily}
         {\namepartgiven}
         {\namepartprefix}
         {\namepartsuffix}%
     \or
       \ifuseprefix
         {\usebibmacro{name:given-family}
           {\namepartfamily}
           {\namepartgiveni}
           {\namepartprefix}
           {\namepartsuffixi}}
         {\usebibmacro{name:given-family}
           {\namepartfamily}
           {\namepartgiveni}
           {\namepartprefixi}
           {\namepartsuffixi}}%
     \or
       \usebibmacro{name:given-family}
         {\namepartfamily}
         {\namepartgiven}
         {\namepartprefix}
         {\namepartsuffix}%
     \fi}
    {\usebibmacro{name:given-family}
       {\namepartfamily}
       {\namepartgiven}
       {\namepartprefix}
       {\namepartsuffix}%
     \cbx@nametracker{\thefield{hash}}}%
    \usebibmacro{name:andothers}}
\makeatother

\begin{document}
\cite{sigfridsson}

\cite{knuth:ct:a}

\cite{sigfridsson}

\cite{knuth:ct:b}

\cite{vizedom:related}

\cite{knuth:ct:a}

\cite{vizedom:related}

\cite{knuth:ct:b}

\printbibliography
\end{document}

The two approaches side-by-side.

enter image description here

  • I had the first solution in mind with my question. But the second solution is clearly what I needed. Great. – Denis Mar 13 '18 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.