17

I'm using BibLaTeX to handle my bibliography and I want a reference to be placed in a footnote on every page where I cite the same work and have the same number. Also I want to be able to cite the same work on one page several times. The latter could be done by using the code from the Joseph Wright's blog. However, it puts a reference in a footnote only once.

Ilya Makarov
  • 379
  • 3
  • 7
  • Do you mean that if you cite an article (say: John Smith (2008). 'An Aritlce' Some Journal 63: 1--20.) five times on one page, you will get five different footnotes at the bottom of the page all with the same number? Also: you need to say what citation 'style' you need to use (author-year, author-title, apa, Chicago, etc.)? Perhaps posting a mock document that shows how everything is supposed to look would help. – jon Sep 14 '12 at 14:55

1 Answers1

22

There are a number of TeX.SE posts on Joseph's citation style. One of them asks about limiting the \ifciteseen to the current page. The accepted solution takes an excessive number of LaTeX runs to compile and doesn't sort footnotes.

The new citation command \sfcite defined in the document below addresses these limitations. It also correctly handles labelnumber prefixes and shorthands.

\documentclass{article}
\usepackage[style=numeric-comp,sorting=none,citetracker,pagetracker=page]{biblatex}
\usepackage[colorlinks]{hyperref}

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

% save instcount, save key and last inline instcount if seen first on page \newbibmacro*{cite:super:foot}{% \xdef\cbx@key{\thefield{entrykey}}% \ifsamepage{\value{instcount}}{\csuse{cbx@instcount@\cbx@key}}{}{% \listxadd{\cbx@savelist}{\cbx@key}% \ifnumequal{\value{cbx@inst@lastonpage}}{0}{% \defcounter{cbx@inst@iter}{\value{instcount}}% \loop\ifnum\value{cbx@inst@iter}>0 \ifsamepage{\value{instcount}}{\value{cbx@inst@iter}} {\ifcsundef{blx@fnpage@\number\numexpr\value{cbx@inst@iter}} {\setcounter{cbx@inst@lastonpage}{\value{cbx@inst@iter}}}{}% \stepcounter{cbx@inst@iter}} {\setcounter{cbx@inst@iter}{0}}% \repeat}{}}% \csnumgdef{cbx@instcount@\cbx@key}{\value{instcount}}} \let\cbx@savelist@empty \newcounter{cbx@inst@iter} \newcounter{cbx@inst@lastonpage} \setcounter{cbx@inst@lastonpage}{0}

\newrobustcmd*{\cbx@superscript}[1]{% \global\toggletrue{cbx@sfcite} \mkbibsuperscript{#1}% \cbx@footnote% \global\togglefalse{cbx@sfcite}} \newtoggle{cbx@sfcite}

\AtEveryCitekey{% \ifciteseen{}{\csnumgdef{cbx@instcount@\thefield{entrykey}}{-1}}% \iftoggle{cbx@sfcite}{}{\cbx@footnote}} \AtEveryBibitem{\cbx@footnote} \AtEveryLositem{\cbx@footnote}

% defer citation footnotes to last inline reference instance on page \newrobustcmd*{\cbx@footnote}{% \ifboolexpr{ not test {\ifdefempty{\cbx@savelist}} and test {\ifnumequal{\value{instcount}}{\value{cbx@inst@lastonpage}}} } {\cbx@sortlist@init% \let\do\cbx@do \dolistloop{\cbx@sortlist}% \global\let\cbx@savelist@empty \setcounter{cbx@inst@lastonpage}{0}}{}}

% print footnotes in 'sorting' order \def\cbx@do#1{% \ifinlist{#1}{\cbx@savelist} {\begingroup \blx@resetdata \blx@getrefcontext{#1}% \blx@getdata@cite{#1}% \blx@setoptions@type\abx@field@entrytype \blx@setoptions@entry \blx@execute \blx@beglang \iffieldundef{shorthand} {\gdef@thefnmark{\printfield{labelprefix}\printfield{labelnumber}}} {\gdef@thefnmark{\printfield{shorthand}}}% \gappto@thefnmark{\blx@initunit}% \ifhyperref {\H@@footnotetext{\blx@driver\abx@field@entrytype}} {@footnotetext{\blx@driver\abx@field@entrytype}}% \blx@endlang \endgroup} {}}

% access internal list of sorted entry keys \def\cbx@sortlist@init{% \global\letcs{\cbx@sortlist} {blx@dlist@entry@\the\c@refsection @\blx@refcontext@context}} \let\cbx@sortlist@empty \makeatother

\addbibresource{biblatex-examples.bib} \renewcommand*{\thefootnote}{\fnsymbol{footnote}} \begin{document} \null\vfill\noindent New citation.\sfcite{companion} New and recurrent citations.\sfcite{kant:ku,companion} Vanilla footnote with citation.\footnote{Following \textcite{companion}...} \clearpage \null\vfill\noindent New citation.\sfcite{ctan} Recurrent citations from previous and current pages.\sfcite{companion,ctan} \clearpage \printbibliography \end{document}

Here are the citations from the first page:

"New citation.1 New and recurrent citations.1,KU Vanilla footnote with citation.∗" with one footnote entry for each citation label

And the second:

"New citation.2 Recurrent citations from previous and current pages.1,2" again one entry for each label

Printing of citation footnotes is deferred to the last inline citation, list of shorthands entry or bibliography item on the current page. This might pose a limitation if the document also contains regular footnotes, but can likely be resolved by using a package like manyfoot.

moewe
  • 175,683
Audrey
  • 28,881
  • I couldn't find that post... Thank you very much! This works perfectly. – Ilya Makarov Sep 14 '12 at 18:46
  • @Audrey Thank you for that solution. Apart from the limitation regarding footnotes you've already mentioned, I've just found another nasty little bug: if the page counter is reset (i.e. to allow for an Appendix with another numbering style), the footnotes are printed on the last pages in the document corresponding to the page number they were on. In the end, that leads to footnotes for the page 1 to be printed on appendix page 1 and so forth. Do you have any idea on how to fix this? – Big-Blue Nov 24 '13 at 20:21
  • @Big-Blue No idea because I can't reproduce your issue. Make another post with an example to get help. – Audrey Nov 25 '13 at 00:32
  • 2
    @Big-Blue Editing your duplicate post won't bump it to the front page. The "bug" is due to the fact that you're recycling page identifiers, which mucks up page tracking. Instead of \pagenumbering redefine \thepage. For example add \newcounter{lastpage} and \preto{\appendix}{\setcounter{lastpage}{\value{page}}\clearpage\renewcommand{\thepage}{\RN{\numexpr\value{page}-\value{lastpage}}}} to your preamble and use \appendix in the document body. – Audrey Nov 26 '13 at 02:06
  • 1
    Forgot hyperref will want \thepage to be expandable. For lowercase roman appendix page numbers use \renewcommand{\thepage}{\romannumeral\numexpr\value{page}-\value{lastpage}}. For uppercase \makeatletter\renewcommand{\thepage}{\expandafter\@slowromancap\romannumeral\numexpr\value{page}-\value{lastpage}@}}\makeatother. – Audrey Nov 26 '13 at 22:08
  • This is really helpful thanks. It works perfectly for me. However, it's beyond my current level in LaTeX and I'm wondering if you could show me how to modify this code to suppress the URL in the footenotes but keep it in the bibliography page and how to have backref working in the bibliography but not show up in the footnotes - if either of these things is possible.

    %\AtEveryCitekey{\clearfield{url}} doesn't seem to work

    – Daniel May 12 '15 at 18:32
  • 1
    @Daniel After the line \blx@setoptions@entry insert \csuse{blx@hook@citekey}% and use the hook \AtEveryCitekey{\clearfield{url}\clearfield{urlyear}\clearlist{pageref}}. I haven't tested this, so if you run into trouble ask a new question. – Audrey May 14 '15 at 18:30
  • If you want to make the citation appear when it was cited, just comment this line and test {\ifnumequal{\value{instcount}}{\value{cbx@tempcntd}} (check the closing brackets) – Arturo Volpe Jun 11 '15 at 02:32
  • 1
    Could this piece of code be transformed into a new biblatex option? – pluton Dec 19 '15 at 18:33