[Tex/LaTex] \citetitle and \citeeditor using the natbib & hyperref packages

hyperrefnatbib

I am very much committed to the natbib package, but still want to cite different fields of my bibliography items. For this I am using this code found in a google forum.

\begin{filecontents}{mytestbib.bib}
@book{author00,
title = {{A Title}},
publisher = {Alpha},
year = {2008},
editor = {Author, A},
address = {London}
}
@book{buthor00,
title = {{B Title}},
publisher = {Bravo},
year = {1990},
author = {Buthor, B},
address = {New York}
}
\end{filecontents}

\documentclass{article}
\usepackage{natbib}
\usepackage{hyperref}
\usepackage{keyval}

\input{https://groups.google.com/forum}% symbolically, for readability's sake 
\newbibfield{editor}
\bibinput{mytestbib}

\begin{document}
\usebibentry{author00}{editor} has edited `\usebibentry{author00}{title}'

\citeauthor{buthor00} has written `\usebibentry{buthor00}{title}'
\bibliographystyle{plainnat}
\bibliography{mytestbib}
\end{document}

This results in

enter image description here

and poses problems I cannot solve:

  1. I would like \usebibentry{author00}{editor} to result in 'Author', analog to \citeauthor{buthor00}
  2. Is it possible to have the \usebibentry{key}{field} also create a hyperlink, analog to \citeauthor?
  3. %% LaTeX2e file `mytestbib.bib' … is being put into the document and causes an error, can that be avoided?
  4. The bibitem 'author00' does not appear in 'References' (a minor problem, since also \cited regularly in my document)

Below is an amendment in response to egreg's answer

JabRef produces .bib files that look in principle the same as if produced by \begin{filecontents}, i.e.

% This file was created with JabRef 2.7.
% Encoding: Cp1252

@book{author00,
title = {{A Title}},
publisher = {Alpha},
year = {2008},
editor = {Author, A},
address = {London}
}
@book{buthor00,
title = {{B Title}},
publisher = {Bravo},
year = {1990},
author = {Buthor, B},
address = {New York}
}

My question regarding the hyperlink was imprecise, indeed. It should point at the entry in the 'References', which I now create as follows:

\newcommand{\editorlastname}[1]{\nocite{#1}%
  \begingroup\edef\x{\usebibentry{#1}{editor}}%
  \expandafter\endgroup\expandafter\removename\x\removename}
\def\removename#1,#2\removename{#1}

By the way, the \editorlastname works fine for me, but in case of multiple editors only the first editor is printed. (Should that be of importance to another user)

Best Answer

Use the filecontents* environment when you want to output a .bib file, so the initial commented lines are omitted. However this should not be a problem when you use the relatively new usebib package, which is derived from the comp.text.tex code you mention.

\begin{filecontents*}{\jobname.bib}
@book{author00,
title = {{A Title}},
publisher = {Alpha},
year = {2008},
editor = {Author, A},
address = {London}
}
@book{buthor00,
title = {{B Title}},
publisher = {Bravo},
year = {1990},
author = {Buthor, B},
address = {New York}
}
\end{filecontents*}

\documentclass{article}
\usepackage{natbib}
\usepackage{hyperref}
\usepackage{keyval}

\usepackage{usebib}
\newbibfield{editor}
\bibinput{\jobname}

\begin{document}
\usebibentry{author00}{editor} has edited `\usebibentry{author00}{title}'

\citeauthor{buthor00} has written `\usebibentry{buthor00}{title}'

\bibliographystyle{plainnat}
\bibliography{\jobname}
\end{document}

Note that I've used \jobname as the name of the .bib file, just not to clutter my (already overcluttered) directory of examples. Any name is just as good.

To get the last name, when the editor is stated in the .bib file in the form

lastname, firstname

you can say in your preamble

\newcommand{\editorlastname}[1]{%
  \begingroup\edef\x{\usebibentry{#1}{editor}}%
  \expandafter\endgroup\expandafter\removename\x\removename}
\def\removename#1,#2\removename{#1}

and then use \editorlastname{author00}. For hyperlinks one should know what to point at.