Organize your scientific publications with BibTeX in Pelican. The package is based on Vlad's pelican-bibtex. The current version is backward compatible and can replace the pelican-bibtex
install of your current project.
pelican_bib
requires pybtex
.
pip install pybtex
pip install pelican-bib
Add the plugin to the PLUGINS
variable:
PLUGINS = ['pelican_bib', ...]
In your Pelican site:
$ mkdir plugins
$ git submodule add https://github.com/scheunemann/pelican-bib plugins/pelican-bib
And Pelican config:
PLUGIN_PATHS = ['plugins/pelican_bib', ...]
PLUGINS = ['pelican_bib', ...]
This plugin reads a user-specified BibTeX file and populates the context with a list of publications, ready to be used in your Jinja2 template.
Configuration is simply:
PUBLICATIONS_SRC = 'content/pubs.bib'
If the file is present and readable, you will be able to find the publications
variable in all templates. It is a list of dictionaries with the following keys:
-
key
is the BibTeX key (identifier) of the entry. -
year
is the year when the entry was published. Useful for grouping by year in templates using Jinja'sgroupby
-
text
is the HTML formatted entry, generated bypybtex
. -
bibtex
is a string containing BibTeX code for the entry, useful to make it available to people who want to cite your work. -
pdf
,slides
,poster
: in your BibTeX file, you can add these special fields, for example:@article{ foo13 ... pdf = {/papers/foo13.pdf}, slides = {/slides/foo13.html} }
This plugin will take all defined fields and make them available in the template.
If a field is not defined, the tuple field will be None
. Furthermore, the
fields are stripped from the generated BibTeX (found in the bibtex
field).
You can add an extra field to each bibtex entry. This value of that field is a comma seperated list.
These values will become the keys of a list publications_lists
containing the associated bibtex entries in your template.
For example, if you want to associate an entry with two different tags (foo-tag
, bar-tag
),
you add the following field to the bib entry:
@article{
foo13
...
tags = {foo-tag, bar-tag}
}
In your pelicanconf.py
you'll need to set:
PUBLICATIONS_SPLIT_BY = 'tags'
In your template you can then access these lists with the variables publications_lists['foo-tag']
and publications_lists['bar-tag']
.
If you want to assign all untagged entries (i.e. entries without
the field defined in PUBLICATIONS_SPLIT_BY
) to a tag named others
, set:
PUBLICATIONS_UNTAGGED_TITLE = 'others'
To generate a page displaying the publications with one of the methods below, you need to add a template file and a page.
1.) place the template file as publications.html
in content/templates
and add it as direct template to your webpage. Add in your pelicanconf.py
:
THEME_TEMPLATES_OVERRIDES.append('templates')
2.) Create a page in your page folder, e.g., 'content/pages/publications.rst' with the following metadata in your content:
Publications
############
:template: publications
Example content of the publications.html
template:
{% extends "base.html" %}
{% block title %}Publications{% endblock %}
{% block content %}
<script type="text/javascript">
function disp(s) {
var win;
var doc;
win = window.open("", "WINDOWID");
doc = win.document;
doc.open("text/plain");
doc.write("<pre>" + s + "</pre>");
doc.close();
}
</script>
<section id="content" class="body">
<h1 class="entry-title">Publications</h1>
<ul>
{% for publication in publications %}
<li id="{{ publication.key }}">{{ publication.text }}
[ <a href="javascript:disp('{{ publication.bibtex|replace('\n', '\\n')|escape|forceescape }}');">Bibtex</a> ]
{% for label, target in [('PDF', publication.pdf), ('Slides', publication.slides), ('Poster', publication.poster)] %}
{{ "[ <a href=\"%s\">%s</a> ]" % (target, label) if target }}
{% endfor %}
</li>
{% endfor %}
</ul>
</section>
{% endblock %}
(Note: that we are escaping the BibTeX string twice in order to properly display it.
This can be achieved using forceescape
)
The entries can be sorted by one of the attributes, for example, if you want to sort the entries by date, your unordered list would look like the following:
...
<ul>
{% for publication in publications|sort(True, attribute='year') %}
<li id="{{ publication.key }}">{{ publication.text }}
[ <a href="javascript:disp('{{ publication.bibtex|replace('\n', '\\n')|escape|forceescape }}');">Bibtex</a> ]
{% for label, target in [('PDF', publication.pdf), ('Slides', publication.slides), ('Poster', publication.poster)] %}
{{ "[ <a href=\"%s\">%s</a> ]" % (target, label) if target }}
{% endfor %}
</li>
{% endfor %}
</ul>
...
The sort builtin filter was added in version 2.6 of jinja2.
To group entries by year,
...
<ul>
{% for grouper, publist in publications|groupby('year')|reverse %}
<li> {{grouper}}
<ul>
{% for publication in publist %}
<li id="{{ publication.key }}">{{ publication.text }}
[ <a href="javascript:disp('{{ publication.bibtex|replace('\n', '\\n')|escape|forceescape }}');">Bibtex</a> ]
{% for label, target in [('PDF', publication.pdf), ('Slides', publication.slides), ('Poster', publication.poster)] %}
{{ "[ <a href=\"%s\">%s</a> ]" % (target, label) if target }}
{% endfor %}
</li>
{% endfor %}
</ul></li>
{% endfor %}
</ul>
...
As described above, lists of publications are stored in publications_lists
.
You can replace publications
from the previous example with publications_lists['foo-tag']
to only show the publications with tagged with foo-tag
.
You can also iterate over the map and present all bib entries of each list. The section of the previous example changes to:
...
<section id="content" class="body">
<h1 class="entry-title">Publications</h1>
{% for tag in publications_lists %}
{% if publications_lists|length > 1 %}
<h2>{{tag}}</h2>
{% endif %}
<ul>
{% for publication in publications_lists[tag] %}
<li id="{{ publication.bibkey }}">{{ publication.text }}
[ <a href="javascript:disp('{{ publication.bibtex|replace('\n', '\\n')|escape|forceescape }}');">Bibtex</a> ]
{% for label, target in [('PDF', publication.pdf), ('Slides', publication.slides), ('Poster', publication.poster)] %}
{{ "[ <a href=\"%s\">%s</a> ]" % (target, label) if target }}
{% endfor %}
</li>
{% endfor %}
</ul>
{% endfor %}
</section>
...