有没有办法在 biblatex 中使用类似于 natbib 的 \citenum 的东西?

有没有办法在 biblatex 中使用类似于 natbib 的 \citenum 的东西?

natbib包提供了命令\citenum,它仅返回引用的编号,与 的排版参考不同\cite。 是否有类似的命令可用biblatex

答案1

假设numeric-comp使用了该样式,可以\citenum按如下方式实现:

\DeclareCiteCommand{\citenum}
  {}
  {\printfield{labelnumber}}
  {}
  {}

它也可以与其他样式一起使用,只需使用labelnumber包选项即可。

\documentclass{article}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
  @article{article1,
    author = {Author, First},
    title  = {Title 1},
    year   = 1993,
    month  = may,
    pages  = {10--15}
  }

  @inproceedings{article2,
    author = {Author, Second},
    booktitle  = {Conference Title},
    title  = {Article 2},
    year   = 1975,
    month  = aug,
    pages  = {120--125}
  }
\end{filecontents}

\usepackage[style=authoryear,citecounter,natbib,labelnumber]{biblatex}
\addbibresource{\jobname.bib}
%\ExecuteBibliographyOptions{labelnumber}

\DeclareCiteCommand{\citenum}
  {}
  {\printfield{labelnumber}}
  {}
  {}

\begin{document}

\cite{article1}

\cite{article2}

\citenum{article1}

\citenum{article2}

\printbibliography  

\end{document}

在此处输入图片描述

答案2

为了考虑到所有可能的情况,我修补了该\cite命令的原始定义numeric-comp.cbx

\documentclass{article}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
  @article{article1,
    author = {Author, First},
    title = {Title 1},
    year = 1993,
    month = may,
    pages = {10--15}
  }

  @inproceedings{article2,
    author = {Author, Second},
    booktitle = {Conference Title},
    title = {Article 2},
    year = 1975,
    month = aug,
    pages = {120--125}
  }
\end{filecontents}

\usepackage[style=numeric-comp,citecounter,natbib,labelnumber]{biblatex}
\addbibresource{\jobname.bib}
%
\DeclareCiteCommand{\cite}%
  {\usebibmacro{cite:init}%
   \usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite:comp}}
  {}
  {\usebibmacro{cite:dump}%
   \usebibmacro{postnote}}

\begin{document}

\cite{article1}

\cite{article2}

\printbibliography

\end{document} 

在此处输入图片描述

相关内容