Skip to content

Instantly share code, notes, and snippets.

@ndgnuh
Created April 10, 2021 16:01
Show Gist options
  • Select an option

  • Save ndgnuh/80710c5362c2a345ca40ded685ee58c5 to your computer and use it in GitHub Desktop.

Select an option

Save ndgnuh/80710c5362c2a345ca40ded685ee58c5 to your computer and use it in GitHub Desktop.
Nice footnote cite
\ExecuteBiblatexOptions{citestyle=numeric-comp}
\makeatletter
\let\ffcitepre\empty
\let\ffcitepost\empty
\DeclareCiteCommand{\cite}[\mkbibbrackets]
{%
\usebibmacro{cite:init}%
\usebibmacro{prenote}%
}
{%
\usebibmacro{citeindex}%
\usebibmacro{cite:comp}%
\ifciteseen{}{%
\csnumgdef{cbx@instcount\thefield{entrykey}}{-100}%
}%
}
{}
{%
\usebibmacro{cite:dump}%
\usebibmacro{postnote}%
}
\DeclareCiteCommand{\@ffcite}[\cbx@ff]
{% % precode start
\usebibmacro{cite:init}%
%precode end
}
{% % loop code
\usebibmacro{citeindex}%
\gdef\cbx@citekey{\thefield{entrykey}}%
\ifciteseen
{}% if true, empty
{% % if false
% if cite for the first time
% the the fakecount to -100
% this will only run at first cite?
% \BibliographyWarning{\cbx@citekey is unseen, ignoring ffcite }%
\csnumgdef{cbx@instcount\cbx@citekey}{-100}%
}%
% end ifciteseen
% when meet a cite within the same page...
% compare two item defined by instcount and the fakecount
\ifsamepage%
{\value{instcount}} % first value
{\number\csuse{cbx@instcount\cbx@citekey}}% the value previously set
{}% do nothing if they are the same
{% write a footnote if not
\xappto{\cbx@citehook}{%
\noexpand\footnotetext[\thefield{labelnumber}]{%
\fullcite{\thefield{entrykey}}%
}%
}%
% \gdef\@makefnmark\old@makefnmark
}%
\csnumgdef{cbx@instcount\cbx@citekey}{\value{instcount}}%
% \usebibmacro{cite:comp}%
% end loop code
}
{}
{\usebibmacro{cite:dump}}
\newrobustcmd{\cbx@ff}[1]{%
\mkbibsuperscript{#1}%
\cbx@citehook%
\global\let\cbx@citehook=\empty%
}
\let\cbx@citehook=\empty
\newcommand{\ffcite}[1]{%
\let\old@makefnmark\@makefnmark%
\let\oldthefootnote\thefootnote
\renewcommand{\thefootnote}{[\arabic{footnote}]}
\renewcommand{\@makefnmark}{\makebox{\normalfont\@thefnmark}}%
\@ffcite{#1}%
\renewcommand{\thefootnote}{\oldthefootnote}
\renewcommand{\@makefnmark}{\old@makefnmark}%
}
\makeatother
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment