0

Because i have a quite large number of literature sources (and for the sake of clarity), I chose to use separate (printed) bibliographies for the various chapters by using the biblatex command \bibbysection. Because I was not 100% convinced of that solution, I tried (for curiosity) to add a prefix to the intext citation using the chapter number, which results e.g. in [1.1]. This works fine if I use \printbibliography within the chapters but not anymore with \bibbysection.

So please help me (to understand) what's missing here. Thx in advance.

\documentclass{scrbook}
\usepackage{blindtext}
\usepackage[backend=biber, refsection=chapter, defernumbers=true, style=numeric]{biblatex}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
    @book{Knuth.1986,
        author = {Knuth, Donald E.},
        year = {1986},
        title = {The \TeX book},
    }   
    @article{Einstein.1923,
        author = {Einstein, Albert},
        year = {1923},
        title = {Grundgedanken und Probleme der Relativitätstheorie},
    }
\end{filecontents}
\addbibresource{\jobname.bib}
\DeclareRefcontext{myContext}{labelprefix=\therchapter.}

\begin{document} %\begin{refcontext}[labelprefix=\thechapter.]{altContext}

\chapter{Ch 1} \newrefcontext{myContext} \blindtext \cite{Knuth.1986} \cite{Einstein.1923} %\printbibliography[heading=subbibliography,section=\therefsection]

\chapter{Ch 2} \newrefcontext{myContext} \blindtext \cite{Einstein.1923} %\printbibliography[heading=subbibliography,section=\therefsection]

\bibbysection %\end{refcontext} \end{document}

Bernard
  • 271,350
Venez
  • 611

1 Answers1

0

biblatex usually assigns an entry to the refcontext in which it was last printed. But in \bibbysection this doesn't quite work because the command may be called outside the desired refcontext. (A similar issue is discussed in Biblatex: dual referencing (both by end of chapter and at the end of the document) on "Clas­sicTh­e­sis" by Dr. André Miede) I did not manage to find a combination of refcontext assignment commands that produces the desired outcome, but since you only want to prefix citations with the chapter numbers we can actually bypass the whole refcontext thingy and inject the chapter numbers directly.

\documentclass{scrbook}
\usepackage{blindtext}
\usepackage[backend=biber, refsection=chapter, defernumbers=true, style=numeric]{biblatex}

\usepackage{refcount}

\makeatletter \AtDataInput{% \blx@bbl@fieldedef{labelprefix}{\getrefnumber{refsection:\therefsection}}% \csuse\blx@bbl@data \iftoggle{blx@skipbib} {} {\ifundef\abx@field@shorthand {\blx@bbl@labelnumberwidth@numeric{}} {}}} \makeatother

\DeclareFieldFormat{labelprefix}{#1.}

\addbibresource{biblatex-examples.bib}

\begin{document} \chapter{Ch 1} \blindtext \cite{nussbaum} \cite{sigfridsson}

\chapter{Ch 2} \blindtext \cite{sigfridsson}

\printbibheading[title=Complete \bibname] \bibbysection[heading=none] \end{document}

Complete bibliography.

moewe
  • 175,683
  • Well i hoped for a solution with built-in mechanics of biblatex, but unfortunately that doesn't seem possible atm. Nevertheless, your answer ist much appreciated. – Venez Nov 01 '20 at 16:08