Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Is there a way to cite a title only with natbib?

2,674 views
Skip to first unread message

Michael

unread,
Oct 2, 2011, 12:21:39 PM10/2/11
to morr...@nhn.ou.edu
Hi,
I'm working on a (long) textbook in which I often need to cite (in text line) the title (only) of a book or paper. natbib gives me \citeyear and \citeauthor but no \citetitle. I've looked at all the CTAN packages I could find. Only bibentry.sty seems close, but it cites the entire bibliographic entry, not just the title. I could use \citealias, but I would have to define aliases (the titles only) for over 100 items. Moreover, this approach seems to defeat the purpose of BibTeX, which is that one does not have to type anything but the bibtex key in a citation. Does anyone know of a package that will cite just the title or of a way to hack natbib so it will do what I need? Many thanks in advance --- michael

Simon Spiegel

unread,
Oct 2, 2011, 1:18:26 PM10/2/11
to
Have a look at biblatex.

Simon

Michael

unread,
Oct 4, 2011, 3:18:30 AM10/4/11
to
> Have a look at biblatex.
>
> Simon

Thanks for the suggestion, Simon. I checked out biblatex.
Unfortauntely, I can't use it for this project because, according to
the documentation, it's incompatible with several CTAN packages the
publisher requires me to use.

Can anyone suggest another way to get LaTeX to cite only the title of
a work --- the analog to natbib's \citeauthor? Thanks.

Simon Spiegel

unread,
Oct 4, 2011, 3:33:22 AM10/4/11
to
On 2011-10-04 09:18:30 +0200, Michael said:

>>
>> Have a look at biblatex.
>>
>> Simon
>
> Thanks for the suggestion, Simon. I checked out biblatex.
> Unfortauntely, I can't use it for this project because, according to
> the documentation, it's incompatible with several CTAN packages the
> publisher requires me to use.

About all the packages which are listed as incompatible in chapter
1.5.4 provide functionality biblatex offers out of the box. Therefore
it doesn't make much sense to "insist" on those packages if you
actually want to use biblatex.

Simon

Michael

unread,
Oct 5, 2011, 1:21:14 AM10/5/11
to
I certainly agree with you! On the other hand, my publisher doesn't.
Is using biblatex my only option?

Enrico Gregorio

unread,
Oct 5, 2011, 3:52:21 PM10/5/11
to
I have some code that makes parts of a bib file reusable:

==== Code start ====
\usepackage{keyval}
\makeatletter

%%% Definition of keys
\define@key{reuse}{currentkind}{\def\@tempa{#1}}
\define@key{reuse}{currententry}{\def\reuse@current{#1}}
\def\define@reuse@key#1{\define@key{reuse}{#1}{%
\global\@namedef{reuse@\reuse@current @#1}{##1}}}
\define@reuse@key{title}
\define@reuse@key{isbn}
\define@reuse@key{url}
\define@reuse@key{year}
\define@reuse@key{note}

%%% The macro substituted to @book, @article, etc.
\def\reuse@find#1#{%
\lowercase{\setkeys{reuse}{currentkind=#1}}%
\ifcsname reuse@type@\@tempa\endcsname
\expandafter\@gobble
\else
\begingroup\makeatother
\expandafter\reuse@extract
\fi}

%%% the macro for extracting the fields
\def\reuse@extract#1{\setkeys{reuse}{currententry=#1}\endgroup}

%%% Ignore @preamble and @string
\let\reuse@type@preamble\@empty
\let\reuse@type@string\@empty

%%% Error management
\def\reuse@error#1#2{%
\PackageError{reuse}
{Undefined key `#1' or empty value for `#2'}
{The key you used is wrong or the value to `#2' has not been set}}

%%% The four user level macros
\newcommand\newbibfield[1]{\define@reuse@key{#1}}

\def\usebibentry#1#2{\@ifundefined{reuse@#1@#2}
{\reuse@error{#1}{#2}}
{\@nameuse{reuse@#1@#2}}}

\newcommand{\usebibentryurl}[2][|]{\@ifundefined{reuse@#2@url}
{\reuse@error{#2}{url}}
{\@usebibentryurl{#1}{#2}}}

\@ifpackageloaded{hyperref}{\@tempswatrue}{\@tempswafalse}
\if@tempswa
\def\@usebibentryurl#1#2{%
\scantokens{\url{\csname reuse@#2@url\endcsname}\endinput}}
\else
\def\@usebibentryurl#1#2{%
\toks@=\expandafter\expandafter\expandafter
{\csname reuse@#2@url\endcsname}%
\scantokens\expandafter{%
\expandafter\url\expandafter#1\the\toks@#1\endinput}}
\fi

\newcommand{\bibinput}[1]{%
\begingroup
\catcode`\%=12
\let\KV@err=\@gobble
\let\KV@errx=\@gobble
\let\XKV@err=\@gobble
\begingroup\lccode`\~=`\@
\lowercase{\endgroup\let~}\reuse@find
\catcode`\@=\active \input{#1.bib}\endgroup}

\makeatother
==== Code end ====

If hyperref is needed, the code must go after having loaded it.

You say in your preamble

\bibinput{bibliography}

where "bibliography.bib" is the bib file (you can load as many
as you wish with successive \bibinput commands).

Then the document command

\usebibentry{key}{title}

(where "key" is the bibliography key) will print the corresponding
title. Only "title", "isbn", "year" and "note" are predefined, but
you can say

\newbibfield{fieldname}

to enable using "fieldname" (say "pages", for instance).

To access URLs (if the "url" field is present in the entry)
you need

\usebibentryurl{key}

Ciao
Enrico

Michael

unread,
Oct 13, 2011, 3:45:05 AM10/13/11
to
On Oct 5, 2:52 pm, Enrico Gregorio <Facile.da.trov...@in.rete.it>
wrote:

First,many thanks for writing the bit of code that defines
\usebibentry. It have been implementing it and, basically, it works
wonderfully --- and is far (!) superior to having to use \citealias
for every relevant title.

In the course of working with it, I have noticed two properties that
have become a bit of a problem. I keep all my citations in various
*.bib files that are generated by a wonderful (free) data manager
called JabRef (http://jabref.sourceforge.net/index.php). Many of my
colleagues also use JabRef, so we can exchange *.bib files with the
assurance that all such files, whoever most recently originated or
modified them, can be used in JabRef. In the LaTeX file, I simply call
the *.bib files I need to use in my \bibliography{} statement. Now I
also call the files using your \bibinput{} statement. This works
splendidly.

The problems are the following. First, JabRef automatically puts a few
lines of internal documentation at the top of each *.bib file it
creates --- information like the date of latest revision and so forth.
Each of these lines begin with a %, so LaTeX ignores them. For some
reason, however, these lines appear in my LaTeX *.dvi output at
whatever place I insert a \bibinput{} statement. Moreover, LaTeX
won't let me put my \bibinput{} statements in the preamble; it issues
an error message to the effect that the \begin{document} statement is
missing. The reason, of course, it that for some reason it is ignoring
the % and treating lines that JabRef has "commented out" using % as
though they were actual input. That, of course, is also why they are
printed in my output.

Second, often JabRef produces BibTeX entries in a *.bib file that
contain blank lines. This typically happens in the abstract, but
sometimes it occurs elsewhere. Whenever \bibinput{} tries to load a
file, it gives an error message if that file contains a blank line
anywhere inside a BibTeX entry. Since such lines can appear anywhere,
the only way I can currently figure out to solve the problem is to go
through each *.bib file produced by JabRef by hand and remove the
blank lines (and, while I'm at it, I could remove the % documentation
lines at the front). The trouble with this approach is that (a) it's
extremely time consuming; and (b) I would have to do it every time I
modify any *.bib file via JabRef, because I can never tell whether or
not doing so will insert one or more blank lines somewhere, and in any
case JabRef will definitely insert its preliminary % documentation
lines at the start of each modified *.bib file.

The idea solution would be for that (a) treat lines that begin with %
as comment lines, so LaTeX will ignore tham, and (b) to ignore blank
lines. Do you have any ideas or suggestions?

Incidentally, this capability is so useful that I also wanted to
encourage you to consider making this code available to other users
through CTAN. I have several friends and a bunch of graduate students
who would love to have such a capability, and I've been hoping that
someone would just include it in an update of natbib.sty. It looks,
however, like that is not going to be done.

Thanks again for your help. --- Michael


Enrico Gregorio

unread,
Oct 13, 2011, 7:20:43 AM10/13/11
to
Michael <morr...@nhn.ou.edu> wrote:

> First,many thanks for writing the bit of code that defines
> \usebibentry. It have been implementing it and, basically, it works
> wonderfully --- and is far (!) superior to having to use \citealias
> for every relevant title.

It's memory intensive, though.

I really don't remember why I set % to have catcode 12; if you
don't use % in entries it should be safe to delete the line

\catcode`\%=12

In its place you can put

\catcode`\^^M=10

that will treat end-of-lines as spaces.

> Incidentally, this capability is so useful that I also wanted to
> encourage you to consider making this code available to other users
> through CTAN. I have several friends and a bunch of graduate students
> who would love to have such a capability, and I've been hoping that
> someone would just include it in an update of natbib.sty. It looks,
> however, like that is not going to be done.
>
> Thanks again for your help. --- Michael

I might make a package out of it, now that at least two people
use the macros.

Ciao
Enrico

Peter Flynn

unread,
Oct 13, 2011, 6:14:34 PM10/13/11
to
On 02/10/11 17:21, Michael wrote:
> Hi, I'm working on a (long) textbook in which I often need to cite
> (in text line) the title (only) of a book or paper. natbib gives me
> \citeyear and \citeauthor but no \citetitle. I've looked at all the
> CTAN packages I could find.

This is a standing defect in all BIBTeX packages I have seen (except
Jurabib). I think it is solved in biblatex.

///Peter

Michael

unread,
Oct 18, 2011, 3:29:20 AM10/18/11
to
On Oct 13, 6:20 am, Enrico Gregorio <Facile.da.trov...@in.rete.it>
wrote:
Hi Enrico,
Thanks very much for your suggestions! They solved the problems.
Incidentally, as a couple of other commentators have pointed out, this
problem is solved in biblatex. Using BibLaTeX at the moment may pose a
practical problem for many writers, as it does for me: many publishers
(well, at least the ones I deal with) don't accept LaTeX material that
is incompatible with the packages listed as incompatibilities in the
BibLaTeX documentation. So while using BibLaTeX is a fine alternative
for in-house documents and for publications whose publishers place no
restrictions on authors, it is not going to work for many people. (For
example, the American Physical Society is one of those publishers.) So
I do think preparing this as a package would be really useful to a lot
of people.
Cheers,
michael

Peter Flynn

unread,
Mar 19, 2012, 3:23:01 PM3/19/12
to
I'm delighted to be proved wrong: Enrico Gregorio just posted the usebib
package to CTAN which does exactly this (and lots more).

///Peter

Enrico Gregorio

unread,
Mar 20, 2012, 4:40:20 AM3/20/12
to
This was the promise. :) I got another request and so I published
the code as a package.

Ciao
Enrico
0 new messages