Bibliography mkii

From Wiki
Revision as of 14:55, 25 April 2007 by Sanjoy (talk | contribs) (active hyperlinks section)
Jump to navigation Jump to search

< Modules | User:Taco/Bib >

The bib module provides the \cite and \placepublications commands, in addition to some setup commands, for collecting and referencing bibliography. Single references can be supplied by special commands, or by using BibTeX databases.

As of Context 2005.01.13, this module is part of the standard distribution. The current version is also on the modules:bib page (Hans picks up the zip from that location as well, so the current version will always be in the modules part of the ConTeXt distribution).

The PDF manual can be found on the bib module page or in your ConTeXt installation. For me (ConTeXt installed in my home directory), it's in ~/texmf/doc/context/bib/bibmod-doc.pdf

Example of use with bibtex

Bibtex support is not integrated in texexec (yet), so you have to run bibtex by hand.

Assuming you have saved this bit of code as bibdemo.tex:

As \cite[article-full] already indicated, bibtex is a \LaTeX-centric program.

Then you have to run the following three commands:

texexec --once bibdemo
bibtex bibdemo
texexec bibdemo

To get the typeset result. xampl.bib comes with the bibtex distribution, it should be on your harddisk somewhere already. On my teTeX 3.0 system, /usr/share/texmf-tetex/bibtex/bib/base/xampl.bib is the location.

The \usemodule[bibltx] line is needed because xampl.bib uses LaTeX commands and defines them using LaTeX syntax. The bibltx module allows ConTeXt to understand some such constructions (which is enough for it to work with xampl.bib). Newer versions of ConTeXt don't include t-bibltx.tex. However, on the mailing list Taco said he'd restore it in due course. Meanwhile here is the previous version, which you can put in the tex/context/bib/ directory of your ConTeXt installation.

Changing the way you show the publication list

If you use bibtex and you want to change the way you show the publication list you might want to look at the following example, it will change the publication list showing the surname in uppercase.

(Credits go to Taco Hoekwater)

%D Copied from \invertedshortauthor, with an extra \uppercase
%D \type{#1} = firstnames
%D \type{#2} = von
%D \type{#3} = surname
%D \type{#4} = inits
%D \type{#5} = junior


After that, you can do:


Active URLs

If you want active (clickable) URLs in the references, you need to do a few steps. [Thanks to Tobias Burnus for the working minimal example, which I've modified only slightly.]

  • Use a patched t-bib.tex (until the next ConTeXt release sometime in May 2007 that will contain the patch).
  • Use the url field in the bibtex entries.
  • Setup a publication layout (for those types of bibtex entries) that knows how to include a URL.

The minimal example is in, which includes the patched t-bib.tex. But here are the details of steps 2 and 3. A bibtex book entry using the url field looks like:

  editor =	 {John D. Barnsford and Ann L. Brown and Rodney R. Cocking},
  title = 	 {{How people learn: Brain, mind, experience, and school}},
  publisher = 	 {National Academy Press},
  year = 	 2000,
  address =	 {Washington, DC},
  edition =	 {expanded},
  url =		 {}

The modified \setuppublicationlayout, which goes into an environment file or in the preamble of the .tex file, includes lines to use the url field. Since I use the num style for the publication list, with \setuppublications[alternative=num], I take the book layout from the bibl-num.tex source file and modify it by adding two lines:

% copied from bibl-num.tex and added
% \inserturl and \insertdoi
   \insertauthors{}{\unskip. }{\inserteditors{}{\unskip, editor%
                         \ifnum\getvalue{editor@num}> 1 s\fi.%
                             \ \global\editedbooktrue 
                     }{\insertthekey{}{\unskip. }{}}}%
        {\bgroup\it }%
                { Number~}%
                    { in~\bgroup}%
                    {\egroup. }%
                    {\insertcrossref{ in~}{}{. }}}%
                {\insertseries{ }{.}{} }%
        {\insertchap{, }{}{}%
         \insertpages{, pages }{. }{. }%
         \insertvolume{Volume~}{ of~}{}%
                   {, volume~}%
                      { of~\bgroup\it}%
                   \insertchap{, }{}{}%
                   \insertpages{, pages }{.}{.}%
    { }%
    {\insertedition{, }{ edition}{}%
     \insertpubyear{, }{.}{.}}%
    {\insertedition{, }{ edition}{}%
     \insertpubyear{, }{.}{.}}%
   \insertpages{ }{p.}{}%
   \insertdoi{ }{.}{}%added
   \insertbiburl{ }{.}{}%added
   \insertnote{ }{.}{}%

When running 'texexec', check the terminal output (or logfile) to ensure that texexec finds the modified t-bib.tex (which I have been keeping in the current directory) rather than the system-supplied t-bib.tex. Once the patched t-bib.tex becomes the official release (Taco says sometime in May 2007), that step won't be necessary.

Other tips

  • To refer directly to a reference number (called inline or online cite), you can do \cite[left=,right=][myRef] or simply define

  • To add further information to a reference, such as a page number within a book, do
\cite[extras={, page 275}][your-book-reference]
  • Bibtex supports mnemonics for months, for example

etc. This allows the style file to choose how to display months. By default, the bib module does not do any conversion of the months. This causes the months to turn up as digits. If you want months to come in words add

\setuppublications [monthconversion=month] %or month:mnem