references.bib
假设我的文件中有以下条目
@incollection{sampleref,
author = "Author 1 and Author 2",
title = "Sample Title",
booktitle = "A sample book title",
publisher = "Custom Monographs",
year = 2020,
pages = "1-10",
chapter = 1,
}
此外,我还有以下最小代码。
\documentclass[11pt,letterpaper,openany,oneside]{book}
\usepackage[square,sort,comma,numbers]{natbib}
\begin{document}
It was \citeauthor{sampleref} % would like to isolate author 2
in \cite{sampleref} who came up with Theorem X.
\nocite{*}
\bibliographystyle{plainnat} % to use natbib
\bibliography{references}
\end{document}
我正在使用natbib
,我想特别提到作者 2。如果我使用\citeauthor{sampleref}
,我会Author 1 and Author 2
在正文中出现。
是否可以使用\citeauthor
或其他技术来隔离具有.bib
多个作者的条目中的一位特定作者?
答案1
natbib
实际上,引文中并没有以机器可读的形式提供引文作者列表。因此,一个命令可以让你排版特别的你的引用的作者有点难以实现。
所以我建议你手动输入名称。如果你想要链接它,下面的内容应该可以帮助你
\documentclass{article}
\usepackage{natbib}
\usepackage{hyperref}
\makeatletter
\newcommand*{\linktocite}[2]{%
\hyper@natlinkstart{#1}#2\hyper@natlinkend}
\makeatother
\begin{filecontents}{\jobname.bib}
@book{appleby,
author = {Humphrey Appleby and James Hacker and Annie Hacker and Bernard Wolley},
title = {On the Importance of the Civil Service},
year = {1980},
publisher = {Pub \& Co.},
}
\end{filecontents}
\begin{document}
\cite{appleby}
\linktocite{appleby}{Annie Hacker}
\bibliographystyle{plainnat}
\bibliography{\jobname}
\end{document}
只是为了好玩,这里biblatex
实现了一个\citespecificauthor
命令,让你选择你想要引用的特定作者。这个实现比我最初想象的要长一点,但这主要是为了让输入更直观一些。我们滥用 postnote 参数来传递作者编号,所以我们需要一些技巧来让事情正确。
\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}
\usepackage[style=authoryear, maxbibnames=999, backend=biber]{biblatex}
\usepackage{hyperref}
\DeclareNameFormat{labelname:noetal}{%
\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}
\makeatletter
\protected\def\nmu@ifinstr#1#2{%
\def\nmu@ifinstr@i##1#2##2\nmu@end{%
\notblank{##2}}%
\nmu@ifinstr@i#1#2\nmu@end}
\newcommand*{\printspecificlabelname@n}[1]{%
\nmu@ifinstr{#1}{-}
{\printnames[labelname:noetal][#1]{labelname}}
{\printnames[labelname:noetal][#1-#1]{labelname}}}
\newcommand*{\printspecificlabelname@x}[1]{%
\begingroup
\edef\x{\endgroup\printspecificlabelname@n{#1}}%
\x}
\DeclareCiteCommand{\citespecificauthor}
{\boolfalse{citetracker}%
\boolfalse{pagetracker}}
{\printtext[bibhyperref]{%
\iffieldundef{postnote}
{\printnames{labelname}}
{\printspecificlabelname@x{\thefield{postnote}}}}}
{\multicitedelim}
{}
\makeatother
\begin{filecontents}{\jobname.bib}
@book{appleby,
author = {Humphrey Appleby and James Hacker and Annie Hacker and Bernard Wolley},
title = {On the Importance of the Civil Service},
year = {1980},
publisher = {Pub \& Co.},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}
\begin{document}
\cite{sigfridsson,appleby}
\citespecificauthor[3]{appleby}
\citespecificauthor[1-2]{appleby}
\citespecificauthor{appleby}
\printbibliography
\end{document}
如果您调整自己的.bst
风格来为每个条目生成一个机器可读的名称列表,那么您可以使用 实现类似的功能natbib
。
关键是plainnat-namelist.bst
使用https://gist.github.com/moewew/80f83c4c93a9f0cdf4fada246b454fe2而不是plainnat.bst
。 差异plainnat.bst
是
--- plainnat.bst 2010-09-14 11:10:56.000000000 +0200
+++ plainnat-namelist.bst 2020-08-01 14:26:49.739944200 +0200
@@ -1,3 +1,11 @@
+%%%% plainnat-namelist.bst
+%%%% A version of plainnat that extracts the author names in
+%%%% machine-readable format for further use on the LaTeX side.
+%%%% The new macro is make.list.names and friends.
+%%%% 2020-08-01 MW
+%%%% for https://tex.stackexchange.com/q/556932/35864
+%%%%
+%%%% original copyrght header follows
%% File: `plainnat.bst'
%% A modification of `plain.bst' for use with natbib package
%%
@@ -373,6 +381,65 @@
if$
}
+FUNCTION {format.list.names}
+{'s :=
+ #1 'nameptr :=
+ s num.names$ 'numnames :=
+ numnames 'namesleft :=
+ { namesleft #0 > }
+ { "\namelistitem{"
+ cite$ *
+ "}{" *
+ nameptr int.to.str$ *
+ "}{" *
+ s nameptr "{vv~}{ll}" format.name$ *
+ "}" *
+ write$
+ newline$
+ nameptr #1 + 'nameptr :=
+ namesleft #1 - 'namesleft :=
+ }
+ while$
+}
+
+FUNCTION {author.editor.list}
+{ author empty$
+ { editor empty$
+ { "" }
+ { editor format.list.names }
+ if$
+ }
+ { author format.list.names }
+ if$
+}
+
+FUNCTION {author.list}
+{ author empty$
+ { "" }
+ { author format.list.names }
+ if$
+}
+
+FUNCTION {editor.list}
+{ editor empty$
+ { "" }
+ { editor format.list.names }
+ if$
+}
+
+FUNCTION {make.list.names}
+{ type$ "book" =
+ type$ "inbook" =
+ or
+ 'author.editor.list
+ { type$ "proceedings" =
+ 'editor.list
+ 'author.list
+ if$
+ }
+ if$
+}
+
FUNCTION {output.bibitem}
{ newline$
"\bibitem[" write$
@@ -385,6 +452,8 @@
cite$ write$
"}" write$
newline$
+ make.list.names
+ newline$
""
before.all 'output.state :=
}
@@ -1420,6 +1489,8 @@
write$ newline$
" \providecommand{\doi}{doi: \begingroup \urlstyle{rm}\Url}\fi"
write$ newline$
+ " \providecommand{\namelistitem}[3]{}"
+ write$ newline$
}
EXECUTE {begin.bib}
接下来只需使用这些数据即可。
\documentclass{article}
\usepackage{natbib}
\usepackage{hyperref}
\usepackage{etoolbox}
\makeatletter
\newcommand*{\namelistitem}[3]{%
\immediate\write\@auxout{\string\namelistitemaux{#1}{#2}{#3}}}
\newcommand*{\namelistitemaux}[3]{%
\csgdef{nmu@namelist@#1@#2}{#3}}
\newcommand*{\citespecificauthor}[2]{%
\hyper@natlinkstart{#1}%
\ifcsundef{nmu@namelist@#1@#2}
{\textbf{??}}
{\csuse{nmu@namelist@#1@#2}}%
\hyper@natlinkend}
\makeatother
\begin{filecontents}{\jobname.bib}
@book{appleby,
author = {Humphrey Appleby and James Hacker and Annie Hacker and Bernard Wolley},
title = {On the Importance of the Civil Service},
year = {1980},
publisher = {Pub \& Co.},
}
\end{filecontents}
\begin{document}
\cite{appleby}
\citespecificauthor{appleby}{2}
\bibliographystyle{plainnat-namelist}
\bibliography{\jobname}
\end{document}