9

I am using biblatex with biber for my thesis. I use sets to have several subentries:

enter image description here

When I refer to multiple subentries (e.g. a & b) of one set, I would like an output as: [1a,b], but instead I get [1a,1b]:

enter image description here

Is there a way to solve this? And also something like: [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}
tujult
  • 93

1 Answers1

9

Update

From biblatex 3.15 onwards the numeric-comp style comes with a subentrycomp option (enabled by default) that compresses subentry references as well.

\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}


An '1a,b,c' solution is not too complicated. We only need to redefine cite:comp:inset a little to check if the last labelnumber is the same.

\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}

enter image description here


With more work you can also get '1a-c'. The following solution recreates the numeric-comp macros for @set entries. The solution is optimised for short code rather than conceptual niceness.

\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//Here I cite a reference with several subentries. 2 Somewhere later, I want to refer to some of the subentries. 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//ipsum 1,2a,b,3//ipsum 1,2a,3//ipsum 1,2c,3//ipsum 1–3

edit Fixed an issue following AndiW's question compress citation of set members in biblatex.

moewe
  • 175,683
  • 1
    '1a-c' is much harder, I'll see what I can do there. – moewe Feb 21 '18 at 13:14
  • Let me know in an MWE if there are problems with the extended solution. I'm sure there are some edge cases I didn't think of and test. – moewe Feb 21 '18 at 15:08
  • Unfortunately this solution breaks if one adds set members of different sets in one cite command... Looks like there is some more checking for a changed labelnumber needed... – AndiW Jan 16 '19 at 22:28