Difference between revisions of "Bibliography mkii"

From Wiki
Jump to navigation Jump to search
m
(39 intermediate revisions by 22 users not shown)
Line 1: Line 1:
< [[Modules]] | [[User:Taco/Bib]] >
+
< [[Modules]] | [[Bibliography| Bibliographies in mkii]] | [[Bibliography mkiv|Bibliographies in mkiv]] | [[sample_bib| sample bib file]] >
  
The '''bib''' module provides the
+
Please note that this information is relevant to mkii. If you are using mkiv, see [[Bibliography_mkiv]].
<cmd>cite</cmd>
 
and
 
<cmd>placepublications</cmd>
 
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 '''bib''' module provides the {{cmd|cite}} and {{cmd|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.
  
The manual can be downloaded from [[http://tex.aanhet.net/bib/ Taco's Page]]
+
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 [[modules:bibman| bib module manual]] page or in your ConTeXt installation.  For me (ConTeXt installed in my home directory), it's in <tt>~/texmf/doc/context/bib/bibmod-doc.pdf</tt>. <b>Read this manual, it is much more complete than this page!</b>
  
 
== Example of use with bibtex ==
 
== Example of use with bibtex ==
  
Bibtex support is not integrated in texexec (yet), so you have to run bibtex by hand.
+
Bibtex support is integrated in texexec you just have to set up the database name.
  
 
Assuming you have saved this bit of code as bibdemo.tex:
 
Assuming you have saved this bit of code as bibdemo.tex:
 
<texcode>
 
<texcode>
 
\usemodule[bib]
 
\usemodule[bib]
 +
\usemodule[bibltx]
 
\setupbibtex[database=xampl]
 
\setupbibtex[database=xampl]
 +
\setuppublications[numbering=yes] % Show reference numbers in the generated list.
 
\starttext
 
\starttext
As \cite[article-full]\ already indicated, bibtex is a \LaTeX-centric program.
+
As \cite[article-full] already indicated, bibtex is a \LaTeX-centric program.
 
\completepublications
 
\completepublications
 
\stoptext
 
\stoptext
 
</texcode>
 
</texcode>
  
Then you have to run the following three commands:
+
Then you just have to run the following command:
 
<pre>
 
<pre>
texexec --once bibdemo
 
bibtex bibdemo
 
 
texexec bibdemo
 
texexec bibdemo
 
</pre>
 
</pre>
To get the typeset result. (xampl.bib comes with the bibtex distribution, it should be on your harddisk somewhere already)
+
To get the typeset result. xampl.bib is a bibtex file example coming with the bibtex distribution (it should be on your harddisk somewhere already:  on my teTeX 3.0 system, <tt>/usr/share/texmf-tetex/bibtex/bib/base/xampl.bib</tt> is the location), in which the <tt>article-full</tt> key is referred.
 +
 
 +
The <code>\usemodule[bibltx]</code> line is needed because <tt>xampl.bib</tt> uses LaTeX commands and defines them using LaTeX syntax.  The <tt>bibltx</tt> module allows ConTeXt to understand some such constructions (which is enough for it to work with <tt>xampl.bib</tt>).
 +
 
 +
Note: Since Bibtex is added to the context core, no external module is necessary. It is sufficient to type for example (minimal):
 +
 
 +
<texcode>
 +
\setupbibtex[database=bib]
 +
 
 +
\starttext
 +
\completepublications
 +
\stoptext
 +
</texcode>
  
 
== Changing the way you show the publication list ==
 
== Changing the way you show the publication list ==
  
If you want to change the way you show the publication list you might want to look
+
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.  
at the following example, it will change the publication list showing  
 
the surname in uppercase.
 
  
 
(Credits go to Taco Hoekwater)
 
(Credits go to Taco Hoekwater)
Line 65: Line 74:
 
</texcode>
 
</texcode>
  
 +
== 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 <code>t-bib.tex</code> (until the next ConTeXt release sometime in May 2007 that will contain the patch).
 +
 +
* Use the <code>url</code> field in the <code>bibtex</code> entries.
 +
 +
* Setup a publication layout (for those types of <code>bibtex</code> entries) that knows how to include a URL.
 +
 +
The minimal example is in [[Image:Biburls.zip]], which includes the patched <code>t-bib.tex</code>.  But here are the details of steps 2 and 3.  A <code>bibtex</code> <code>book</code> entry using the <code>url</code> field looks like:
 +
 +
<texcode>
 +
@Book{HPL2000,
 +
  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 = {http://www.nap.edu/}
 +
}
 +
</texcode>
 +
 +
The modified <code>\setuppublicationlayout</code>, which goes into an environment file or in the preamble of the <code>.tex</code> file, includes lines to use the <code>url</code> field.  Since I use the <code>num</code> style for the publication list, with <code>\setuppublications[alternative=num]</code>, I take the <code>book</code> layout from the <code>bibl-num.tex</code> source file and modify it by adding two lines:
 +
 +
<texcode>
 +
\unprotect
 +
% copied from bibl-num.tex and added
 +
% \inserturl and \insertdoi
 +
\setuppublicationlayout[book]{%
 +
  \insertauthors{}{\unskip. }{\inserteditors{}{\unskip, editor%
 +
                        \ifnum\getvalue{editor@num}> 1 s\fi.%
 +
                            \ \global\editedbooktrue
 +
                    }{\insertthekey{}{\unskip. }{}}}%
 +
  \inserttitle
 +
        {\bgroup\it }%
 +
        {\/\egroup
 +
        \ifeditedbook.%
 +
          \global\editedbookfalse
 +
          \insertvolume
 +
                { Number~}%
 +
                {\insertseries
 +
                    { in~\bgroup}%
 +
                    {\egroup. }%
 +
                    {\insertcrossref{ in~}{}{. }}}%
 +
                {\insertseries{ }{.}{} }%
 +
        \else
 +
      \insertcrossref
 +
        {\insertchap{, }{}{}%
 +
        \insertpages{, pages }{. }{. }%
 +
        \insertvolume{Volume~}{ of~}{}%
 +
        }%
 +
        {}%
 +
        {\insertvolume
 +
                  {, volume~}%
 +
                  {\insertseries
 +
                      { of~\bgroup\it}%
 +
                      {\egroup}
 +
                      {}}
 +
                  {}%
 +
                  \insertchap{, }{}{}%
 +
                  \insertpages{, pages }{.}{.}%
 +
                }%
 +
        \fi}%
 +
        {}%
 +
  \insertpublisher
 +
    { }%
 +
    {\insertedition{, }{ edition}{}%
 +
    \insertpubyear{, }{.}{.}}%
 +
    {\insertedition{, }{ edition}{}%
 +
    \insertpubyear{, }{.}{.}}%
 +
  \insertpages{ }{p.}{}%
 +
  \insertdoi{ }{.}{}%added
 +
  \insertbiburl{ }{.}{}%added
 +
  \insertnote{ }{.}{}%
 +
}
 +
\protect
 +
</texcode>
 +
 +
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.
 +
 +
== Superscript Citations ==
 +
 +
Cross-referenced citations can be raised in the text using the {{cmd|raisebox}} command:
 +
 +
  % Superscript citation cross-references.
 +
  \setupcite[num][
 +
    left=\raisebox{1ex}\hbox\bgroup\tfxx,
 +
    right=\egroup,
 +
  ]
 +
 +
== Other tips ==
 +
 +
* <cmd>placepublications</cmd> and <cmd>completepublications</cmd> default to producing a publication list for the citations that are local to the current sectioning level. If you find that your reference list is empty even though the citations look fine, you will probably need to add an option to the list command, like so:
 +
<texcode>
 +
\placepublications[criterium=all]
 +
</texcode>
 +
 +
* To refer directly to a reference number (called inline or online cite), you can do <tt>\cite[left=,right=][myRef]</tt> or simply define
 +
<texcode>
 +
\def\onlinecite{\cite[left=,right=]}
 +
 +
\onlinecite[myRef]
 +
</texcode>
 +
 +
* To add further information to a reference, such as a page number within a book, do
 +
<texcode>
 +
\cite[extras={, page 275}][your-book-reference]
 +
</texcode>
 +
 +
* Bibtex supports mnemonics for months, for example
 +
  month=jan,
 +
  month=feb,
 +
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
 +
 +
<texcode>
 +
\setuppublications [monthconversion=month] %or month:mnem
 +
</texcode>
 +
 +
* Even though Bibtex is not encoding-aware at all, it does allows special (8-bit) characters. So there is no need for ugly constructs like \"a (for ä) or \'e (for é). The one exception is within author family names, because those are handled specially, both for sorting and for generating so-called 'short tags'. For the same reasons, one must also avoid using non-ascii characters in the bibtex citation reference labels.
  
 
[[Category:Modules]]
 
[[Category:Modules]]
 +
 +
* Bibliography items whose title ends in a ‘?’ (question mark, interrogation mark) can cause problems. See [[Question marks in bibliography entries]] for details of how to work around this.
 +
 +
==What can I do, if entries are not shown?==
 +
 +
Check if a <code>jobname.bbl</code> - file is generated. If it is empty, try manually running
 +
 +
  bibtex <filename>
 +
 +
In case of an error message like <code>I couldn't open style file cont-no.bst</code>, you can try
 +
 +
  mktexlsr
 +
 +
in root terminal. Bibtex uses LS-R to find these files.
 +
 +
{{Getting started navbox}}

Revision as of 05:37, 11 August 2014

< Modules | Bibliographies in mkii | Bibliographies in mkiv | sample bib file >

Please note that this information is relevant to mkii. If you are using mkiv, see Bibliography_mkiv.

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 manual page or in your ConTeXt installation. For me (ConTeXt installed in my home directory), it's in ~/texmf/doc/context/bib/bibmod-doc.pdf. Read this manual, it is much more complete than this page!

Example of use with bibtex

Bibtex support is integrated in texexec you just have to set up the database name.

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

\usemodule[bib]
\usemodule[bibltx]
\setupbibtex[database=xampl]
\setuppublications[numbering=yes] % Show reference numbers in the generated list.
\starttext
As \cite[article-full] already indicated, bibtex is a \LaTeX-centric program.
\completepublications
\stoptext

Then you just have to run the following command:

texexec bibdemo

To get the typeset result. xampl.bib is a bibtex file example coming 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), in which the article-full key is referred.

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).

Note: Since Bibtex is added to the context core, no external module is necessary. It is sufficient to type for example (minimal):

\setupbibtex[database=bib]

\starttext
\completepublications
\stoptext

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

\unprotect\def\UCauthor#1#2#3#4#5%
   {\bibdoif{#2}{#2\bibalternative\c!vonsep}%
    \uppercase{#3}\bibalternative\c!surnamesep    
    \bibdoif{#5}{#5\bibalternative\c!juniorsep}%
    \bibdoif{#4}{#4\unskip}}
\protect

After that, you can do:

\setuppublicationlist
    [artauthor=\UCauthor,
     editor=\UCauthor,
     author=\UCauthor]

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 File:Biburls.zip, 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:

@Book{HPL2000,
  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 =		 {http://www.nap.edu/}
}

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:

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

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.

Superscript Citations

Cross-referenced citations can be raised in the text using the \raisebox command:

 % Superscript citation cross-references.
 \setupcite[num][
   left=\raisebox{1ex}\hbox\bgroup\tfxx,
   right=\egroup,
 ]

Other tips

  • \placepublications and \completepublications default to producing a publication list for the citations that are local to the current sectioning level. If you find that your reference list is empty even though the citations look fine, you will probably need to add an option to the list command, like so:
\placepublications[criterium=all]
  • To refer directly to a reference number (called inline or online cite), you can do \cite[left=,right=][myRef] or simply define
\def\onlinecite{\cite[left=,right=]}

\onlinecite[myRef]
  • 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
 month=jan,
 month=feb,

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
  • Even though Bibtex is not encoding-aware at all, it does allows special (8-bit) characters. So there is no need for ugly constructs like \"a (for ä) or \'e (for é). The one exception is within author family names, because those are handled specially, both for sorting and for generating so-called 'short tags'. For the same reasons, one must also avoid using non-ascii characters in the bibtex citation reference labels.

What can I do, if entries are not shown?

Check if a jobname.bbl - file is generated. If it is empty, try manually running

 bibtex <filename>

In case of an error message like I couldn't open style file cont-no.bst, you can try

 mktexlsr

in root terminal. Bibtex uses LS-R to find these files.

Template:Getting started navbox