TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Biblatex is loaded as

\usepackage[style=numeric-comp,hyperref=true]{biblatex}
\ExecuteBibliographyOptions{citetracker=true,sorting=none,firstinits=true}

I am looking for an if-command, which would do the same job as \ifciteseen does, but only for the current page.

The idea is to test if some source has been cited already on the current page and, depending on the result, change the citation. For instance, if I want to produce a footnote only upon the first citation on the current page, I could do

\ifciteseenONTHISPAGE
{% yes, do nothing
 }
{% no, do smth
 \noexpand\footnote[\thefield{labelnumber}]{%
 \fullcite{\thefield{entrykey}}\addperiod}}}}

I am aware of \iffirstonpage and \ifsamepage but cannot figure out if they can be of any help here and how.

share|improve this question
up vote 14 down vote accepted

The counter instcount uniquely identifies a citation or item in the bibliography/list of shorthands. The test \ifsamepage{<inst1>}{<inst2>}{<true>}{<false>} expands <true> if the two citations/items identified by the instcount values <inst1> and <inst2> are found on the same page.

In your test we need to compare the current value (\value{instcount}) with the value of instcount the last time the current entry was cited. In general this is not the value of instcount in the last citation (i.e. \value{instcount}-1). AFAIK you'll have to track the last instcount value for each entry with some additional code.

The example below demonstrates how this can be done using a citation format considered in a previous post. It relies on some commands from etoolbox and requires additional passes to get the tests right.

\documentclass{report}
\usepackage[american]{babel}
\usepackage{csquotes}
\usepackage[colorlinks]{hyperref}
\usepackage[style=numeric-comp,citetracker=true,pagetracker=true,sorting=none]{biblatex}

\makeatletter
%---------------------------------------------------------------
% Essentially verbatim from Joseph Wright (except for refinements to \ifciteseen test)
% http://www.texdev.net/2010/03/08/biblatex-numbered-citations-as-footnotes/

\DeclareCiteCommand{\superfootcite}[\cbx@superscript]
  {\usebibmacro{cite:init}%
   \let\multicitedelim=\supercitedelim
   \iffieldundef{prenote}
     {}
     {\BibliographyWarning{Ignoring prenote argument}}%
   \iffieldundef{postnote}
     {}
     {\BibliographyWarning{Ignoring postnote argument}}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite:superfoot}%
   \usebibmacro{cite:comp}}
  {}
  {\usebibmacro{cite:dump}}

\newbibmacro*{cite:superfoot}{%
  \xdef\cbx@citekey{\thefield{entrykey}}%
  \ifciteseen
    {}
    {\csnumgdef{cbx@instcount\cbx@citekey}{-100}}%
  \ifsamepage{\value{instcount}}{\number\csuse{cbx@instcount\cbx@citekey}}
    {}
    {\xappto\cbx@citehook{%
       \noexpand\footnotetext[\thefield{labelnumber}]{%
         \fullcite{\thefield{entrykey}}\addperiod}}}%
  \csnumgdef{cbx@instcount\cbx@citekey}{\value{instcount}}}

\newrobustcmd{\cbx@superscript}[1]{%
  \mkbibsuperscript{#1}%
  \cbx@citehook
  \global\let\cbx@citehook=\empty}
\let\cbx@citehook=\empty

%---------------------------------------------------------------
\makeatother

\addbibresource{biblatex-examples.bib}

\begin{document}
\chapter{Title}
\null\vfill\noindent
First citation.\superfootcite{bertram}
First citation.\superfootcite{companion}
Some recurrent citations on same page.\superfootcite{bertram,companion,augustine}
\chapter{Title}
\null\vfill\noindent
Recurrent citation on different page.\superfootcite{companion}
Recurrent on different page and first citations.\superfootcite{augustine,cicero}
Recurrent citation on same page.\superfootcite{companion}
\printbibliography
\end{document}

Here are the citations from the first page:

enter image description here

And from the second:

enter image description here

share|improve this answer
    
Great, thanks! I've combined the code above with some other code of yours (and Joseph, of course) tex.stackexchange.com/questions/20787/… and some cosmetic changes from my side to achieve exactly what I needed. I see a lot of questions connected to footnote citation style. Do you consider writing a package, which would incorporate different modifications of it and would allow switching between different styles in a flexible way? – amorua Nov 23 '11 at 8:04
    
@amorua Perhaps eventually, unless Joseph prefers to write one himself or someone else beats me to it. Ideally I'd like to see some adaptation of code from manyfoot, but I don't have time to look into that right now. – Audrey Nov 23 '11 at 14:28
    
Your solution worked perfectly for me. I have one question though. Do you think it is possible to have the footnotes with cites sorted? To explain what I mean, let's look at your example: imagine on page 2 you would first cite Augustine [3] and only then Goosens [2]. Then the footnotes would be in the following order: [3], then [2] and then [4]. Is it possible to have them sorted: although the citation order is 3,2,4, the footnotes would first list 2, then 3 and 4? If you think it is something that can be done, I would like to post a new question. – amorua Nov 23 '11 at 19:38
    
@amorua I finally got around to solving this problem over here. It is suited mainly for documents where the list of shorthands and bibliography appear on new pages, though. – Audrey Sep 14 '12 at 17:53

This is a slightly more "readable" version of Audrey's approach above

\AtDataInput{%
  \csnumgdef{cbx@instcount@curr@\thefield{entrykey}}{0}}
\AtEveryCitekey{%
  \csnumgdef{cbx@instcount@last@\thefield{entrykey}}{%
    \csuse{cbx@instcount@curr@\thefield{entrykey}}}%
  \csnumgdef{cbx@instcount@curr@\thefield{entrykey}}{\value{instcount}}}

\def\iflastciteonsamepage{%
  \ifsamepage
    {\number\csuse{cbx@instcount@curr@\thefield{entrykey}}}
    {\number\csuse{cbx@instcount@last@\thefield{entrykey}}}}

Where \iflastciteonsamepage checks if the last citation of the current work was on the same page (as detected by \ifsamepage).

Please be aware that this test is not guaranteed to work in all circumstances, I have tested it for some (relatively common) cases, but there might well be cases where this breaks down horribly. Thanks to Audrey to pointing this out in the comments.

Audrey's MWE then becomes

\documentclass{report}
\usepackage[american]{babel}
\usepackage{csquotes}
\usepackage[colorlinks]{hyperref}
\usepackage[style=numeric-comp,citetracker=true,pagetracker=true,sorting=none]{biblatex}

\makeatletter
%---------------------------------------------------------------
% Essentially verbatim from Joseph Wright (except for refinements to \ifciteseen test)
% http://www.texdev.net/2010/03/08/biblatex-numbered-citations-as-footnotes/

\DeclareCiteCommand{\superfootcite}[\cbx@superscript]
  {\usebibmacro{cite:init}%
   \let\multicitedelim=\supercitedelim
   \iffieldundef{prenote}
     {}
     {\BibliographyWarning{Ignoring prenote argument}}%
   \iffieldundef{postnote}
     {}
     {\BibliographyWarning{Ignoring postnote argument}}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite:superfoot}%
   \usebibmacro{cite:comp}}
  {}
  {\usebibmacro{cite:dump}}

\AtDataInput{%
  \csnumgdef{cbx@instcount@curr@\thefield{entrykey}}{0}}
\AtEveryCitekey{%
  \csnumgdef{cbx@instcount@last@\thefield{entrykey}}{%
    \csuse{cbx@instcount@curr@\thefield{entrykey}}}%
  \csnumgdef{cbx@instcount@curr@\thefield{entrykey}}{\value{instcount}}}

\def\iflastciteonsamepage{%
  \ifsamepage
    {\number\csuse{cbx@instcount@curr@\thefield{entrykey}}}
    {\number\csuse{cbx@instcount@last@\thefield{entrykey}}}}

\newbibmacro*{cite:superfoot}{% 
  \iflastciteonsamepage   
    {}
    {\xappto\cbx@citehook{%
       \noexpand\footnotetext[\thefield{labelnumber}]{%
         \fullcite{\thefield{entrykey}}\addperiod}}}}

\newrobustcmd{\cbx@superscript}[1]{%
  \mkbibsuperscript{#1}%
  \cbx@citehook
  \global\let\cbx@citehook=\empty}
\let\cbx@citehook=\empty
%---------------------------------------------------------------
\makeatother

\addbibresource{biblatex-examples.bib}

\begin{document}
\chapter{Title}
\null\vfill\noindent
First citation.\superfootcite{bertram}
First citation.\superfootcite{companion}
Some recurrent citations on same page.\superfootcite{bertram,companion,augustine}
\chapter{Title}
\null\vfill\noindent
Recurrent citation on different page.\superfootcite{companion}
Recurrent on different page and first citations.\superfootcite{augustine,cicero}
Recurrent citation on same page.\superfootcite{companion}
\printbibliography
\end{document}

For the first page

first page of MWE

and for the second page

second page of MWE


Here is a solution that addresses some of the concerns raised in the comments

\AtEveryCitekey{%
  \ifcsundef{cbx@instcount@curr@\the\c@refsection @\thefield{entrykey}}
    {\csnumgdef{cbx@instcount@curr@\the\c@refsection @\thefield{entrykey}}{0}}
    {}%
  \csnumgdef{cbx@instcount@last@\the\c@refsection @\thefield{entrykey}}{%
    \csuse{cbx@instcount@curr@\the\c@refsection @\thefield{entrykey}}}%
  \csnumgdef{cbx@instcount@curr@\the\c@refsection @\thefield{entrykey}}{\value{instcount}}}

\def\iflastciteonsamepage{%
  \ifsamepage
    {\number\csuse{cbx@instcount@curr@\the\c@refsection @\thefield{entrykey}}}
    {\number\csuse{cbx@instcount@last@\the\c@refsection @\thefield{entrykey}}}}

While this version is more robust in some aspects, it is still not guaranteed to work in all circumstances.

share|improve this answer
    
I didn't intend this test to be user-level. It is specific to the special 1:1 correspondence between a single citation and a footnote in the OP's desired style. There are likely unanticipated results with initializing in \AtDataInput. I suspect this won't work with numeric styles under reference sections or multiple sorting schemes. – Audrey Oct 30 '15 at 2:59
    
@Audrey Ah, thanks, I didn't think of that. Is there another hook one could use? Of course I could just move the initialisation into the \AtEveryCitekey with an \ifciteseen, I presume ... – moewe Oct 30 '15 at 5:24
    
@Audrey Thank you again for your comment. Would you mind having a look at my second suggestion that seems to play well with refsections at least? – moewe Oct 30 '15 at 15:10
    
This might work is some settings, but I know the strategy isn't good enough as a general test. That is why I embedded the test into the OP's citation style and didn't make the it directly accessible. – Audrey Oct 31 '15 at 2:50
    
@Audrey OK, thank you very much again. I will add a more prominent warning then. If you happen to stumble across a case where this doesn't work or have any further explanations as to what could go wrong, I would be really interested. – moewe Oct 31 '15 at 5:57

You should try (with pagetracker activated) something like this (works by me when I use it in my custom style) :

\ifciteseen{%
    \ifsamepage{\value{instcount}}{\value{instcount}-1}{Do nothing}
    {Print the reference}}
share|improve this answer
    
Unfortunately, this does not do the trick. Actually, if I have something like \cite{a1} text \cite{a2} text \cite{a3} on the same page, then the conditional above will give false only for a1 and true for a2 and a3. Whereas a2 and a3 are certainly "new citations". Is there any counter "for a given citation key", just like instcount is for all citations? – amorua Nov 22 '11 at 21:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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