使用 BibLaTeX,我想创建一个\textcite
基于 numeric-comp 样式的命令,它不显示 [1-3, 5] 而是显示参考文献 1-3 和 5,也不显示 [1-3, 5-7] 而是显示参考文献 1-3 和 5-7。
我已经能够实现前者,但无法通过以下 MWE 实现后者:
\documentclass{article}
\usepackage{filecontents}
\usepackage[style=numeric-comp]{biblatex}
% Cite without square brackets - with Ref./Refs.
\NewBibliographyString{refname}
\NewBibliographyString{refsname}
\DefineBibliographyStrings{english}{%
refname = {Ref\adddot},
refsname = {Refs\adddot}
}
\DeclareCiteCommand{\textcite}
{%
\ifnum\thecitetotal=1
\bibstring{refname}%
\else%
\bibstring{refsname}%
\fi%
\addnbspace%
\usebibmacro{cite:init}%
\usebibmacro{prenote}%
\renewcommand*{\multicitedelim}{\iflastcitekey{\addspace\bibstring{and}\addspace}{\addcomma\addspace}}%
}
{\usebibmacro{citeindex}\usebibmacro{cite:comp}}
{}
{\usebibmacro{cite:dump}\usebibmacro{postnote}}
\begin{filecontents*}{\jobname.bib}
@book{A,
title = {A Bla},
author = {A Foo}
}
@book{B,
title = {B Bla},
author = {B Foo}
}
@book{C,
title = {C Bla},
author = {C Foo}
}
@book{D,
title = {D Bla},
author = {D Foo}
}
@book{E,
title = {E Bla},
author = {E Foo}
}
@book{F,
title = {F Bla},
author = {F Foo}
}
@book{G,
title = {G Bla},
author = {G Foo}
}
\end{filecontents*}
\addbibresource{\jobname.bib}
\begin{document}
\nocite{*}
Cite commands should stay like this (i.e. no and): \cite{A,B,C,E,F,G}
These textcites work: \textcite{A,C,E,G} ; \textcite{A,B,C,E}
This textcite misses the final and: \textcite{A,C,E,F,G}
This textcite has two ands: \textcite{A,C,D,F}
\printbibliography
\end{document}
MWE 的输出:
我认为问题在于,当引用被压缩时,最后一个引用键位于压缩间隔内,因此根本没有打印引用列表分隔符。是否有一个测试可以用来检查哪个是实际打印的最后一个分隔符,即使它不在最后一个引用键之前?另外,请注意,在最后一个示例中不知何故有两个“and”,我认为问题再次在于它\iflastcitekey
实际上没有按预期工作。