biblatex icon indicating copy to clipboard operation
biblatex copied to clipboard

biblatex defines two refsections if I print two bibliographies

Open eyalroz opened this issue 3 months ago • 1 comments

Woe is me, I maintain my alma mater's thesis document class and template: technion-iit-thesis.

In theses at the Technion, it is required to produce a list of publications of results covered by the thesis, which I achieve through the printing of a (mini-)bibliography, according to a suggestion on TeX.SX from a while back the code for which is listed below (cautioning in advance it's ugly code and I'm not very good with LaTeX). It uses a refsection command within a refcontext, and somewhere inside there's a \printbibliography. At the end of the thesis, the 'regular' bibliography is printed usign a plain \printbibliography command.

The problem I'm encountering is that, in the document .aux file, I get two labels with the same name:

\newlabel{refsection:1}{{}{5}{}{Doc-Start}{}}
\newlabel{refsection:1}{{}{}{}{Doc-Start}{}}

My complaint is one of two things: Either I should not be getting a second label with the same name (after all, it's a different refsection, right?), or alternatively, the documentation should tell me how I can suppress the generation of the label, or control the label name etc.

That is - unless I'm getting things totally wrong and I should be doing something else entirely.

PS - This started happening not a long time ago - somewhere between 3 years and a few months; I have not had to perform any maintenance work recently. Before that time, my code was essentially the same, and I would not get warnings about duplicate labels. I'm sorry I can't bibisect when this started occuring more precisely.


My code for the mini-bibliography:

\defbibenvironment{pubinfo}
{\list
   {}
   {\setlength{\leftmargin}{0in}%
    \setlength{\rightmargin}{0in}%
    \setlength{\itemindent}{-\leftmargin}%
    \setlength{\itemsep}{\bibitemsep}%
    \setlength{\parsep}{\bibparsep}}}
{\endlist}
{\item}

\AtEveryBibitem{
  % For front-page bibliography remove url and doi.
  \ifkeyword{pubinfo}{%
    \clearfield{url}%
    \clearfield{doi}%
  }{}%
}

\newcommand{\preparebutcheredbibliography}[1]{%
  % Set the keyword "pubinfo" for the references in the front page bibliography
  % https://tex.stackexchange.com/a/35779
  \DeclareSourcemap{
    \maps[datatype=bibtex, overwrite]{
      \map{
        % https://tex.stackexchange.com/a/516673/5109
        \step[fieldset=ABSTRACT, null]
        \step[fieldset=KEYWORDS, null]
      }
      \map{
        \perdatasource{#1}
        \step[fieldset=KEYWORDS, fieldvalue=pubinfo, append]
      }
    }
  }
}


\newsavebox{\butcheredbib@box}
\newcommand{\butcheredbibliography}[1]{
  %\makeatletter
  \ifdefined\butcheredbib@pubinfo
  \else
    \begin{lrbox}{\butcheredbib@box}%
      \begin{refcontext}[sorting=none]
        % See: https://tex.stackexchange.com/a/171153
        \begin{refsection}[#1]
          \nocite{*}

          \begingroup
            \def\bibfont{\footnotesize}
            \begin{minipage}{0.9\textwidth}
              \printbibliography[heading=none,env=pubinfo]
            \end{minipage}
          \endgroup%
        \end{refsection}
      \end{refcontext}
    \end{lrbox}%
  \fi
  \begin{center}
    \par
    \fbox{%
      \usebox\butcheredbib@box%
    }%
  \end{center}
  \global\def\butcheredbib@pubinfo{}
  %\makeatother
}

eyalroz avatar Nov 24 '25 21:11 eyalroz

Can you show us a short example document that reproduces the issue, please?

Based on your description, the files in the linked repository and the linked TeX.SX question I came up with

\documentclass{article}
\usepackage[utf8]{inputenc}

% Biblatex general settings
\RequirePackage[
  isbn=false,
  doi=false,
  url=true,
  maxbibnames=99, % Effectively ensure all authors are listed
  language=american, % ... English
  style=trad-alpha,
  maxalphanames=4 % Only use first 4 names for an initials key
  ]{biblatex}
\setcounter{biburllcpenalty}{7000}
\setcounter{biburlucpenalty}{8000}
\setcounter{biburlnumpenalty}{9000}
\AtEveryBibitem{
  % remove abstract from bibliographic entries
  \clearfield{abstract}%
  % do not show both eprint/doi and url
  \iffieldundef{eprint}{}{\clearfield{url}}%
}

\newcommand{\makebibliography}{%
  \ifdefined\pdfbookmark
    % If hyperref is loaded, this will help us to more
    % easily navigate to the bibliography
    % \pdfbookmark[0]{Bibliography}{bib}%
  \fi
  \printbibliography[heading=bibintoc]
}

\makeatletter
\defbibenvironment{pubinfo}
{\list
   {}
   {\setlength{\leftmargin}{0in}%
    \setlength{\rightmargin}{0in}%
    \setlength{\itemindent}{-\leftmargin}%
    \setlength{\itemsep}{\bibitemsep}%
    \setlength{\parsep}{\bibparsep}}}
{\endlist}
{\item}

\AtEveryBibitem{
  % For front-page bibliography remove url and doi.
  \ifkeyword{pubinfo}{%
    \clearfield{url}%
    \clearfield{doi}%
  }{}%
}

% \preparebutcheredbibliography - set up the front page bibliography
% arguments:
%  #1 - the bib file
\newcommand{\preparebutcheredbibliography}[1]{%
  % Set the keyword "pubinfo" for the references in the front page bibliography
  % https://tex.stackexchange.com/a/35779
  \DeclareSourcemap{
    \maps[datatype=bibtex, overwrite]{
      \map{
        % https://tex.stackexchange.com/a/516673/5109
        \step[fieldset=ABSTRACT, null]
        \step[fieldset=KEYWORDS, null]
      }
      \map{
        \perdatasource{#1}
        \step[fieldset=KEYWORDS, fieldvalue=pubinfo, append]
      }
    }
  }
}

% \butcheredbibliography - inserts an on-the-spot 'bibliography' -
% no title, no new section/chapter etc. - with no cite keys, smaller
% font and enclosed in a frame. Usable on the acknowledgement page
% of your thesis. This \nocite{}'s everything in the bib file, so
% have a bib file with just those entries you need for the butchered
% bibliography, or otherwise do your own \nocite{} 's to choose which
% entries from the file are used.
%
% arguments:
%  #1  the bibliography filename/s
%      (e.g. if your bib file is in a subdirectory)
%
\newsavebox{\butcheredbib@box}
\newcommand{\butcheredbibliography}[1]{
  %\makeatletter
  \ifdefined\butcheredbib@pubinfo
    % TODO assert the same #1 parameter is used
  \else
    \begin{lrbox}{\butcheredbib@box}%
      \begin{refcontext}[sorting=none]
        % See: https://tex.stackexchange.com/a/171153
        \begin{refsection}[#1]
          \nocite{*}

          \begingroup
            \def\bibfont{\footnotesize}
            \begin{minipage}{0.9\textwidth}
              \printbibliography[heading=none,env=pubinfo]
            \end{minipage}
          \endgroup%
        \end{refsection}
      \end{refcontext}
    \end{lrbox}%
  \fi
  \begin{center}
    \par
    \fbox{%
      \usebox\butcheredbib@box%
    }%
  \end{center}
  \global\def\butcheredbib@pubinfo{}
  %\makeatother
}
\makeatother


\begin{filecontents}{\jobname-primary.bib}
@BOOK{hectic,
  AUTHOR    = {Henry Hectic},
  TITLE     = {How Horticulturalists Howl},
  PUBLISHER = {Honorary Books: Henage},
  YEAR      = {2000}
}
\end{filecontents}
\begin{filecontents}{\jobname-secondary.bib}
@BOOK{flutter,
  AUTHOR    = {Frederick Flutter},
  TITLE     = {Fraternising with Flowers},
  PUBLISHER = {Frippery Pamphlets: Folkestone},
  YEAR      = {1995}
}
\end{filecontents}
\addbibresource{\jobname-primary.bib}
\addbibresource{\jobname-secondary.bib}

\preparebutcheredbibliography{\jobname-primary.bib}

\begin{document}
\butcheredbibliography{\jobname-primary.bib}

Some citations: \cite{hectic}, \cite{flutter}.
\makebibliography
\end{document}

which gives me the .aux file

\relax 
\abx@aux@refcontext{anyt/global//global/global/global}
\abx@aux@refcontext{none/global//global/global/global}
\abx@aux@refsection{1}{1}
\abx@aux@nociteall
\abx@aux@cite{0}{hectic}
\abx@aux@segm{0}{0}{hectic}
\abx@aux@cite{0}{flutter}
\abx@aux@segm{0}{0}{flutter}
\newlabel{refsection:1}{{}{1}{}{}{}}
\@writefile{toc}{\contentsline {section}{References}{1}{}\protected@file@percent }
\abx@aux@read@bbl@mdfivesum{B29E30FD7E864B7CF3595F1F6638C7B9}
\abx@aux@defaultrefcontext{0}{flutter}{anyt/global//global/global/global}
\abx@aux@defaultrefcontext{0}{hectic}{anyt/global//global/global/global}
\abx@aux@defaultrefcontext{1}{hectic}{none/global//global/global/global}
\gdef \@abspage@last{1}

with just a single \newlabel{refsection:1}.

moewew avatar Nov 26 '25 07:11 moewew