![biblatex:authoryear 样式和 \cite 重新定义 = 多次引用错误](https://linux22.com/image/249055/biblatex%EF%BC%9Aauthoryear%20%E6%A0%B7%E5%BC%8F%E5%92%8C%20%5Ccite%20%E9%87%8D%E6%96%B0%E5%AE%9A%E4%B9%89%20%3D%20%E5%A4%9A%E6%AC%A1%E5%BC%95%E7%94%A8%E9%94%99%E8%AF%AF.png)
在一个很好的答案的帮助下https://tex.stackexchange.com/a/50706/13904我能够将\cite
命令重新定义为:
\renewbibmacro*{cite}{%
\iffieldundef{shorthand}
{\ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}}
{\usebibmacro{cite:label}%
\setunit{\addspace}}
{\printnames{labelname}%
\setunit{\nameyeardelim}}%
% \usebibmacro{cite:labelyear+extrayear}}% DELETED
\printtext[brackets]{\usebibmacro{cite:labelyear+extrayear}}}% ADDED
{\usebibmacro{cite:shorthand}}}
但当对同一作者有多次引用时就会出现问题。
\cite{Hembree88,Hembree90}
给出
亨布里 1988亨布里 1990
代替
亨布里 [1988; 1990]
知道如何解决这个问题吗?
这是一个有效的例子:
\documentclass{article}
\usepackage[english]{babel}
\usepackage[style=authoryear-icomp]{biblatex}
\makeatletter
\renewbibmacro*{cite}{%
\iffieldundef{shorthand}
{\ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}}
{\usebibmacro{cite:label}%
\setunit{\addspace}}
\printnames{labelname}%
\setunit{\nameyeardelim}}%
\printtext[brackets]{\usebibmacro{cite:labelyear+extrayear}}}% ADDED
{\usebibmacro{cite:shorthand}}}
\makeatother
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@misc{A01,
author = {Author, A.},
year = {2001},
title = {Alpha},
}
@misc{A02,
author = {Author, A.},
year = {2002},
title = {Alpha},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\begin{document}
\cite{A01,A02}
\printbibliography
\end{document}
答案1
根据您提供的信息,您应该使用命令\textcite
而不是\cite
。此命令使用括号执行您的请求,()
因此您可以在声明中更改它\textcite
。年份的分隔由命令设置\compcitedelim
。
\documentclass{article}
\usepackage[english]{babel}
\usepackage[style=authoryear-icomp]{biblatex}
\DeclareCiteCommand{\textcite}
{\usebibmacro{cite:init}}
{%
\let\bibopenparen\bibopenbracket%
\let\bibcloseparen\bibclosebracket%
\usebibmacro{citeindex}%
\usebibmacro{textcite}}
{}
{\usebibmacro{textcite:postnote}}
\renewcommand*\compcitedelim{\addsemicolon\space}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@misc{A01,
author = {Author, A.},
year = {2001},
title = {Alpha},
}
@misc{A02,
author = {Author, A.},
year = {2002},
title = {Alpha},
}
@misc{A03,
author = {Author, A.},
year = {2003},
title = {Alpha},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\begin{document}
\textcite{A01,A02,A03}
\printbibliography
\end{document}
结果是