4

For my work I'm using scrreprt and biblatex with the custom citation command from this answer. With the one-sided layout everything works fine but if I use twoside option then sometimes references in footnotes appear not on the same page as the footnote mark but move to the next page or further.

Here is an MWE which shows the problem:

\documentclass[b5paper,headinclude=true,DIV=12,toc=bibliographynumbered,
%twoside%<- uncomment this
]{scrreprt}
\usepackage{lipsum,hyperref}
\hypersetup{pdfborder={0 0 0},colorlinks=true,unicode}
\usepackage[style=chem-acs,sorting=none,citetracker,pagetracker,backend=biber]{biblatex}
\addbibresource{biblatex-chem.bib}

\makeatletter

% user-level citation command
\DeclareCiteCommand{\sfcite}[\cbx@superscript]
    {\usebibmacro{cite:init}%
        \let\multicitedelim\supercitedelim
        \iffieldundef{prenote}{}{\BibliographyWarning{Ignoring prenote}}%
        \iffieldundef{postnote}{}{\BibliographyWarning{Ignoring postnote}}}
    {\usebibmacro{citeindex}%
        \usebibmacro{cite:super:foot}%
        \usebibmacro{cite:comp}}
    {}
    {\usebibmacro{cite:dump}}

% initialize or save last instcount, save key if seen first on page
\newbibmacro*{cite:super:foot}{%
    \xdef\cbx@key{\thefield{entrykey}}%
    \ifciteseen{}{\csnumgdef{cbx@instcount@\cbx@key}{-100}}%
    \ifsamepage{\value{instcount}}{\csuse{cbx@instcount@\cbx@key}}
        {}{\listxadd{\cbx@savelist}{\cbx@key}}%
    \csnumgdef{cbx@instcount@\cbx@key}{\value{instcount}}}

% citation output
\newrobustcmd*{\cbx@superscript}[1]{%
    \global\toggletrue{cbx@sfcite}
    \mkbibsuperscript{#1}% Footnote's superscript in lining figures
    \cbx@footnote%
    \global\togglefalse{cbx@sfcite}}
\let\cbx@savelist\@empty
\newtoggle{cbx@sfcite}

\AtEveryCitekey{\iftoggle{cbx@sfcite}{}{\cbx@footnote}}

% prints footnotes if last reference on page
\newrobustcmd*{\cbx@footnote}{%
    \ifboolexpr{ test {\ifsamepage{\value{instcount}}{\value{instcount}+1}}
              or test {\ifdefempty{\cbx@savelist}} }
    {}
    {\cbx@sortlist@init%
    \let\do\cbx@do
    \dolistloop{\cbx@sortlist}%
    \global\let\cbx@savelist\@empty}}

% list handler that prints footnotes in order
\def\cbx@do#1{%
    \ifinlist{#1}{\cbx@savelist}
        {\begingroup
            \blx@getdata@cite{#1}%
            \blx@setoptions@type\abx@field@entrytype
            \blx@setoptions@entry
            \footnotetext[\thefield{labelnumber}]{%
            \blx@driver\abx@field@entrytype}%
        \endgroup}
        {}}

% internal list of sorted entry keys
\def\cbx@sortlist@init{%
    \ifcsundef{blx@sort@\the\c@refsection}
        {\global\letcs{\cbx@sortlist}
            {blx@slists@\the\c@refsection @entry@\blx@sorting}}% Biber
        {\global\letcs{\cbx@sortlist}{blx@sort@\the\c@refsection}}}% BibTeX
\let\cbx@sortlist\@empty

\makeatother
\begin{document}
\chapter{First Chapter}
\section{Section}
\subsection{Subsection}
\lipsum*[1]%
\sfcite{Arduengo1991,Booth1962,Augustine1995,Coghill2006}

\lipsum*[2]%
\sfcite{Danopoulos2008}

\lipsum*[3-5]%
\sfcite{Dehnicke1981,Smidt1959}

\lipsum*[5-6]%
\sfcite{Rees2000}

\lipsum*[1-2]

\printbibliography
\end{document}

If I uncomment twoside in the MWE and run pdflatex, biber, pdflatex then all footnote references appear in the right place but I need to run pdflatex one more time to get Bibliography in the Table of Contents of the pdf file. And after this run references 6 and 7 move to the next page.

The question is why it happens and how to fix this.

Ilya Makarov
  • 379
  • 3
  • 7

1 Answers1

6

Enable the page tracker with pagetracker=page. With two-sided documents pagetracker becomes pagetracker=spread. So \ifsamepage becomes an if "same spread"/"facing pages" test.

Audrey
  • 28,881