24

I tried to use natbib and other attempts but for vain. I would like to produce a cite key which is identical to the BibTeX entry. For example, if I have a BibTeX entry Bt98, then I want \cite{Bt98} to produce something like [Bt98].

Any ideas how can I accomplish this?

lockstep
  • 250,273
Dror
  • 22,613
  • Should be easy to realize. Do you need the package natbib anyway? –  Jan 07 '11 at 09:43
  • @Herbert: At the moment I don't need natbib, I just tried to use it in order to produce the desired result. I'd be happy to do it without it. – Dror Jan 07 '11 at 09:52

5 Answers5

21

Here's a biblatex solution with a properly formatted bibliography.

\documentclass{article}

\usepackage[style=alphabetic,sorting=debug]{biblatex}

\DeclareFieldFormat{labelalpha}{\thefield{entrykey}}
\DeclareFieldFormat{extraalpha}{}

\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@misc{whatever,
  author = {Author, A.},
  year = {2001},
  title = {Testing the effects of biblatex styles on bibliography formatting},
}
@misc{B02f,
  author = {Buthor, B.},
  year = {2002},
  title = {First},
}
@misc{B02s,
  author = {Buthor, B.},
  year = {2002},
  title = {Second},
}
\end{filecontents}

\addbibresource{\jobname.bib}

\nocite{*}

\begin{document}

\printbibliography

\end{document}

enter image description here

(The filecontents environment is only used to include some external files directly into the example, so that it compiles. It is not necessary for the solution.)

lockstep
  • 250,273
  • Thanks a lot! This seems like the solution for my setting. One remark though, I was not familiar with the package filecontents, and it made your answer unclear at first sight. – Dror Jan 07 '11 at 17:24
  • @Dror: I'm sorry I didn't bother to explain filecontents. – lockstep Jan 07 '11 at 17:30
  • No worries! At first it made me insert a lengthy edit to my original question, but then somehow I figured it out. So now it seems OK. I have to admit, I thought the solution would be simpler. Some sort of predefined style. – Dror Jan 07 '11 at 17:45
  • If you're starting from bibtex, you still do this using biblatex by adding backend=bibtex in the arguments to \usepackage{biblatex}. If you're relying on natbib as well, the only way I could get the list of refs I needed was to take a copy of my source and strip all the natbib stuff, replacing it with biblatex as above. – Chris H Sep 18 '13 at 15:09
3

biblatex with, for example, the style=draft option will do this.

Thorsten
  • 12,872
PLK
  • 22,776
3

Without natbib, I don't know if it should be the same in the bibliography?

\documentclass{article}

\makeatletter \def@citex[#1]#2{\leavevmode \if@filesw\immediate\write@auxout{\string\citation{#2}}\fi @cite{#2}{#1}} \makeatother

\usepackage{filecontents}

\begin{filecontents}{\jobname.bib} @misc{whatever, author = {Author, A.}, year = {2001}, title = {Testing the effects of biblatex styles on bibliography formatting}, }

@misc{B02f, author = {Buthor, B.}, year = {2002}, title = {First}, }

@misc{B02s, author = {Buthor, B.}, year = {2002}, title = {Second}, } \end{filecontents}

\begin{document}

foo\cite{whatever} and bar\cite{B02s}

\bibliographystyle{alpha} \bibliography{\jobname}

\end{document}

  • Your changes affect the in-text-citation labels, but not the labels and the sorting order in the bibliography. – lockstep Jan 07 '11 at 12:30
  • 1
    @lockstop: I know, otherwise I hadn't ask if it should be ion the bib too ... ;-) And the question was to change \cite ... –  Jan 07 '11 at 12:53
2

If you are having trouble with natbib and biblatex (sometimes I have compilation issues with these packages), the following answer enables you to avoid those packages. Only three simple steps:

1) download this style: http://ftp.math.utah.edu/pub/tex/bibtex/alpha.bst

2) place it in your project's directory, preferentially under a different name (e.g. keystyle.bst).

3) in the file, replace the output.bibitem entry to:

FUNCTION {output.bibitem}
{ newline$
  "\bibitem[" write$
   cite$ write$
%  label write$
  "]{" write$
  cite$ write$
  "}" write$
  newline$
  ""
  before.all 'output.state :=
}
  • One should not use natbib and biblatex in one and the same document. Did you maybe mean to write BibTeX rather than biblatex? – Mico Jan 30 '16 at 15:22
  • I edited the answer to clarify that this is an alternative to use BibTeX key as the cite key, WITHOUT using the natbib and biblatex packages. Sorry for the confusion. – João Matos Jan 30 '16 at 15:45
1

The abstract bibtex style does so out of the box.

Dorian
  • 628