5

I want to number and prefix my references in each section by the number of the section. However, I need to cite a reference from a section in another subsection, but my solution does not allow it. Indeed, the code:

\documentclass{article}

\pagestyle{empty}

\usepackage{filecontents}

\begin{filecontents*}{test.bib}

@article{A1,
  keywords = {articles},
  title={First Paper},
  author={Green},
  journal={Journal 1}, 
  note={based on \cite{C2}},
  year={2014}
}

@article{A2,
  keywords = {articles},
  title={Second paper},
  author={Smith},
  journal={Journal 2}, 
  year={2013}
}

@article{C1,
  keywords = {conferences},
  title={First Communication},
  author={Jack},
  journal={Conference 1}, 
  year={2012}
}

@article{C2,
  keywords = {conferences},
  title={Second Communication},
  author={John},
    journal={Conference 2}, 
  year={2011}
}
\end{filecontents*}

\usepackage[
  backend=biber,
  defernumbers=true,
  citestyle=numeric,
  refsection=section 
]{biblatex}

\DeclareFieldFormat{labelnumber}{\mkbibsecnum{#1}}
\newrobustcmd{\mkbibsecnum}[1]{\thesection-#1\relax}

\addbibresource{test.bib}
\begin{document}
\section{Articles}
\nocite{*}
\printbibliography[
  title={Articles},
  heading=none,
  keyword=articles,
  resetnumbers=true 
]

\section{Conferences}
\nocite{*}
\printbibliography[
  title={Conferences},
  heading=none,
  keyword=conferences,
  resetnumbers=true 
]

\end{document}

produces (I use bold case where the problem is):

1 Articles

[1-1] Green. “First Paper”. In: Journal 1 (2014). based on [1-4]

[1-2] Smith. “Second paper”. In: Journal 2 (2013).

2 Conferences

[2-1] Jack. “First Communication”. In: Conference 1 (2012).

[2-2] John. “Second Communication”. In: Conference 2 (2011).

while I would like that the first line be :

[1-1] Green. “First Paper”. In: Journal 1 (2014). based on [2-2].

Any help is welcome.

  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – cfr Oct 8 '14 at 1:44
  • 2
    Note that biblatex is doing exactly what you have told it to do. You have added 4 references to section 1. You have chosen only to print those which contain the keyword articles. But there are still 4 references in this section and I take it that's what the 1-4 refers to. You cannot refer here to items in another reference section since the whole point of such sections is that the items are local. (Cf. refsegment which works differently.) I think you might be better served using a bibfilter but I am not sure how you could get the numbering you want. – cfr Oct 8 '14 at 1:48
  • 3
    If you know in advance the number of the sections, you can use refsegment=section as the option of biblatex and then in the option of the \printbibliography use prefixnumbers=X and prefixnumbers=Y are the numbers of the Articles and Conferences sections. – Guido Oct 8 '14 at 2:29
  • I agree that biblatex is doing what I told it to do. Thanks anyway for a quick comment. – Jacques Levy Vehel Oct 8 '14 at 6:41
4

Here is an hack using latex crossref mechanism to define the labels of the bibliographic references.

The trick is to redefine how the bibliography is handled (using the facilities provided by biblatex). To redefine it we use enumitem that allows us to specify how the labels and the references are formatted. We also have to redefine \cite accordingly.

\usepackage{enumitem}
\usepackage[
  backend=biber,
  defernumbers=true,
  citestyle=numeric,
  refsegment=section 
]{biblatex}

\DeclareCiteCommand{\cite}
  [\mkbibbrackets]
  {}
  {\ref{\thefield{entrykey}}}
  {\addcomma}
  {\iffieldundef{postnote}{}{\addcomma\addspace\printfield{postnote}}}

\defbibenvironment{bibliography}
  {\begin{enumerate}[label={[\thesection-\arabic*]},ref=\thesection-\arabic*]}
  {\end{enumerate}}
  {\item\label{\thefield{entrykey}}}

\addbibresource{test.bib}

\begin{document}
\section{Articles}\label{sec:article}
\nocite{*}
\printbibliography[
  title={Articles},
  heading=none,
  keyword=articles,
  resetnumbers=true,
]

\section{Conferences}\label{sec:conf}
\nocite{*}
\printbibliography[
  title={Conferences},
  heading=none,
  keyword=conferences,
  resetnumbers=true,
]

\end{document}

enter image description here

  • Thanks a lot for a very quick answer. This works perfectly. – Jacques Levy Vehel Oct 8 '14 at 6:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.