-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for patents; Add support for month ordering
- Loading branch information
Showing
10 changed files
with
284 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# SPDX-FileCopyrightText: Copyright © 2024 André Anjos <[email protected]> | ||
# SPDX-License-Identifier: MIT | ||
"""Monkey-patch standard style from pybtex to support some extra entry | ||
types. | ||
""" | ||
|
||
from pybtex.style.formatting import toplevel | ||
import pybtex.style.formatting.unsrt | ||
from pybtex.style.formatting.unsrt import date | ||
from pybtex.style.template import field, node, optional, sentence, tag, words | ||
|
||
|
||
def _monkeypatch_method(cls): | ||
def decorator(func): | ||
setattr(cls, func.__name__, func) | ||
return func | ||
|
||
return decorator | ||
|
||
|
||
@_monkeypatch_method(pybtex.style.formatting.unsrt.Style) | ||
def get_patent_template(self, e): | ||
"""Format patent bibtex entry. | ||
Parameters | ||
---------- | ||
e | ||
The entry to be formatted. | ||
Returns | ||
------- | ||
The formatted entry object. | ||
""" | ||
return toplevel[ | ||
sentence[self.format_names("author")], | ||
self.format_title(e, "title"), | ||
sentence(capfirst=False)[tag("em")[field("number")], date], | ||
optional[self.format_url(e), optional[" (visited on ", field("urldate"), ")"]], | ||
] | ||
|
||
|
||
# format month by converting integers to month name | ||
_MONTH_NAMES = { | ||
1: "January", | ||
2: "February", | ||
3: "March", | ||
4: "April", | ||
5: "May", | ||
6: "June", | ||
7: "July", | ||
8: "August", | ||
9: "September", | ||
10: "October", | ||
11: "November", | ||
12: "December", | ||
} | ||
|
||
|
||
@node | ||
def _month_field(children, data): | ||
assert not children | ||
m = data["entry"].fields.get("month") | ||
try: | ||
m = int(m) | ||
# normalize | ||
m = 1 if m < 1 else m | ||
m = len(_MONTH_NAMES) if m > len(_MONTH_NAMES) else m | ||
# reset | ||
data["entry"].fields["month"] = _MONTH_NAMES[m] | ||
except (TypeError, ValueError): | ||
pass | ||
return optional[field("month")].format_data(data) | ||
|
||
|
||
# Ensures we always have the month correctly formatted | ||
pybtex.style.formatting.unsrt.date = words[_month_field(), field("year")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
%% SPDX-FileCopyrightText: Copyright © 2024 André Anjos <andre.dos.anjos-at-gmail.com> | ||
%% SPDX-License-Identifier: MIT | ||
@patent{pat, | ||
author = "A. G. Bell", | ||
title = "Improvement in telegraphy", | ||
nationality = "United States", | ||
number = "174465", | ||
day = "7", | ||
month = Mar, | ||
year = "1876", | ||
url = "https://www.google.com/patents/US174465", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.. SPDX-FileCopyrightText: Copyright © 2024 André Anjos <[email protected]> | ||
.. SPDX-License-Identifier: MIT | ||
This is an article | ||
################## | ||
|
||
:date: 2010-10-03 10:20 | ||
:modified: 2010-10-04 18:40 | ||
:tags: test, article | ||
:category: bibliography | ||
:slug: article | ||
:authors: André Anjos | ||
:summary: Short version for index and feeds | ||
:pybtex_sources: article.bib | ||
|
||
This will be turned into a citation [@@pat]. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# SPDX-FileCopyrightText: Copyright © 2024 André Anjos <[email protected]> | ||
# SPDX-License-Identifier: MIT | ||
PATH = "content" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
%% SPDX-FileCopyrightText: Copyright © 2024 André Anjos <andre.dos.anjos-at-gmail.com> | ||
%% SPDX-License-Identifier: MIT | ||
@misc{no-month, | ||
title = "Misc title 1", | ||
author = "Author Last", | ||
year = 2015, | ||
} | ||
|
||
@misc{month-short, | ||
title = "Misc with short month name", | ||
author = "Author Last", | ||
year = 2015, | ||
month = jan, | ||
} | ||
|
||
@misc{month-long, | ||
title = "Misc with short month name", | ||
author = "Author Last", | ||
year = 2015, | ||
month = "June", | ||
} | ||
|
||
@misc{month-number, | ||
title = "Misc with numbered month", | ||
author = "Author Last", | ||
year = 2015, | ||
month = 3, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# SPDX-FileCopyrightText: Copyright © 2024 André Anjos <[email protected]> | ||
# SPDX-License-Identifier: MIT | ||
PATH = "content" | ||
PYBTEX_SOURCES = ["publications.bib"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters