假设我有一个 bib 文件,其中包含所有条目中每个作者的姓氏和名字。有些期刊要求在第一次引用参考文献时添加名字,例如,John Q. Smith (1972)
而不仅仅是Smith(1972)
。我目前是 bibtex 用户,但我四处寻找却没有找到任何东西。如果需要,我也会考虑使用 biblatex 解决方案。
我包含了一个 MWEB,但显然它不能提供我想要的东西。
\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}
答案1
有biblatex
两种解决方案。
简单的解决方案是在第一次引用任何作品时打印全名。
\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}
第二种解决方案仅在第一次出现时完整打印每个名称。这更复杂,因为需要跟踪名称而不是条目。代码实现了一个新选项nametracker
。如果设置为,context
则将分别跟踪文本和脚注的名称,如果设置为global
(别名true
),则不会分别跟踪名称。nametracker=off
禁用名称跟踪。这个想法基于第一次出现时在 biblatex 中引用作者的全名,首次出现时自动完整引用作者姓名和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}
两种方法并存。