Skip to content

Commit

Permalink
support for more fields and bibtex types
Browse files Browse the repository at this point in the history
  • Loading branch information
mpharrigan authored and Matthew Harrigan committed Feb 16, 2018
1 parent d0594d4 commit f9fc92e
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 13 deletions.
38 changes: 36 additions & 2 deletions gitbib/gitbib.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,10 +486,44 @@ def _replace2(ma):


def bibtype(key, entries, ulog):
# https://api.crossref.org/v1/types
type_mapping = {
## Cross-ref
#'book-section'
#'monograph'
#'report'
#'book-track'
'journal-article': 'article',
#'book-part'
'other': 'misc',
'book': 'book',
#'journal-volume'
#'book-set'
#'reference-entry'
'proceedings-article': 'proceedings',
#'journal'
#'component'
'book-chapter': 'incollection',
#'report-series'

## Arxiv
'unpublished': 'unpublished',
# TODO: More type mappings. Is there any dx.doi.org documentation for these?

## Biorxiv
'posted-content': 'unpublished',

## Other raw bibtex
'article': 'article',
'booklet': 'booklet',
'inbook': 'inbook', # crossref book-part?
'incollection': 'incollection', # crossref book-section?
'inproceedings': 'inproceedings',
'manual': 'manual',
'mastersthesis': 'mastersthesis',
'misc': 'misc',
'phdthesis': 'phdthesis',
'proceedings': 'proceedings',
'techreport': 'techreport',
}
s = entries[key].get('type', '')
if s in type_mapping:
Expand Down Expand Up @@ -752,7 +786,7 @@ def render_by_input_filename(entries, input_fn, *, ulog):

class Renderfunc:
def __init__(self, fn, fext, list_of_idents, entries, ulog):
env = Environment(loader=PackageLoader('gitbib'))
env = Environment(loader=PackageLoader('gitbib'), keep_trailing_newline=True)
env.filters['latex_escape'] = latex_escape
env.filters['bibtype'] = lambda k: bibtype(k, entries, ulog)
env.filters['pretty_author_list'] = pretty_author_list
Expand Down
42 changes: 31 additions & 11 deletions gitbib/templates/template.bib
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,41 @@
{% set entry = entries[ident] -%}
@{{ ident | bibtype }}{{ '{'+ident }},
author = "{{entry['author'] | bibtex_author_list}}",
title = "{{entry.get('title', '') | latex_escape | bibtex_capitalize}}",
author = "{{entry['author'] | bibtex_author_list}}",
title = "{{entry.get('title', '') | latex_escape | bibtex_capitalize}}",
{% if entry['booktitle'] -%}
booktitle = "{{entry['booktitle']}}",
{% endif -%}
{% if entry['published-online'] -%}
year = "{{entry['published-online'] | attr('year') }}",
year = "{{entry['published-online'] | attr('year') }}",
{% elif entry['published-print'] -%}
year = "{{entry['published-print'] | attr('year') }}",
year = "{{entry['published-print'] | attr('year') }}",
{% endif -%}
{% if entry['container-title'] -%}
journal = "{{entry['container-title']['short'] | latex_escape }}",{% endif %}
volume = "{{entry['volume']}}",
number = "{{entry['issue']}}",
pages = "{{ entry['page'] | replace('-', '--') }}",
doi = "{{ entry['doi'] }}",
{% if entry['arxiv'] -%}
note = "arXiv:{{ entry['arxiv'] }}",{% endif %}
journal = "{{entry['container-title']['short'] | latex_escape }}",
{% endif -%}
{% if entry['address'] -%} {# note: I don't think this is ever given by crossref #}
address = "{{entry['address']}}",
{% endif -%}
volume = "{{entry['volume']}}",
number = "{{entry['issue']}}",
chapter = "{{entry['chapter']}}",
pages = "{{ entry['page'] | replace('-', '--') }}",
{% if entry['note'] -%}
note = "{{entry['note']}}",
{% elif entry['arxiv'] -%}
note = "arXiv:{{ entry['arxiv'] }}",
{% elif entry['biorxiv'] -%}
note = "bioRxiv:{{ entry['biorxiv'] }}",
{% endif -%}
{% if entry['publisher'] -%}
publisher = "{{entry['publisher']}}",
{% endif -%}
{% if not entry['doi'] and entry['biorxiv'] -%}
doi = "{{ entry['biorxiv'] }}",
{% else -%}
doi = "{{ entry['doi'] }}",
{% endif %}
}
{% endfor %}
Expand Down

0 comments on commit f9fc92e

Please sign in to comment.