-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebsite_style.py
103 lines (92 loc) · 3.31 KB
/
website_style.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# I am extending and overwriting pybtex's UnsrtStyle here.
# I change the following:
# - Simplified URL and DOI labels
# - surround titles with "
# - Remove the "IN" for conference proceedings
from pybtex.style.formatting.unsrt import Style as UnsrtStyle
from pybtex.style.formatting import toplevel
from pybtex.style.template import (
join, words, together, field, optional, first_of,
names, sentence, tag, optional_field, href, Node
)
# Initialize to use only year labels for sections, sort by year, month, and then title in descending order
class Style(UnsrtStyle):
default_sorting_style = 'year_month_title'
default_label_style = 'year'
# Overwrite URL format for PDFs: Process URLs, only use PDF as link label
def format_url(self, e):
# based on urlbst format.url
url=field('url', raw=False)
return words [
href [
url,
'PDF'
]
]
# Overwrite URL format for DOIs: only use DOI as link label
def format_doi(self, e):
# based on urlbst format.doi
return href [
join [
'https://doi.org/',
field('doi', raw=True)
],
'DOI'
]
# Overwrite title style: surround with " "
def format_title(self, e, which_field, as_sentence=True):
formatted_title = field(
which_field, apply_func=lambda text: text.capitalize()
)
formatted_title= join()[
'"',
formatted_title,
'"'
]
if as_sentence:
return sentence [ formatted_title ]
else:
return formatted_title
# Overwrite: Remove 'IN' from proceedings.
# THIS DOES NOT WORK - NO IDEA WHY....got too annoyed by it so I gave up on fixing...
def get_inproceedings_template(self, e):
template = toplevel [
sentence [self.format_names('author')],
self.format_title(e, 'title'),
words [
# 'In',
sentence [
optional[ self.format_editor(e, as_sentence=False) ],
self.format_btitle(e, 'booktitle', as_sentence=False),
self.format_volume_and_series(e, as_sentence=False),
optional[ pages ],
],
self.format_address_organization_publisher_date(e),
],
sentence [ optional_field('note') ],
self.format_web_refs(e),
]
return template
# Overwrite: Remove 'IN' from proceedings.
def get_incollection_template(self, e):
template = toplevel [
sentence [self.format_names('author')],
self.format_title(e, 'title'),
words [
# 'In',
sentence [
optional[ self.format_editor(e, as_sentence=False) ],
self.format_btitle(e, 'booktitle', as_sentence=False),
self.format_volume_and_series(e, as_sentence=False),
self.format_chapter_and_pages(e),
],
],
sentence [
optional_field('publisher'),
optional_field('address'),
self.format_edition(e),
date,
],
self.format_web_refs(e),
]
return template