Improved superscript citations for BibLaTeX
Tags: typography, latex
libclang
: Counting …
— Next post: Surprises with name hiding in C++ »
I am big fan of Nature-style citations—they are rather unobtrusive and make using a citation as a noun impossible. For example the following sentence is fine:
Previously, Adams [42] showed the importance of always carrying a towel.
Now watch what happens when I try to use the citation in place of noun:
Previously, [42] showed the importance of always carrying a towel.
Looks stupid, doesn’t it? And indeed it should because using a citation key as a noun is rather bad form in my opinion. If you share my opinion and want to use this sort of citation style when using LaTeX, let me spare you some hours of “productive procrastination” (which is the time I should spent writing or doing research, but end up doing something else that is somewhat related to my thesis) and show you how I obtained beautiful Nature-style citations with BibLaTeX.
First, let’s load BibLaTeX with the required options:
\usepackage[%
autocite = superscript,
backend = bibtex,
sortcites = true,
style = numeric,
]{biblatex}
This tells BibLaTeX to use superscript citations by default when using
\autocite
. The numeric
style is required in order to ensure that
superscripts are typeset. In your LaTeX file, you may now use
Previously, Adams~\autocite{Adams42} showed the importance of always
carrying a towel.
The \autocite
command is my best friend when using BibLaTeX. Not only
can it be easily style by changing the setting in the preamble, it also
is smart in the sense that it detects surrounding punctuation correctly
and will place the actual citation properly, depending on your language
settings. This is great.
However, when we typeset the example above, we get something along the lines of:
Previously, Adams 42 showed the importance of always carrying a towel.
Close, but not cigar. I want brackets to surround the citation. Furthermore, if you use postnotes like me, they will not be shown. In other words, if you like to write
Previously, Adams~\autocite[\ppno~41--42]{Adams42} showed the importance
of always carrying a towel.
in order to add additional information about page numbers to your citation, you will be sorely disappointed. The additional information, which is the postnote in LaTeX jargon, simply will not show up. To fix this, we need to redefine the superscript citation of BibLaTeX:
\DeclareCiteCommand{\supercite}[\mkbibsuperscript]{
\iffieldundef{prenote}
{}
{\BibliographyWarning{Ignoring prenote argument}}%
\iffieldundef{postnote}
{}
{}
}
{\bibopenbracket%
\usebibmacro{citeindex}%
\usebibmacro{cite}%
\usebibmacro{postnote}%
\bibclosebracket}
{\supercitedelim}
{}
In case you wonder, this is the original code for \supercite
with some
modifications for the postnote. The placement of %
signs is
critical, by the way. Else, additional whitespace will be introduced to
the macro. If you use it like this, the citation should now look the
way we want it to look:
Previously, Adams [42, pp. 41–42] showed the importance of always carrying a towel.
And now we may marvel at our LaTeX documents and care about the less important stuff, such as—in my case—actually producing some content.
By the way, if you care about typography as much as I do, you may want to check out the illustrated glossary of typographic terms that the nice folks at Canva compiled for you.