TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
    
Should be easy to realize. Do you need the package natbib anyway? – Herbert Jan 7 '11 at 9: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 7 '11 at 9:52
up vote 19 down vote accepted

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.)

share|improve this answer
    
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 7 '11 at 17:24
    
@Dror: I'm sorry I didn't bother to explain filecontents. – lockstep Jan 7 '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 7 '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

without natbib, don't know if it sjould 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}
share|improve this answer
    
Your changes affect the in-text-citation labels, but not the labels and the sorting order in the bibliography. – lockstep Jan 7 '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 ... – Herbert Jan 7 '11 at 12:53

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

share|improve this answer
    
has also an effect to the bibliography – Herbert Jan 7 '11 at 11:31
    
+1 for pointing me to sorting=debug. – lockstep Jan 7 '11 at 12:38

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 :=
}
share|improve this answer
    
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 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 at 15:45

The abstract bibtex style does so out of the box.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.