类似 \textcite 的新命令,但可自由配置作者数量

类似 \textcite 的新命令,但可自由配置作者数量

我正在使用 biblatex,并希望定义一个类似的新命令\textcite,但可以自由配置打印的作者数量。在文档的其余部分,我仍然想使用全局配置,例如全局的maxcitenames

以下是一个小例子:

\documentclass{article}
\usepackage[citestyle=numeric-comp,bibstyle=numeric,backend=biber,maxcitenames=1,maxbibnames=10]{biblatex}
\begin{filecontents}{ref.bib}
@BOOK{test1,
  AUTHOR    = {Author, A. and Buthor, B. and Cuthor, C. and Duthor, D.},
  TITLE     = {Test},
  YEAR      = {2000},
}  
\end{filecontents}
\addbibresource{ref.bib}

\newcommand{\textcitenew}[1]{\AtNextCite{\defcounter{maxnames}{#1}}\textcite}

\begin{document}
Reference to \textcite{test1} and \textcitenew{3}{test1}.
\printbibliography
\end{document}

期望的输出是 Reference to Author et al. [1] and Author, Buthor, Cuthor et al. [1].

实际输出是Reference to Author et al. [1] and Author et al. [1].

参考作者等1和作者等1。

我认为,一个好的解决方案是进行局部改变maxcitenames,但不幸的是,这并不能在示例中产生预期的结果。

澄清:我希望打印的作者数量完全等于新命令的参数(不截断)。

答案1

改编

结果

在此处输入图片描述

代码

\documentclass{article}
\usepackage[citestyle=numeric-comp,bibstyle=numeric,backend=biber,maxcitenames=1,maxbibnames=10]{biblatex}
\begin{filecontents}{ref.bib}
@BOOK{test1,
  AUTHOR    = {Author, A. and Buthor, B. and Cuthor, C. and Duthor, D.},
  TITLE     = {Test},
  YEAR      = {2000},
}  
\end{filecontents}
\addbibresource{ref.bib}

\makeatletter
\newrobustcmd*{\setmincitenames}{\numdef\blx@mincitenames}
\newrobustcmd*{\setmaxcitenames}{\numdef\blx@maxcitenames}
\makeatother
\newcommand{\textcitenew}[2]{{\setmincitenames{#1}\setmaxcitenames{#1}\textcite{#2}}}

\begin{document}
\textcite{test1}

2: \textcitenew{2}{test1}

3: \textcitenew{3}{test1}

4: \textcitenew{4}{test1}

\printbibliography
\end{document}

相关内容