2

How can I add the citation key to the bibliography?

Let's take this entry as an example:

@book{Fowler1999,
  address = {Boston, MA, USA},
  author = {Fowler, Martin},
  description = {AOEvolutionchapter short paper},
  isbn = {0-201-48567-2},
  publisher = {Addison-Wesley},
  title = {Refactoring: Improving the Design of Existing Code},
  year = 1999
}

I would now want the bibliography in my PDF document to look like this:

[Fowler1999] Martin Fowler. Refactoring: Improving the Design of Existing Code. Addison-Wesley, Boston, MA, USA, 1999. ISBN 0-201-48567-2.

Can someone please help me? I'm using natbib and bibliographystyle plainnat. And since it's the last day before deadline and I'm not that familiar with LaTeX, I'd prefer a solution where I don't need to change those two...

EDIT: apparently I did not express myself well. I don't want those keys in the text. There I already have them. I want them to appear in my bibliography as well.

Instead of:

Martin Fowler. Refactoring: Improving the Design of Existing Code. Addison-Wesley, Boston, MA, USA, 1999. ISBN 0-201-48567-2.

I want:

[Fowler1999] Martin Fowler. Refactoring: Improving the Design of Existing Code. Addison-Wesley, Boston, MA, USA, 1999. ISBN 0-201-48567-2.

Note that Fowler1999 is the citation key I used.

3
  • Are you using natbib? In this case you could use the authoryear option, assumed you have the keys like that in your bib-file.
    – Habi
    Nov 4, 2013 at 11:03
  • @Habi yeah, I'm using natbib. How do I enable this authoryear option?
    – keinabel
    Nov 4, 2013 at 11:05
  • Don't crosspost. Nov 4, 2013 at 21:08

1 Answer 1

4

If you use the authoryear and square options of natbib, the keys in your text show up as desired, if you use the \citep-command

\documentclass{article}

\usepackage{blindtext}
\usepackage[square,authoryear]{natbib}
\usepackage{filecontents}

\begin{filecontents}{library.bib}
@book{Fowler1999,
  address = {Boston, MA, USA},
  author = {Fowler, Martin},
  description = {AOEvolutionchapter short paper},
  isbn = {0-201-48567-2},
  publisher = {Addison-Wesley},
  title = {Refactoring: Improving the Design of Existing Code},
  year = 1999
}

@book{Doe2000,
  address = {Somewhere},
  author = {Doe, John},
  title = {Awesome title},
  year = 2000
}
\end{filecontents}

\setcitestyle{aysep={}}

\begin{document}
\blindtext\citep{Fowler1999}

\blindtext\cite{Doe2000}

\bibliography{library}
\bibliographystyle{unsrtnat}

\end{document}

Or you could use the alpha bibliography style.

\documentclass{article}

\usepackage{blindtext}
\usepackage{filecontents}

\begin{filecontents}{library.bib}
@book{Fowler1999,
  address = {Boston, MA, USA},
  author = {Fowler, Martin},
  description = {AOEvolutionchapter short paper},
  isbn = {0-201-48567-2},
  publisher = {Addison-Wesley},
  title = {Refactoring: Improving the Design of Existing Code},
  year = 1999
}

@book{Doe2000,
  address = {Somewhere},
  author = {Doe, John},
  title = {Awesome title},
  year = 2000
}
\end{filecontents}

\begin{document}
\blindtext\cite{Fowler1999}

\blindtext\cite{Doe2000}

\bibliography{library}
\bibliographystyle{alpha}

\end{document}
3
  • I guess I did not express myself well. I don't want those keys in the text. There I already have them. I want them to appear in my bibliography as well. Instead of Martin Fowler. Refactoring: Improving the Design of Existing Code. Addison-Wesley, Boston, MA, USA, 1999. ISBN 0-201-48567-2. I want [Fowler1999] Martin Fowler. Refactoring: Improving the Design of Existing Code. Addison-Wesley, Boston, MA, USA, 1999. ISBN 0-201-48567-2.
    – keinabel
    Nov 4, 2013 at 13:26
  • 1
    In this case you can use the 'alpha' style, as mentioned in the second example of my answer. If that does not suit you, you can generate a style for yourself, either with makebst or the graphical user-interface to it here: podoblaz.net/cml/?id=39
    – Habi
    Nov 4, 2013 at 15:40
  • Or take a look at this question/answer: tex.stackexchange.com/questions/10464 or this one: tex.stackexchange.com/questions/35306
    – Habi
    Nov 4, 2013 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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