Skip to main content

Organize your scientific publications using Pelican and BibTeX

Project description

Pelican Bib

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.

Installation

pelican_bib requires pybtex.

pip install pybtex

Using pip

pip install pelican-bib

Add the plugin to the PLUGINS variable:

PLUGINS = ['pelican_bib', ...]

As a Submodule

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', ...]

How to Use

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:

  1. key is the BibTeX key (identifier) of the entry.

  2. year is the year when the entry was published. Useful for grouping by year in templates using Jinja's groupby

  3. text is the HTML formatted entry, generated by pybtex.

  4. bibtex is a string containing BibTeX code for the entry, useful to make it available to people who want to cite your work.

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

Split into lists of publications

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'

Page with a list of publications

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 templates

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 }}
          [&nbsp;<a href="javascript:disp('{{ publication.bibtex|replace('\n', '\\n')|escape|forceescape }}');">Bibtex</a>&nbsp;]
          {% for label, target in [('PDF', publication.pdf), ('Slides', publication.slides), ('Poster', publication.poster)] %}
            {{ "[&nbsp;<a href=\"%s\">%s</a>&nbsp;]" % (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)

Sorting entries

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 }}
          [&nbsp;<a href="javascript:disp('{{ publication.bibtex|replace('\n', '\\n')|escape|forceescape }}');">Bibtex</a>&nbsp;]
          {% for label, target in [('PDF', publication.pdf), ('Slides', publication.slides), ('Poster', publication.poster)] %}
            {{ "[&nbsp;<a href=\"%s\">%s</a>&nbsp;]" % (target, label) if target }}
          {% endfor %}
          </li>
        {% endfor %}
    </ul>
...

The sort builtin filter was added in version 2.6 of jinja2.

Grouping entries

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 }}
      [&nbsp;<a href="javascript:disp('{{ publication.bibtex|replace('\n', '\\n')|escape|forceescape }}');">Bibtex</a>&nbsp;]
      {% for label, target in [('PDF', publication.pdf), ('Slides', publication.slides), ('Poster', publication.poster)] %}
        {{ "[&nbsp;<a href=\"%s\">%s</a>&nbsp;]" % (target, label) if target }}
      {% endfor %}
      </li>
    {% endfor %}
    </ul></li>
  {% endfor %}
</ul>
...

Using lists of publications

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 }}
            [&nbsp;<a href="javascript:disp('{{ publication.bibtex|replace('\n', '\\n')|escape|forceescape }}');">Bibtex</a>&nbsp;]
            {% for label, target in [('PDF', publication.pdf), ('Slides', publication.slides), ('Poster', publication.poster)] %}
                {{ "[&nbsp;<a href=\"%s\">%s</a>&nbsp;]" % (target, label) if target }}
            {% endfor %}
            </li>
	       {% endfor %}
	       </ul>
	   {% endfor %}
</section>
...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pelican-bib-0.2.7.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

pelican_bib-0.2.7-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file pelican-bib-0.2.7.tar.gz.

File metadata

  • Download URL: pelican-bib-0.2.7.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for pelican-bib-0.2.7.tar.gz
Algorithm Hash digest
SHA256 06c81ca743fa0a3f3672d9a394715c787589ce28a5538b784aa14e1f2e617004
MD5 984e282347156d708aa8f1698b749f13
BLAKE2b-256 bf457d8ff9cd9196c305685582da889d1660da3a7a54b2d6e74a36b4fd92794a

See more details on using hashes here.

File details

Details for the file pelican_bib-0.2.7-py3-none-any.whl.

File metadata

  • Download URL: pelican_bib-0.2.7-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for pelican_bib-0.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 cdcca3678a6b1fcdbebfb457ee10e6716e546408b3db22204ae5c5cf19348bd1
MD5 2009be2e784bdf9c9fb51ecca7968385
BLAKE2b-256 be2d2dc45d316f0353f16f3074171cbf900bfec1371d0ee2c6690864a70e966b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page