Custom citation keys

I am preparing a publication list in LaTeX in which I'd like to have custom keys to differentiate between paper types. For instance, if I originally I have:

• [1] journal publication 1
• [2] journal publication 2
• [3] conference publication 1
• [4] conference publication 2
• [5] workshop publication 1

I'd like to turn it into something like:

• [J1] journal publication 1
• [J2] journal publication 2
• [C3] conference publication 1
• [C4] conference publication 2
• [W5] workshop publication 1

Of course the same keys would appear in the reference list and in the text.

I could not find any easy way to do that with LaTeX/BibTeX. Do you have any suggestions?

-

migrated from stackoverflow.comJan 1 '12 at 15:20

This question came from our site for professional and enthusiast programmers.

bibtex or is biblatex an alternative? – Marco Daniel Jan 1 '12 at 15:33
I think it should be possible to do this with biblatex but I have to admit, I'd have to study the manual in more detail. Is there a specific reason why you want the special style for the labels? For example, biblatex lets you split your bibliography into bibliographies for books, for journal articles, and so on. – Marc van Dongen Jan 2 '12 at 5:17
Thanks ... the reason is that I would actually be able to split the bibliography in topics and then for each topic distinguish between journals, conferences and workshops. Of course, I could have subcategories but it looks less elegant in my opinion. – ebertini Jan 3 '12 at 23:14
This will be possible when using biblatex 2.x with biber. The functionality to define your own label templates is already implemented in biber and there will be a biblatex interface to this in 2.x – PLK Jan 7 '12 at 14:14

Here's a solution using biblatex. (There are possibly more elegant ways to define the new \typeprefix macro.)

\documentclass{article}

\usepackage{biblatex}

\newcommand*{\typeprefix}{%
\ifentrytype{article}{%
A%
}{%
\ifentrytype{book}{%
B%
}{%
O% "other"
}%
}%
}

\DeclareFieldFormat{labelnumber}{\typeprefix #1}

\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@article{A01,
author = {Author, A.},
year = {2001},
title = {Alpha},
journaltitle ={Journal Title},
}
@book{B02,
author = {Buthor, B.},
year = {2002},
title = {Bravo},
publisher = {Publisher},
location = {Location},
}
@misc{C03,
author = {Cuthor, C.},
year = {2003},
title = {Charlie},
}
\end{filecontents}

\begin{document}

Some text \autocite{A01,B02,C03}.

\printbibliography

\end{document}


-

Here is a way of doing something like this with biber 0.9.9 (beta)+biblatex1.7. In the future (biblatex 2.x), you will be able to define your own label templates so this will be easy but for now, you can use the biber config file sourcemap option to change your entries as biber reads them:

<?xml version="1.0" encoding="UTF-8"?>
<config>
<sourcemap>
<maps datatype="bibtex" map_overwrite="1">
<map>
<map_step map_field_set="LABEL" map_origentrytype="1"/>
<map_step map_field_source="LABEL" map_match="\A(.).+" map_replace="\u\$1"/>
</map>
</maps>
</sourcemap>
</config>


This will (assuming biblatex options style=alphabetic and labelalpha=true) make the alpha part of the label into the first letter of the entrytype. Playing with the match/replace will allow you a bit more control over the format, obviously. You can get the biber 0.9.9 (beta) from SourceForge (there is a small bug which prevents this example from working in 0.9.8).

-
It seems the OP wants a "type prefix" for numeric labels. – lockstep Jan 7 '12 at 16:54
Ah, my mistake. This is really only going to be properly possible when the label template interface is implemented in biblatex. It can actually be used now but you have to generate the .bcf and then put in a new XML section defining the label template before running biber - see sourceforge.net/apps/mediawiki/biblatex/… – PLK Jan 7 '12 at 16:58
I'm looking forward to biblatex 2.0, then! – lockstep Jan 7 '12 at 17:00