Biblatex supercite 带方括号和分组

Biblatex supercite 带方括号和分组

我找到了这个代码这里

\documentclass{article}

\usepackage{biblatex}

\DeclareCiteCommand{\supercite}[\mkbibsuperscript]
  {\iffieldundef{prenote}
     {}
     {\BibliographyWarning{Ignoring prenote argument}}%
   \iffieldundef{postnote}
     {}
     {\BibliographyWarning{Ignoring postnote argument}}}
  {\usebibmacro{citeindex}%
   \bibopenbracket\usebibmacro{cite}\bibclosebracket}
  {\supercitedelim}
  {}

\usepackage{filecontents}

\begin{filecontents}{test.bib}
@book{A01,
  author = {Author, A.},
  year = {2001},
  title = {Alpha},
}
@book{B02,
  author = {Buthor, B.},
  year = {2002},
  title = {Bravo},
}
@article{C03,
  author = {Cuthor, C.},
  year = {2003},
  title = {Charlie},
}
\end{filecontents}

\addbibresource{test.bib}

\let\cite=\supercite

\begin{document}

We are citing \supercite{A01,C03} and \supercite{B02} and \cite{A01,B02,C03}

\printbibliography

\end{document}

它将数字放在括号和上标中,但我想将它们分组。在示例中,我得到了 [1],[3],但我想要 [1,3],而不是 [1],[2],[3],我想要 [1-3]。

这可能吗?如果可能,怎么做?

答案1

您必须将命令\bibopenbracket和-loop\bibclosebracket的外部站点放在cite

\DeclareCiteCommand{\supercite}[\mkbibsuperscript]
  {\iffieldundef{prenote}
     {}
     {\BibliographyWarning{Ignoring prenote argument}}%
   \iffieldundef{postnote}
     {}
     {\BibliographyWarning{Ignoring postnote argument}}%
   \bibopenbracket}%
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\supercitedelim}
  {\bibclosebracket}

要获得数字样式的紧凑版本,您可以使用样式numeric-comp。因此,您需要对进行其他修改\supercite

\DeclareCiteCommand{\supercite}[\mkbibsuperscript]
  {\usebibmacro{cite:init}%
   \let\multicitedelim=\supercitedelim
   \iffieldundef{prenote}
     {}
     {\BibliographyWarning{Ignoring prenote argument}}%
   \iffieldundef{postnote}
     {}
     {\BibliographyWarning{Ignoring postnote argument}}%
  \bibopenbracket}%
  {\usebibmacro{citeindex}%
   \usebibmacro{cite:comp}}
  {}
  {\usebibmacro{cite:dump}\bibclosebracket}

以下是完整的 MWE:

\documentclass{article}

\usepackage[style=numeric-comp]{biblatex}


\DeclareCiteCommand{\supercite}[\mkbibsuperscript]
  {\usebibmacro{cite:init}%
   \let\multicitedelim=\supercitedelim
   \iffieldundef{prenote}
     {}
     {\BibliographyWarning{Ignoring prenote argument}}%
   \iffieldundef{postnote}
     {}
     {\BibliographyWarning{Ignoring postnote argument}}%
  \bibopenbracket}%
  {\usebibmacro{citeindex}%
   \usebibmacro{cite:comp}}
  {}
  {\usebibmacro{cite:dump}\bibclosebracket}

\usepackage{filecontents}

\begin{filecontents}{test.bib}
@book{A01,
  author = {Author, A.},
  year = {2001},
  title = {Alpha},
}
@book{B02,
  author = {Buthor, B.},
  year = {2002},
  title = {Bravo},
}
@article{C03,
  author = {Cuthor, C.},
  year = {2003},
  title = {Charlie},
}
\end{filecontents}

\addbibresource{test.bib}

\let\cite=\supercite

\begin{document}

We are citing \supercite{A01,C03} and \supercite{B02} and \cite{A01,B02,C03}

\printbibliography

\end{document}

在此处输入图片描述

相关内容