40

Is it possible to have several keys referring to the same bibliography entry (using biblatex+Biber)?

For example, I'd like \cite{Tolkien:1954:LordOfTheRings} and \cite{lotr} to have exactly the same effect when used in a document (and produce only a single bibliography entry, when both are used in the same document).

PLK
  • 22,776
Caramdir
  • 89,023
  • 26
  • 255
  • 291
  • 1
    Assuming that lotr is defined in your bibliography and you want to use Tolkien:1954:LordOfTheRings, try \makeatletter \expandafter\def\csname b@Tolkien:1954:LordOfTheRings\endcsname{\b@lotr} \makeatother in your document preamble? – Werner Dec 05 '11 at 22:54
  • @Werner: But wouldn't one have to use \cite{\csname b@Tolkien:1954:LordOfTheRings\endcsname} in the main text? – lockstep Dec 06 '11 at 00:06
  • @lockstep: AFAIK, \cite{<stuff>} checks for the existence of \b@<stuff> via a construction. So you should just be able to use \cite{Tolkien:1954:LordOfTheRings}. – Werner Dec 06 '11 at 00:10
  • @Werner: I'd love to see a MWE using this trick. :-) – lockstep Dec 06 '11 at 00:12
  • @lockstep: This trick, with some hiccups, worked with regular bibtex; not biblatex. biblatex defines things in a much more complicated way it seems. – Werner Dec 06 '11 at 07:28
  • Have you tried doing it with @crossref directly in the .bib-File? I uses this occasionally for fixing typos or convention issues in keys to stay backward compatible. I have not yet tried to use both keys within the same document, so it might be perfectly possible that you end up with two entries. – Daniel Dec 06 '11 at 09:53
  • @Daniel: The @crossref type doesn't exist; using the crossref field gives duplicate entries in the bibliography list if both keys are used in the same document. – Caramdir Dec 06 '11 at 19:09
  • @Caramdir: You are right of course, that is how I actually used it. – Daniel Dec 06 '11 at 20:07
  • 2
    I'm looking into this for biber 0.9.8. Probably something like this @BOOK{key1, IDS={key2,key3, ... keyn}, ...} where you can cite by either the main key or any of the secondary IDs. I need a little bit of biblatex support to deal with citations of the same entry via different keys as this can't be dealt with entirely in biber. – PLK Dec 07 '11 at 16:56
  • @PLK That would be the perfect solution. If you do implement this, please keep up us updated. – Caramdir Dec 08 '11 at 19:57

3 Answers3

35

With newer versions of biblatex (≥2.0) and biber (≥0.9.8) you can define your entries as normal and use the "IDS" field for extra citations keys:

@BOOK{key,
  IDS = {key2, key3, ..., keyn},
  .
  .
}

You can then cite by any of the keys, you can cite by any of them mixed in the same section and and you can use \nocite{*} too - it won't duplicate entries in the bibliography. In fact, the other keys are just aliases to the main key which owns the entry in the .bbl and are redirected to the main key before any label generation etc. happens.

It will also detect if you use a key as a primary key and also an alias elsewhere, in which case it will disable the alias. It also notices duplicate aliases as well as keys now.

Caramdir
  • 89,023
  • 26
  • 255
  • 291
PLK
  • 22,776
  • Great news -- the biblatex/biber combo keeps getting better and better! – lockstep Dec 08 '11 at 23:13
  • 3
    We have some pretty significant features coming. I wonder if it would be possible to have somewhere on here to announce and request comments and suggestions for them - Community wiki perhaps? The problem is that the new features are not so visible and so problems are often reported a long time after they were introduced when someone discovers the features in the biblatex Release file. – PLK Dec 09 '11 at 12:27
  • 2
    Is there some update about official support for this from the biblatex side? – Caramdir Mar 20 '12 at 17:04
  • Good question. I have an unofficial biblatex 1.7 patch for this but the biblatex maintainer seems to have disappeared temporarily for about six months and I don't know how to contact him. – PLK Mar 21 '12 at 07:58
  • Seems still to be an issue: I get Undefined control sequence \keyalias. So are any update on this by now? Still biblatex person not available? @PLK: can you say what slightly hacked means? I mean is there a patch to see the actual difference? The link to the biblatex.sty seems outdated. – math Oct 18 '13 at 08:22
  • This is fully supported now and has been for a while. it looks to me like you perhaps have an outdated version of biblatex? Or, you are not using biber as the backend, which this requires. – PLK Oct 18 '13 at 11:34
  • I have the same issue using a contemporary Ubuntu which seems to ship 1.7-1. Do you know what version is compatible? – Frederick Nord Mar 05 '14 at 21:30
  • 1.7 biber or biblatex? I think this was done a couple of years ago in biber 0.9.8 – PLK Mar 06 '14 at 14:05
  • Ubuntu ships biblatex-1.7-1, as per http://packages.ubuntu.com/search?keywords=biblatex – Frederick Nord Mar 11 '14 at 14:11
  • That's really old, however, I assume that if this is a TL installation, users can just run the TL updater to get the latest version. – PLK Mar 11 '14 at 15:47
  • Is this still valid today? Has it been integrated into the non-hacked version? – einpoklum Jun 27 '14 at 10:05
  • Just to be clear, this has been fully integrated into biber/biblatex for a couple of years now. – PLK Dec 15 '15 at 14:26
  • If I see it correctly, then the entries have to define their own alias keys rather than having another entry with the target key referencing the already existing entry. My scenario is that I have a bib file exported through Zotero. And I cannot manually patch that file each time I export. So having a second file defining the aliases would be great. – Frederick Nord Jun 05 '19 at 20:01
  • What you want here isn't possible and is such a niche requirement, I doubt it would be implemented. However, I imagine that you could do something with cloning sourcemaps and crossref/xdata. – PLK Jun 09 '19 at 13:07
14

The following, taken from "Alias for BiBTeX Keys" on comp.text.tex, provides \bibalias{<alias>}{<source>} and should use \acite{<citation>} instead of \cite{<citation>}:

enter image description here

\documentclass{article}
\usepackage{biblatex}% http://ctan.org/pkg/biblatex
\bibliography{references}

\makeatletter
% \bibalias{<alias>}{<source>} makes \cite{<alias>} equivalent to \cite{<source>}
\newcommand\bibalias[2]{%
  \@namedef{bibali@#1}{#2}%
}

\newtoks\biba@toks
\newcommand\acite[2][]{%
  \biba@toks{\cite#1}%
  \def\biba@comma{}%
  \def\biba@all{}%
  \@for\biba@one:=#2\do{%
    \@ifundefined{bibali@\biba@one}{%
      \edef\biba@all{\biba@all\biba@comma\biba@one}%
    }{%
      \PackageInfo{bibalias}{%
        Replacing citation `\biba@one' with `\@nameuse{bibali@\biba@one}'
      }%
      \edef\biba@all{\biba@all\biba@comma\@nameuse{bibali@\biba@one}}%
    }%
    \def\biba@comma{,}%
  }%
  \edef\biba@tmp{\the\biba@toks{\biba@all}}%
  \biba@tmp
}
\makeatother

\bibalias{Tolkien:1954:LordOfTheRings}{lotr}

\begin{document}
The reference~\acite{Tolkien:1954:LordOfTheRings} is
exactly the same as~\acite{lotr}.

\bibstyle{plain}
\printbibliography
\end{document}

where references.bib resembles:

@book{lotr,
  author  = "J.R.R. Tolkien",
  title   = "{The Lord of the Rings}",
  address = "New York",
  year    = 1954,
  publisher = "Ballantine Books"
}
Werner
  • 603,163
  • 2
    I've packed it up at http://absatzen.de/, but I don't remember why it's v0.2 anymore. (Also, it's quite possible that it will not work with more advanced syntactic forms of \cite. I think it'll accept anything that has a comma-separated list of labels as the first mandatory argument and pretty arbitrary stuff between the command and that argument.) – Ulrich Schwarz Dec 06 '11 at 07:41
  • This seems to work well. I would have preferred something that is completely transparent in the actual document (i.e. everything is defined in the .bib file), but that doesn't seem to be possible. – Caramdir Dec 06 '11 at 19:11
  • I'll accept this until biber/biblatex directly supports multiple keys. – Caramdir Dec 08 '11 at 19:58
1

Pure-bibtex answer:

Put this in the preamble and then use \bibalias{new key}{old, long, and cumbersome key}. It is the original LaTeX \cite macro, modified only by the two unindented "magic" lines.

% Bib aliases
\makeatletter
\def\@citex[#1]#2{\leavevmode
  \let\@citea\@empty
  \@cite{\@for\@citeb:=#2\do
    {\@citea\def\@citea{,\penalty\@m\ }%
\edef\magic##1{\let##1\expandafter\noexpand\csname bibalias@\@citeb\endcsname}%
\magic\tmp \ifx\tmp\relax\else \let\@citeb\tmp\fi
     \edef\@citeb{\expandafter\@firstofone\@citeb\@empty}%
     \if@filesw\immediate\write\@auxout{\string\citation{\@citeb}}\fi
     \@ifundefined{b@\@citeb}{\hbox{\reset@font\bfseries ?}%
       \G@refundefinedtrue
       \@latex@warning
         {Citation `\@citeb' on page \thepage \space undefined}}%
       {\@cite@ofmt{\csname b@\@citeb\endcsname}}}}{#1}}
\def\bibalias#1#2{\expandafter\def\csname bibalias@#1\endcsname{#2}}
\makeatother
  • 1
    Does this work together with biblatex? – moewe Feb 11 '16 at 16:54
  • It probably does (although tbh I don't know what a biblatex is). It works by tweaking the lowest level of LaTeX's \cite, so probably works with anything that does not touch that command; else, adapting it should be fairly trivial! – Circonflexe Feb 12 '16 at 14:53
  • I had the feeling that it probably wouldn't work with biblatex since that uses a new way to implement the \cite macros and indeed, it didn't work for me just now. (To be fair, I cannot say for sure that I dibn't do something wrong, I just copied the code, wrote a \bibalias and expected it to work with \cite.) Maybe you want to warn people that your solution will not work with biblatex out of the box (the question is specifically about biblatex). I assume the "trivial" modifications will lead to something like in Werner's answer? – moewe Feb 12 '16 at 16:58