我使用以下风格:
\usepackage[style=authoryear-comp,
backend=biber,
giveninits=true
]{biblatex}
我的 bib 文件中有以下两个示例条目
@article{HN2018a,
author = {THOMPSON, RAY},
title = {Exemplary Title A},
journal = {The Journal of Bibtex-Examples},
volume = {4343},
number = {2},
pages = {1-2},
year = {2018}
}
@article{HN2018b,
author = {Thompson, RAY},
title = {Exemplary Title B},
journal = {The Journal of Bibtex Second-Entries},
volume = {3},
number = {4},
pages = {1-2},
year = {2018}
}
我使用这个命令:\cite{HN2018a,HN2018b}
我得到:
汤普森 2018a,b
我对这个结果有两点不满。首先,逗号后没有空格。其次,我认为最好有
汤普森 2018a、2018b
是否可以通过使用的引用样式来改变这种情况?
答案1
逗号是硬编码的authoryear-comp.cbx
(但它可以被自定义为extradateonlycompcitedelim
- 多么朗朗上口的名字 - 在biblatex-ext
的-comp
样式版本中)。
为了生成这些紧凑的引文,biblatex
需要记住最后一条条目的年份。如果我们可以让它忘记那一年,我们就会自动获得所需的引文样式。
\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}
\usepackage[style=authoryear-comp,
backend=biber,
giveninits=true, uniquename=init,
]{biblatex}
\makeatletter
\AtEveryCitekey{\global\undef\cbx@lastyear}
\makeatother
\addbibresource{biblatex-examples.bib}
\begin{document}
\autocite{knuth:ct:b,knuth:ct:c}
\printbibliography
\end{document}
以下解决方案在概念上对我来说感觉更好,但需要很多更多代码。我们可以重新定义相关的引用bibmacros来直接删除测试\cbx@lastyear
。
\makeatletter
\renewbibmacro*{cite}{%
\iffieldundef{shorthand}
{\ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}}
{\usebibmacro{cite:label}%
\setunit{\printdelim{nonameyeardelim}}%
\usebibmacro{cite:labeldate+extradate}%
\usebibmacro{cite:reinit}}
{\iffieldequals{namehash}{\cbx@lasthash}
{\setunit{\compcitedelim}%
\usebibmacro{cite:labeldate+extradate}}
{\printnames{labelname}%
\setunit{\printdelim{nameyeardelim}}%
\usebibmacro{cite:labeldate+extradate}%
\savefield{namehash}{\cbx@lasthash}}}}
{\usebibmacro{cite:shorthand}%
\usebibmacro{cite:reinit}}%
\setunit{\multicitedelim}}
\renewbibmacro*{citeyear}{%
\iffieldundef{shorthand}
{\iffieldundef{labelyear}
{\usebibmacro{cite:label}%
\usebibmacro{cite:reinit}}
{\iffieldequals{namehash}{\cbx@lasthash}
{\setunit{\compcitedelim}%
\usebibmacro{cite:labeldate+extradate}}
{\usebibmacro{cite:labeldate+extradate}%
\savefield{namehash}{\cbx@lasthash}}}}
{\usebibmacro{cite:shorthand}%
\usebibmacro{cite:reinit}}%
\setunit{\multicitedelim}}
\renewbibmacro*{textcite}{%
\iffieldequals{namehash}{\cbx@lasthash}
{\iffieldundef{shorthand}
{\setunit{\compcitedelim}%
\usebibmacro{cite:labeldate+extradate}}
{\setunit{\compcitedelim}%
\usebibmacro{cite:shorthand}}}
{\ifnameundef{labelname}
{\iffieldundef{shorthand}
{\usebibmacro{cite:label}%
\setunit{%
\global\booltrue{cbx:parens}%
\printdelim{nonameyeardelim}\bibopenparen}%
\ifnumequal{\value{citecount}}{1}
{\usebibmacro{prenote}}
{}%
\usebibmacro{cite:labeldate+extradate}}
{\usebibmacro{cite:shorthand}}}
{\printnames{labelname}%
\setunit{%
\global\booltrue{cbx:parens}%
\printdelim{nameyeardelim}\bibopenparen}%
\ifnumequal{\value{citecount}}{1}
{\usebibmacro{prenote}}
{}%
\iffieldundef{shorthand}
{\iffieldundef{labelyear}
{\usebibmacro{cite:label}}
{\usebibmacro{cite:labeldate+extradate}}}
{\usebibmacro{cite:shorthand}}}%
\stepcounter{textcitecount}%
\savefield{namehash}{\cbx@lasthash}}%
\setunit{%
\ifbool{cbx:parens}
{\bibcloseparen\global\boolfalse{cbx:parens}}
{}%
\textcitedelim}}
\makeatother
与原始定义进行比较authoryear-comp.cbx
(版本 3.14 中第 26-114 行)。