我在我的手稿中定义了以下命令:
\newcommand{\citesep}[2]{\citeauthor{#1}#2~\cite{#1}}
例如,它允许我使用 打印“Knuth 和 Tarjan 的算法 [16]” \citesep{knuth-681}{'s algorithm}
。
但是,这会导致同一作者的论文出现不良行为;例如,\citesep{knuth-681,knuth-702}{'s work}
生成“Knuth 和 Tarjan,Knuth 和 Tarjan 的作品 [16,17]”,而我希望它打印“Knuth 和 Tarjan 的作品 [16,17]”。
有什么办法可以修复它吗?
答案1
我终于想出了一个看似解决方案的方法。我做了以下事情:
深入
natbib.sty
研究负责排版作者姓名的宏段。反复试验发现,它\NAT@nm
执行“原始”排版,然后由 格式化\NAT@nmfmt
。重新定义
\NAT@nmfmt
,以便它将额外排版新\nameadjunct
命令的扩展(默认情况下不执行任何操作)。定义新的命令
\citeposs
和,\citesep
它们是的包装器\citet
,但将\nameadjunct
分别在本地重新定义为“的”\citesep
的第二个强制参数。
\documentclass{article}
\usepackage{natbib}
\newcommand*{\nameadjunct}{\relax}
\makeatletter
\renewcommand*{\NAT@nmfmt}[1]{\NAT@up #1\nameadjunct}
\makeatother
\newcommand*{\citeposs}[2][]{%
\begingroup
\renewcommand*{\nameadjunct}{'s}%
\citet[#1]{#2}%
\endgroup
}
\newcommand*{\citesep}[3][]{%
\begingroup
\renewcommand*{\nameadjunct}{#3}%
\citet[#1]{#2}%
\endgroup
}
\begin{filecontents}{\jobname.bib}
@misc{Knu01,
author = {Knuth, Donald E. and Tarjan, Robert E.},
year = {2001},
title = {A new algorithm},
}
@misc{Knu02,
author = {Knuth, Donald E. and Tarjan, Robert E.},
year = {2002},
title = {More about our algorithm},
}\end{filecontents}
\begin{document}
\citet{Knu01,Knu02}
\citeposs{Knu01,Knu02}
\citesep{Knu01,Knu02}{'s algorithm}
\bibliographystyle{plainnat}
\bibliography{\jobname}
\end{document}
答案2
我不理解 natbib 的复杂性,但这是一个使用的解决方案比布拉特克斯。(注意:我的\citesep
命令对于同时引用同一作者的多篇论文很有效,但对于不同的作者会产生奇怪的结果。)
\documentclass{article}
\usepackage{biblatex}
\makeatletter
% COPIED FROM \newbibmacro*{textcite}
\newbibmacro*{textadjunctcite}{%
\iffieldequals{namehash}{\cbx@lasthash}
{\multicitedelim}
{\cbx@tempa
\ifnameundef{labelname}
{\printfield[citetitle]{labeltitle}}
% {\printnames{labelname}}% DELETED
{\printnames{labelname}% NEW
\printfield{adjunct}}% NEW
\addspace\bibopenbracket}%
\ifnumequal{\value{citecount}}{1}
{\usebibmacro{prenote}}
{}%
\usebibmacro{cite}%
\savefield{namehash}{\cbx@lasthash}%
\gdef\cbx@tempa{\bibclosebracket\multicitedelim}}
% COPIED FROM \DeclareCiteCommand{\textcite}
\DeclareCiteCommand{\textadjunctcite}
{\let\cbx@tempa=\empty
\undef\cbx@lasthash}
{\usebibmacro{citeindex}%
% \usebibmacro{textcite}}% DELETED
\usebibmacro{textadjunctcite}}% NEW
{}
{\usebibmacro{postnote}%
\bibclosebracket}
\newcommand*{\citeposs}[2][]{%
\def\abx@field@adjunct{'s}%
\textadjunctcite[#1]{#2}%
}
\newcommand*{\citesep}[3][]{%
\def\abx@field@adjunct{#3}%
\textadjunctcite[#1]{#2}%
}
\makeatother
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@misc{Knu01,
author = {Knuth, Donald E. and Tarjan, Robert E.},
year = {2001},
title = {A new algorithm},
}
@misc{Knu02,
author = {Knuth, Donald E. and Tarjan, Robert E.},
year = {2002},
title = {More about our algorithm},
}
\end{filecontents}
\bibliography{\jobname}
\begin{document}
This was \citeposs{Knu01,Knu02} work~\dots
As shown in \citesep{Knu01,Knu02}{'s algorithm}~\dots
\printbibliography
\end{document}
编辑:扩展 MWE 以包含\citeposs
命令。