Biblatex:引用中有“and”,但参考书目中有“&”

Biblatex:引用中有“and”,但参考书目中有“&”

我开始使用 BibLatex/biber 来处理我在 Latex 中的书目条目。使用 authoryear 样式作为开始,我进行了一些调整,以符合我将向其提交论文的期刊的编辑风格。其中一项调整是使用以下代码将书目中最后一位作者前的默认“and”替换为“&”符号:

% Add a comma and replace "and" with "&" before last coauthor
\renewcommand*{\finalnamedelim}{%
   \ifnumgreater{\value{liststop}}{2}{\finalandcomma}{}%
   \addcomma\addspace\&\space}

不幸的是,此代码也替换了引用中的“and”,这与期刊对引用的要求相反。

我的问题是,如何仅在参考书目中用“&”替换“and”?似乎 biblatex-dw 有这个选项,但我的文档不能用这种样式编译。

答案1

我确信BibLaTeX有更好、更有效的解决方案,下面是一个快速破解方法

\documentclass{article}

\usepackage{filecontents}
\usepackage{etoolbox}
\usepackage[style=authoryear]{biblatex}

\newtoggle{incitation}
\pretocmd{\citesetup}{\toggletrue{incitation}}{}{}
\pretocmd{\bibsetup}{\togglefalse{incitation}}{}{}
\newcommand{\biband}{\iftoggle{incitation}{and}{\&}}

\renewcommand*{\finalnamedelim}{%
   \ifnumgreater{\value{liststop}}{2}{\finalandcomma}{}%
   \addcomma\addspace\biband\space}

\begin{filecontents}{\jobname.bib}
@article{test,
 author = "Family, Given and FamilyTwo, GivenTwo",
 title = "title",
 journal = "Journal",
 year = "2012"}
\end{filecontents}

\addbibresource{\jobname.bib}

\begin{document}

\cite{test}

\printbibliography

\end{document}  

编辑

根据@Audrey 的建议

\documentclass{article}

\usepackage{filecontents}
\usepackage[style=authoryear]{biblatex}

\newcommand{\biband}{\ifcurrentname{labelname}{\bibstring{and}}{\&}}

\renewcommand*{\finalnamedelim}{%
   \ifnumgreater{\value{liststop}}{2}{\finalandcomma}{}%
   \addcomma\addspace\biband\space}

\begin{filecontents}{\jobname.bib}
@article{test,
 author = "Family, Given and FamilyTwo, GivenTwo",
 title = "title",
 journal = "Journal",
 year = "2012"}
\end{filecontents}

\addbibresource{\jobname.bib}

\begin{document}

\cite{test}

\printbibliography

\end{document}                    

答案2

\documentclass{article}

\usepackage{filecontents}
\usepackage[style=authoryear,backend=biber]{biblatex}% delete backend= when running bibtex

\begin{filecontents}{\jobname.bib}
@article{test,
 author = "Family, Given and FamilyTwo, GivenTwo and Family3, Given3",
 title = "title",
 journal = "Journal",
 year = "2012"}
\end{filecontents}

\addbibresource{\jobname.bib}

\begin{document}
foo\cite{test}

\begingroup
\renewcommand*\finalnamedelim{ \& }
\printbibliography
\endgroup
\end{document}

相关内容