==The database==
<br/>
A bibTEX file looks like this:
<pre style='"color:rgb(102,0,102);font-size:120% '">@Article{sometag,
author = "An Author and Another One",
title = "A hopefully meaningful title",
<br/>
In the old MkII setup we have two kinds of entries: the ones that come from the bibTEX run and user supplied ones. We no longer rely on bibTEX output but we do still support the user supplied definitions. These were in fact prepared in a way that suits the processing of bibTEX generated entries. The next variant reflects the ConTEXt recoding of the old bibTEX output.
<pre detailstyle='typing'"color:rgb(102,0,102);font-size:120%">\startpublication[k=Hagen:Second,t=article,a={Hans Hagen},y=2013,s=HH01]
\artauthor[]{Hans}[H.]{}{Hagen}
\arttitle{Who knows more?}
<br/>
In the new setup we support these variants as well:
<pre detailstyle='typing'"color:rgb(102,0,102);font-size:120%">\startpublication[k=Hagen:Third,t=article]
\author{Hans Hagen}
\title{Who knows who?}
<br/>
and
<pre detailstyle='typing'"color:rgb(102,0,102);font-size:120%">\startpublication[tag=Hagen:Third,category=article]
\author{Hans Hagen}
\title{Who knows who?}
<br/>
and
<pre detailstyle='typing'"color:rgb(102,0,102);font-size:120%">\startpublication
\tag{Hagen:Third}
\category{article}
<br/>
Because internally the entries are Lua tables, we also support loading of Lua based definitions:
<pre detailstyle='typing'"color:rgb(102,0,102);font-size:120%">return {
["Hagen:First"] = {
author = "Hans Hagen",
<br/>
Files set up like this can be loaded too. The following xml input is rather close to this, and is also accepted as input.
<pre detailstyle='typing'"color:rgb(102,0,102);font-size:120%"><?xml version="2.0" standalone="yes" ?>
<bibtex>
<entry tag="Hagen:First" category="article">
You can load more data than you actually need. Only entries that are referred to explicitly through the <tt>\cite</tt> and <tt>\nocite</tt> commands will be shown in lists. We will cover these details later.
==Commands in entries==
One unfortunate aspect commonly found in bibTEX files is that they often contain TEX commands. Even worse is that there is no standard on what these commands can be and what they mean, at least not formally, as bibTEX is a program intended to be used with many variants of TEX style: plain, LATEX, and others. This means that we need to define our use of these typesetting commands. However, in most cases, they are just abbreviations or font switches and these are often known. Therefore, ConTEXt will try to resolve them before reporting an issue. In the log file there is a list of commands that has been seen in the loaded databases. For instance, loading <tt>tugboat.bib</tt> gives a long list of commands of which we show a small set here:
<pre detailstyle='typing'"color:rgb(102,0,102);font-size:120%">publications > start used btx commands
publications > standard CONTEXT 1 known
publications > standard ConTeXt 4 known
<br/>
You can define unknown commands, or overload existing definitions in the following way:
<pre detailstyle='typing'"color:rgb(102,0,102);font-size:120%">\definebtxcommand\TUB {TUGboat}
\definebtxcommand\sltt{\tt}
\definebtxcommand\<#1>{\type{#1}}
<br/>
Unknown commands do not stall processing, but their names are then typeset in a mono- spaced font so they probably stand out for proofreading. You can access the commands with <tt>\btxcommand{...}</tt>, as in:
<pre detail='buffer'> commands like \btxcommand{MySpecialCommand} are handled in an indirect way</pre>
<br/>
As this is an undefined command we get: “commands like MySpecialCommand are handled in an indirect way”.
Normally in a document you will use only one bibliographic database, whether or not distributed over multiple files. Nevertheless we support multiple databases as well which is why we talk of datasets instead. A dataset is loaded with the <tt>\usebtxdataset</tt> command. Although currently it is not necessary to define a (default) dataset you can best do this because in the future we might provide more options. Here are some examples:
<pre detailstyle='typing'"color:rgb(102,0,102);font-size:120%">\definebtxdataset[standard]
\usebtxdataset[standard][tugboat.bib]
\usebtxdataset[standard][mtx-bibtex-output.xml]
<br/>
In this document we use some example databases, so let’s load one of them now:
<pre detail='buffer'> \definebtxdataset[example]
\usebtxdataset[example][mkiv-publications.bib]
</pre>
<br/>
You can ask for an overview of entries in a dataset with:
<pre detail='buffer'> \showbtxdatasetfields[example]</pre>
<br/>
this gives:
<br/>
You can set the current active dataset with
<pre detailstyle='typing'"color:rgb(102,0,102);font-size:120%">\setbtxdataset[standard]
</pre>
<br/>
<br/>
If you want to see what publications are in the database, the easiest way is to ask for a complete list:
<pre detail='buffer'> \definebtxrendering
[example]
[dataset=example,
[example]
[criterium=all]
</pre>
<br/>
This gives:1 Hagen, H. and Otten, T. (1996). Typesetting education documents2 Scarso, L. (2021). Designing high speed trains3 author (year). title pages p.
<br/>
There are a couple of accessors and helpers to get the job done. When you want to fetch a field from the current entry you use <tt>\btxfield</tt>. In most cases you want to make sure this field has a value, for instance because you don’t want fences or punctuation that belongs to a field.
<pre detailstyle='typing'"color:rgb(102,0,102);font-size:120%">\btxdoif {title} {
\bold{\btxfield{title}},
}
<br/>
There are three test macros:
<pre detailstyle='typing'"color:rgb(102,0,102);font-size:120%">\btxdoifelse{fieldname}{action when found}{action when not found}
\btxdoif {fieldname}{action when found}
\btxdoifnot {fieldname} {action when not found}
<br/>
An extra conditional is available for testing interactivity:
<pre detailstyle='typing'"color:rgb(102,0,102);font-size:120%">\btxdoifelseinteraction{action when true}{action when false}
</pre>
<br/>
<br/>
You can improve readability by using setups, for instance:
<pre detailstyle='typing'"color:rgb(102,0,102);font-size:120%">\btxdoifelse {author} {
\btxsetup{btx:apa:author:yes}
} {
<br/>
So, the previous example setup can be rewritten as:
<pre detailstyle='typing'"color:rgb(102,0,102);font-size:120%">\btxdoif {title} {
\bold{\btxfield{title}}
\btxcomma
<br/>
There is a special command for rendering a (combination) of authors:
<pre detailstyle='typing'"color:rgb(102,0,102);font-size:120%">\btxflushauthor{author}
\btxflushauthor{editor}
\btxflushauthor[inverted]{editor}
<br/>
Instead of the last one you can also use:
<pre detailstyle='typing'"color:rgb(102,0,102);font-size:120%">\btxflushauthorinverted{editor}
</pre>
<br/>
Citations are references to bibliographic entries that normally show up in lists someplace in the document: at the end of a chapter, in an appendix, at the end of an article, etc. We discussed the rendering of these lists in the previous chapter. A citation is normally pretty short as its main purpose is to refer uniquely to a more detailed description. But, there are several ways to refer, which is why the citation subsystem is configurable and extensible. Just look at the following commands:
<pre detail='buffer'> \cite[author][example::demo-003]
\cite[authoryear][example::demo-003]
\cite[authoryears][example::demo-003]
\cite[authoryear][example::demo-004,demo-003]
\cite[authoryears][example::demo-004,demo-003]
</pre>
(Hans Hagen and Ton Otten)
<br/>
You can tune the way a citation shows up:
<pre detail='buffer'> \setupbtxcitevariant[author] [sorttype=author,color=darkyellow]
\setupbtxcitevariant[authoryear] [sorttype=author,color=darkyellow]
\setupbtxcitevariant[authoryears][sorttype=author,color=darkyellow]
</pre>
\cite[author][example::demo-004,demo-003]
\cite[authoryear][example::demo-004,demo-003]
<br/>
The <tt>\citation</tt> command is synonymous but is more flexible with respect to spacing of its arguments:
<pre detailstyle='typing'"color:rgb(102,0,102);font-size:120%">\citation[author] [example::demo-004,demo-003]
\citation[authoryear] [example::demo-004,demo-003]
\citation[authoryears][example::demo-004,demo-003]
A citation variant is defined in several steps and if you really want to know the dirty details, you should look into the <tt>publ-imp-*.mkiv</tt> files. Here we stick to the concept.
<pre detailstyle='typing'"color:rgb(102,0,102);font-size:120%">\startsetups btx:cite:author
\btxcitevariant{author}
\stopsetups
<br/>
You can overload such setups if needed, but that only makes sense when you cannot configure the rendering with parameters. The <tt>\btxcitevariant</tt> command is one of the build in accessors and it calls out to Lua where more complex manipulation takes place if needed. If no manipulation is known, the field with the same name (if found) will be flushed. A command like <tt>\btxcitevariant</tt> assumes that a dataset and specific tag has been set. This is normally done in the wrapper macros, like <tt>\cite</tt>. For special purposes you can use these commands
<pre detailstyle='typing'"color:rgb(102,0,102);font-size:120%">\setbtxdataset[example]
\setbtxentry[hh2013]
</pre>
<br/>
Unless you use <tt>criterium=all</tt> only publications that are cited will end up in the lists. You can force a citation into a list using <tt>\usecitation</tt>, for example:
<pre detailstyle='typing'"color:rgb(102,0,102);font-size:120%">\usecitation[example::demo-004,demo-003]
</pre>
<br/>
<br/>
The entries are collected in datasets and each set has a unique name. In this document we have the set named <tt>example</tt>. A dataset table has several fields, and probably the one of most interest is the <tt>luadata</tt> field. Each entry in this table describes a publication:
<pre detailstyle='typing'"color:rgb(102,0,102);font-size:120%">t={
["author"]="Hans Hagen",
["category"]="book",
</pre>
This is <tt>publications.datasets.example.luadata["demo-001"]</tt>. There can be a companion entry in the parallel <tt>details</tt> table.
<pre detailstyle='typing'"color:rgb(102,0,102);font-size:120%">t={
["author"]={
{
<br/>
You can loop over the entries using regular Lua code combined with MkIV helpers:
<pre detail='buffer'> local dataset = publications.datasets.example</pre>
context.starttabulate { "|l|l|l|" }
for tag, entry in table.sortedhash(dataset.luadata) do
<br/>
Once a dataset is accessible as xml tree, you can use the regular <tt>\xml...</tt> commands. We start with loading a dataset, in this case from just one file.
<pre detail='buffer'> \usebtxdataset[tugboat][tugboat.bib]</pre>
<br/>
The dataset has to be converted to xml:
<pre detail='buffer'> \convertbtxdatasettoxml[tugboat]</pre>
<br/>
The tree is now accessible by its root reference <tt>btx:tugboat</tt>. If we want simple field access we can use a few setups:
<pre detail='buffer'> \startxmlsetups btx:initialize
\xmlsetsetup{#1}{bibtex|entry|field}{btx:*}
\xmlmain{#1}
\stopxmlsetups
</pre>
\startxmlsetups btx:field
\xmlflushcontext{#1}
<br/>
The two setups are predefined in the core already, but you might want to change them. They are applied in for instance:
<pre detail='buffer'> \starttabulate[|||]
\NC \type {tag} \NC \xmlfirst {btx:tugboat}
{/bibtex/entry[string.find(@tag,'Hagen')]/attribute('tag')}
\NC \NR
\stoptabulate
</pre>
{|
|}
<pre detail='buffer'> \startxmlsetups btx:demo
\xmlcommand
{#1}
{/bibtex/entry[string.find(@tag,'Hagen')][1]}{btx:table}
\stopxmlsetups
</pre>
\startxmlsetups btx:table
\starttabulate[|||]
<br/>
Here is another example:
<pre detail='buffer'> \startxmlsetups btx:row
\NC \xmlatt{#1}{tag}
\NC \xmlfirst{#1}{/field[@name='title']}
\NC \NR
\stopxmlsetups
</pre>
\startxmlsetups btx:demo
\xmlfilter {#1} {
<br/>
A more extensive example is the following. Of course this assumes that you know what xml support mechanisms and macros are available.
<pre detail='buffer'> \startxmlsetups btx:getkeys
\xmladdsortentry{btx}{#1}{\xmlfilter{#1}{/field[@name='author']/text()}}
\xmladdsortentry{btx}{#1}{\xmlfilter{#1}{/field[@name='year' ]/text()}}
\xmladdsortentry{btx}{#1}{\xmlatt{#1}{tag}}
\stopxmlsetups
</pre>
\startxmlsetups btx:sorter
\xmlresetsorter{btx}
In the original bibliography support module usage was as follows (example taken from the contextgarden wiki):
<pre detailstyle='typing'"color:rgb(102,0,102);font-size:120%">% engine=pdftex
\usemodule[bib]
\usemodule[bibltx]
<br/>
In the new approach we no longer use bibTEXso we don’t need to setup bibTEX. Instead we define dataset(s). We also no longer set up publications with one command, but have split that up in rendering-, list-, and cite-variants. The basic <tt>\cite</tt> command remains. The above example becomes:
<pre detailstyle='typing'"color:rgb(102,0,102);font-size:120%">\definebtxdataset
[document]
\usebtxdataset
<br/>
So, we have a few more commands to set up things. If you intend to use just a single dataset and rendering, the above preamble can be simplified to:
<pre detailstyle='typing'"color:rgb(102,0,102);font-size:120%">\usebtxdataset
[mybibfile.bib]
\setupbtxrendering
As TEX and Lua are both open and accessible in ConTEXt it is possible to extend the functionality of the bibliography related code. For instance, you can add extra loaders.
<pre detailstyle='typing'"color:rgb(102,0,102);font-size:120%">function publications.loaders.myformat(dataset,filename)
local t = { }
-- Load data from 'filename' and convert it to a Lua table 't' with
<br/>
This then permits loading a database (into a dataset) with the command:
<pre detailstyle='typing'"color:rgb(102,0,102);font-size:120%">\usebtxdataset[standard][myfile.myformat]
</pre>
<br/>
The <tt>myformat</tt> suffix is recognized automatically. If you want to use another suffix, you can do this:
<pre detailstyle='typing'"color:rgb(102,0,102);font-size:120%">\usebtxdataset[standard][myformat::myfile.txt]
</pre>