Biber 和 Biblatex:引用多个子条目

Biber 和 Biblatex:引用多个子条目

我在论文中使用 biblatex 和 biber。我使用集合来包含多个子条目:

在此处输入图片描述

当我引用一个集合的多个子条目(例如 a 和 b)时,我希望输出为:[1a,b],但我得到的却是 [1a,1b]:

在此处输入图片描述

有办法解决这个问题吗?还有类似 [1a-c] 的东西吗?

\RequirePackage{filecontents}
\begin{filecontents}{test.bib}
@article{author1,
journal = {journal},
year = {1999},
author = {author1},
}

@article{author2,
  journal = {journal},
year = {1999},
author = {author2},
}

@article{author3,
journal = {journal},
year = {1999},
author = {author3},
}

\end{filecontents}
\documentclass[12pt,a4paper, headinclude=true, titlepage=true,DIV=12,oneside,BCOR=1cm, numbers=noendperiod, toc=bib, chapterprefix=true]{scrreprt}

\usepackage[babel,german=quotes]{csquotes}
\usepackage[backend=biber,citestyle=numeric-comp,bibstyle=chem-angew,mcite=true,subentry,pageranges=true,sorting=none,citetracker]{biblatex}
\addbibresource{my_refs.bib}
\usepackage[ngerman,KeepShorthandsActive]{babel}                   
\usepackage[utf8]{inputenc}                   
\usepackage[T1]{fontenc}

\addbibresource{test.bib}

\begin{document}

Here I cite a reference with several    subentries.\defbibentryset{set1}{author1,author2,author3}\supercite{set1} Somewhere later, I want to refer to some of the subentries.\supercite{author1,author2}

\printbibliography

\end{document}

答案1

更新

biblatex3.15开始,numeric-comp样式附带一个subentrycomp选项(默认启用),可以压缩子条目引用。

\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[babel,german=quotes]{csquotes}
\usepackage[backend=biber, style=numeric-comp, subentry]{biblatex}

\begin{filecontents}{\jobname.bib}
@article{author1,
  journal = {journal},
  year = {1999},
  author = {author1},
}

@article{author2,
  journal = {journal},
  year = {1999},
  author = {author2},
}

@article{author3,
  journal = {journal},
  year = {1999},
  author = {author3},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}

\begin{document}
\supercite{sigfridsson}
Here I cite a reference with several subentries.\defbibentryset{set1}{author1,author2,author3}\supercite{set1} Somewhere later, I want to refer to some of the subentries.\supercite{author1,author3}

Lorem\supercite{author1,author2}

ipsum\supercite{author1,author2,author3}

ipsum\supercite{vizedom:related}

ipsum\supercite{author1,author2,author3}

ipsum\supercite{author1,author2,author3,vizedom:related,sigfridsson}

ipsum\supercite{author1,author2,author3,vizedom:related,sigfridsson}

ipsum\supercite{author1,author3,vizedom:related,sigfridsson}

ipsum\supercite{author1,author2,vizedom:related,sigfridsson}

ipsum\supercite{author1,vizedom:related,sigfridsson}

ipsum\supercite{author3,vizedom:related,sigfridsson}

ipsum\supercite{set1,vizedom:related,sigfridsson}

\printbibliography
\end{document}

“1a,b,c” 的解决方案并不太复杂。我们只需要重新定义cite:comp:inset一点来检查最后一个是否labelnumber相同。

\RequirePackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{author1,
  journal = {journal},
  year = {1999},
  author = {author1},
}

@article{author2,
  journal = {journal},
  year = {1999},
  author = {author2},
}

@article{author3,
  journal = {journal},
  year = {1999},
  author = {author3},
}
\end{filecontents}
\documentclass[12pt,a4paper, headinclude=true, titlepage=true,DIV=12,oneside,BCOR=1cm, numbers=noendperiod, toc=bib, chapterprefix=true]{scrreprt}
\usepackage[ngerman,KeepShorthandsActive]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[babel,german=quotes]{csquotes}
\usepackage[backend=biber, citestyle=numeric-comp, bibstyle=chem-angew, mcite=true, subentry, pageranges=true, sorting=none, citetracker]{biblatex}

\addbibresource{\jobname.bib}

\makeatletter
\renewbibmacro*{cite:comp:inset}{%
  \usebibmacro{cite:dump}%
  \ifnumgreater{\value{cbx@tempcntb}}{-1}
    {\multicitedelim}
    {}%
  \printtext[bibhyperref]{%
    \iffieldequals{labelnumber}{\cbx@lastnumber}
      {}
      {\printfield{labelprefix}%
       \printfield{labelnumber}}%
    \printfield{entrysetcount}}%
  \savefield{labelnumber}{\cbx@lastnumber}%
  \setcounter{cbx@tempcntb}{-1}}
\makeatother


\begin{document}
Here I cite a reference with several subentries.\defbibentryset{set1}{author1,author2,author3}\supercite{set1} Somewhere later, I want to refer to some of the subentries.\supercite{author1,author2,author3}

\printbibliography
\end{document}

在此处输入图片描述


通过更多的工作,您还可以获得“1a-c”。以下解决方案重新创建了条目numeric-comp的宏@set。该解决方案针对短代码而不是概念上的美观进行了优化。

\RequirePackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{author1,
  journal = {journal},
  year = {1999},
  author = {author1},
}

@article{author2,
  journal = {journal},
  year = {1999},
  author = {author2},
}

@article{author3,
  journal = {journal},
  year = {1999},
  author = {author3},
}
\end{filecontents}
\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[babel,german=quotes]{csquotes}
\usepackage[backend=biber, citestyle=numeric-comp, bibstyle=chem-angew, mcite=true, subentry, pageranges=true, sorting=none, citetracker]{biblatex}

\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}

\makeatletter
% the first two counters are already defined in numeric-comp.cbx
% cbx@tempcnta % no. of labelnumbers we skipped
% cbx@tempcntb % 'predicted' labelnumber for current cite
\newcounter{cbx@tempcntc}% no. of entrysetcounts we skipped
\newcounter{cbx@tempcntd}% 'predicted' entrysetcount
\renewbibmacro*{cite:init}{%
  \global\boolfalse{cbx:parens}%
  \global\undef\cbx@lasthash
  \global\undef\cbx@lastnumber
  \global\undef\cbx@lastprefix
  \global\undef\cbx@lastcount
  \setcounter{cbx@tempcnta}{0}%
  \setcounter{cbx@tempcntb}{-2}%
  \setcounter{cbx@tempcntc}{0}%
  \setcounter{cbx@tempcntd}{-1}}

\newcommand*{\cbx@iflabelnumberequalslast}{%
  \iffieldequals{labelnumber}{\cbx@lastnumber}}

% \iffieldequals is false even if both are empty/undef
% so we need a special test for that case
% this test is optimised for performance and laziness
% rather than prettiness, not that it would matter a lot...
\newcommand*{\cbx@iflabelprefixequalslast}{%
  \ifundef\cbx@lastprefix
    {\iffieldundef{labelprefix}
       {\@firstoftwo}
       {\@secondoftwo}}
    {\iffieldequals{labelprefix}{\cbx@lastprefix}
       {\@firstoftwo}
       {\@secondoftwo}}}

% \cbx@iflabelnumberequalslast and \cbx@iflabelprefixequalslast
\newcommand*{\cbx@iflabelequalslast}{%
  \iffieldequals{labelnumber}{\cbx@lastnumber}
    {\cbx@iflabelprefixequalslast
       {\@firstoftwo}
       {\@secondoftwo}}
    {\@secondoftwo}}

\renewbibmacro*{cite:comp:inset}{%
  \stepcounter{cbx@tempcntd}%
  % the calls for false \cbx@iflabelequalslast
  % are split between stuff that happens before
  % the link and that happens within the link
  \cbx@iflabelequalslast
    {}
    {\usebibmacro{cite:dump}%
     \ifnumgreater{\value{cbx@tempcntb}}{-1}
       {\multicitedelim}
       {}}%
  \printtext[bibhyperref]{%
    \cbx@iflabelequalslast
      {}
      {\setcounter{cbx@tempcntd}{-1}%
       \printfield{labelprefix}%
       \printfield{labelnumber}%
       \savefield{labelprefix}{\cbx@lastprefix}%
       \savefield{labelnumber}{\cbx@lastnumber}}%
    \ifnumequal{\thefield{entrysetcount}}{\value{cbx@tempcntd}}
      {\savefield{entrykey}{\cbx@lastkey}%
       \savefield{entrysetcount}{\cbx@lastcount}%
       \stepcounter{cbx@tempcntc}}
      {\usebibmacro{cite:dump}%
       \ifnumgreater{\value{cbx@tempcntd}}{0}
         {\multicitedelim}
         {}%
       \printfield{entrysetcount}}}%
    \setcounter{cbx@tempcntd}{\thefield{entrysetcount}}%
    \setcounter{cbx@tempcntb}{-1}}

\renewbibmacro*{cite:dump}{%
  % dump subentry
  \ifnumgreater{\value{cbx@tempcntc}}{0}
    {\ifnumgreater{\value{cbx@tempcntc}}{1}
       {\bibrangedash}
       {\multicitedelim}%
     \bibhyperref[\cbx@lastkey]{%
       \printtext[entrysetcount]{\cbx@lastcount}}}
    {}%
  \setcounter{cbx@tempcntc}{0}%
  % dump labelnumber (+labelprefix)
  \ifnumgreater{\value{cbx@tempcnta}}{0}
    {\ifnumgreater{\value{cbx@tempcnta}}{1}
       {\bibrangedash}
       {\multicitedelim}%
     \bibhyperref[\cbx@lastkey]{%
       \ifdef\cbx@lastprefix
         {\printtext[labelprefix]{\cbx@lastprefix}}
         {}%
       \printtext[labelnumber]{\cbx@lastnumber}}%
     \global\undef\cbx@lastprefix}
    {}%
  \setcounter{cbx@tempcnta}{0}}
\makeatother


\begin{document}
\supercite{sigfridsson}
Here I cite a reference with several subentries.\defbibentryset{set1}{author1,author2,author3}\supercite{set1} Somewhere later, I want to refer to some of the subentries.\supercite{author1,author3}

Lorem\supercite{author1,author2}

ipsum\supercite{author1,author2,author3}

ipsum\supercite{vizedom:related}

ipsum\supercite{author1,author2,author3}

ipsum\supercite{author1,author2,author3,vizedom:related,sigfridsson}

ipsum\supercite{author1,author2,author3,vizedom:related,sigfridsson}

ipsum\supercite{author1,author3,vizedom:related,sigfridsson}

ipsum\supercite{author1,author2,vizedom:related,sigfridsson}

ipsum\supercite{author1,vizedom:related,sigfridsson}

ipsum\supercite{author3,vizedom:related,sigfridsson}

ipsum\supercite{set1,vizedom:related,sigfridsson}

\printbibliography
\end{document}

1//这里我引用了一个有多个子条目的参考文献。 2 稍后我想引用一些子条目。 2a,c//Lorem 2a,b//ipsum 2a–c//ipsum 3//ipsum 2a–c//ipsum 1,2a–c,3//ipsum 1,2a–c,3//ipsum 1, 2a,c,3//同上 1,2a,b,3//同上 1,2a,3//同上 1,2c,3//同上 1–3

编辑修复了以下问题安迪·的问题在 biblatex 中压缩集合成员的引用

相关内容