我非常致力于该natbib
软件包,但仍然想引用我的参考书目项目的不同领域。为此,我使用此代码在谷歌论坛上发现。
\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}
这导致
并提出了我无法解决的问题:
- 我希望
\usebibentry{author00}{editor}
得到“作者”,类似于\citeauthor{buthor00}
- 是否可以
\usebibentry{key}{field}
创建一个类似于的超链接\citeauthor
? - %% LaTeX2e 文件“mytestbib.bib”...被放入文档并导致错误,可以避免吗?
- bibitem 'author00' 没有出现在'参考文献'中(这是一个小问题,因为
\cite
我的文档中也经常出现)
以下是对 egreg 的回答的修正
JabRef 生成的 .bib 文件在原理上与 生成的文件相同\begin{filecontents}
,即
% 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}
}
我关于超链接的问题确实不准确。它应该指向“参考文献”中的条目,我现在按如下方式创建:
\newcommand{\editorlastname}[1]{\nocite{#1}%
\begingroup\edef\x{\usebibentry{#1}{editor}}%
\expandafter\endgroup\expandafter\removename\x\removename}
\def\removename#1,#2\removename{#1}
顺便说一句,\editorlastname
对我来说,这个功能很好用,但如果有多个编辑器,则只会打印第一个编辑器。(这对其他用户来说很重要吗)
答案1
filecontents*
当您想要输出文件时,请使用环境.bib
,因此初始注释行将被省略。但是,当您使用相对较新的usebib
包,它源自comp.text.tex
您提到的代码。
\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}
请注意,我使用 来\jobname
作为文件的名称.bib
,只是为了不让我的示例目录(已经很混乱了)变得混乱。任何名称都可以。
要获取姓氏,当编辑器在文件中.bib
以以下形式说明时
lastname, firstname
你可以在序言中说
\newcommand{\editorlastname}[1]{%
\begingroup\edef\x{\usebibentry{#1}{editor}}%
\expandafter\endgroup\expandafter\removename\x\removename}
\def\removename#1,#2\removename{#1}
然后使用\editorlastname{author00}
。对于超链接,应该知道指向什么。