def format_inbook(self, e): template = toplevel [ tag('pubtitle') [tag('b') [field('title')]], Symbol('br'), sentence [self.format_names('author')], self.format_volume_and_series(e), Symbol('br'), words [ sentence(capfirst=True) [ self.format_chapter_and_pages(e), #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), ], Symbol('br'), sentence [ field('publisher'), optional_field('address'), optional [ words [field('edition'), 'edition'] ], #date, #Symbol('br'), #optional_field('note'), ], ], Symbol('br'), sentence [ optional_field('note'), ], Symbol('br'), #self.format_web_refs(e), ] return template.format_data(e)
def format_address_organization_publisher_date( self, e, include_organization=True): """Format address, organization, publisher, and date. Everything is optional, except the date. """ # small difference from unsrt.bst here: unsrt.bst # starts a new sentence only if the address is missing; # for simplicity here we always start a new sentence if include_organization: organization = optional_field('organization') else: organization = None return first_of[ # this will be rendered if there is an address optional [ join(sep=' ') [ sentence[ field('address'), date, ], sentence[ organization, optional_field('publisher'), ], ], ], # if there is no address then we have this sentence[ organization, optional_field('publisher'), date, ], ]
def format_proceedings(self, e): template = toplevel [ first_of [ # there are editors optional [ join(' ')[ self.format_editor(e), sentence [ self.format_btitle(e, 'title', as_sentence=False), self.format_volume_and_series(e, as_sentence=False), self.format_address_organization_publisher_date(e), ], ], ], # there is no editor optional_field('organization'), sentence [ self.format_btitle(e, 'title', as_sentence=False), self.format_volume_and_series(e, as_sentence=False), self.format_address_organization_publisher_date( e, include_organization=False), ], ], sentence(capfirst=False) [ optional_field('note') ], ] return template.format_data(e)
def get_inbook_template(self, e): # Required fields: author/editor, title, chapter/pages, publisher, year # Optional fields: volume, series, address, edition, month, note, key return toplevel[ sentence(sep=' ')[ self.format_names('author'), join["(", date, ")"] ], self.format_title(e, 'title'), sentence(sep=' ')[ optional[ "In ", editor_names(), "," ], self.format_btitle(e, 'booktitle', as_sentence=False), optional[ join[ "(", sentence(add_period=False)[ optional[field('edition'), ' ed.'], self.format_volume(e), pages, ], ")" ] ] ], sentence(sep=': ')[ optional_field('address'), field('publisher'), ], sentence[optional_field('note')], ]
def format_booklet(self, e): template = toplevel[self.format_names('author'), self.format_title(e, 'title'), sentence[optional_field('howpublished'), optional_field('address'), date, optional_field('note'), ], self.format_web_refs(e), ] return template.format_data(e)
def get_mastersthesis_template(self, e): template = toplevel[sentence[self.format_names('author')], self.format_title(e, 'title'), sentence["Master's thesis", field('school'), optional_field('address'), date, ], sentence[optional_field('note')], self.format_web_refs(e), ] return template
def get_manual_template(self, e): template = toplevel[optional[sentence[self.format_names('author')]], self.format_btitle(e, 'title'), sentence[optional_field('organization'), optional_field('address'), self.format_edition(e), optional[date], ], sentence[optional_field('note')], self.format_web_refs(e), ] return template
def format_phdthesis(self, e): template = toplevel[sentence[self.format_names('author')], self.format_btitle(e, 'title'), sentence['PhD thesis', field('school'), optional_field('address'), date, ], sentence(capfirst=False)[optional_field('note')], self.format_web_refs(e), ] return template.format_data(e)
def format_unpublished(self, entry): template = toplevel[self.format_title(entry, 'title'), sentence[self.format_names('author')], sentence[words[first_of[optional_field('type'), 'Unpublished', ], optional_field('number'), ], date, ], sentence[optional_field('note')], self.format_web_refs(entry), ] return template.format_data(entry)
def format_dsa(self, e): # based on urlbst format.dsa return words['DSA:', href[join['https://datasheet.datasheetarchive.com/', field('dsa'), '.pdf'], field('dsa', apply_func=lambda x: x.split('/')[-1])], join[sentence(capfirst=False, add_period=False)[ '(PDF', optional_field('dsasize'), optional_field('dsadate'), ], ')']]
def get_phdthesis_template(self, e): template = toplevel[sentence[self.format_names('author')], self.format_btitle(e, 'title'), sentence[first_of[optional_field('type'), 'PhD thesis', ], field('school'), optional_field('address'), date, ], sentence[optional_field('note')], self.format_web_refs(e), ] return template
def format_book(self, e): template = toplevel[self.format_author_or_editor(e), self.format_btitle(e, 'title'), self.format_volume_and_series(e), sentence[field('publisher'), optional_field('address'), self.format_edition(e), date], sentence(capfirst=False)[optional_field('note')], self.format_web_refs(e), ] return template.format_data(e)
def format_manual(self, e): # TODO this only corresponds to the bst style if author is non-empty # for empty author we should put the organization first template = toplevel[optional[sentence[self.format_names('author')]], self.format_btitle(e, 'title'), sentence[optional_field('organization'), optional_field('address'), self.format_edition(e), optional[date], ], sentence(capfirst=False)[optional_field('note')], self.format_web_refs(e), ] return template.format_data(e)
def get_book_template(self, e): template = toplevel[self.format_author_or_editor(e), self.format_btitle(e, 'title'), self.format_volume_and_series(e), sentence[field('publisher'), optional_field('address'), self.format_edition(e), date], optional[sentence[self.format_isbn(e)]], sentence[optional_field('note')], self.format_web_refs(e), ] return template
def format_techreport(self, e): template = toplevel[sentence[self.format_names('author')], self.format_title(e, 'title'), sentence[words[first_of[optional_field('type'), 'Technical Report', ], optional_field('number'), ], field('institution'), optional_field('address'), date, ], sentence(capfirst=False)[optional_field('note')], self.format_web_refs(e), ] return template.format_data(e)
def get_book_template(self, e): # Required fields: author/editor, title, publisher, year # Optional fields: volume, series, address, edition, month, note, key, # isbn return toplevel[self.format_author_or_editor_and_date(e), join(sep=' ')[self.format_btitle(e, 'title'), optional[sentence[ optional_field('edition'), self.format_volume(e), ]]], join(sep=': ')[optional_field('address'), field('publisher'), ]]
def format_lpns(self, e): # based on urlbst format.dsa return words['Li-Pro.Net Store:', href[ join['http://store.li-pro.net/', field('lpns')], field('lpns', apply_func=lambda x: x.split('/')[-1].split('.', 1)[0])], join['(', sentence(capfirst=False, add_period=False)[ optional_field('lpnstype'), optional_field('lpnssize'), optional_field('lpnsdate')], ')']]
def format_booklet(self, e): template = toplevel [ self.format_names('author'), self.format_title(e, 'title'), sentence [ optional_field('howpublished'), optional_field('address'), date, optional_field('note'), ] ] return template.format_data(e)
def format_ghd(self, e): # based on urlbst format.ghd return words['GDR-HC Download:', href[ join['https://hc-ddr.hucki.net/wiki/lib/exe/fetch.php/', field('ghd')], field('ghd', apply_func=lambda x: x.split('/')[-1].split('.', 1)[0])], join['(', sentence(capfirst=False, add_period=False)[ optional_field('ghdtype'), optional_field('ghdsize'), optional_field('ghddate')], ')']]
def get_inbook_template(self, e): template = toplevel[self.format_author_or_editor(e), sentence[ self.format_btitle(e, 'title', as_sentence=False), self.format_chapter_and_pages(e), ], self.format_volume_and_series(e), sentence[field('publisher'), optional_field('address'), optional[words[field('edition'), 'edition']], date, optional_field('note'), ], self.format_web_refs(e), ] return template
def format_inbook(self, e): template = toplevel[sentence[self.format_names('author')], sentence[self.format_btitle(e, 'title'), self.format_chapter_and_pages(e), ], self.format_volume_and_series(e), sentence[field('publisher'), optional_field('address'), optional[words[field('edition'), 'edition']], date, optional_field('note'), ], self.format_web_refs(e), ] return template.format_data(e)
def format_inproceedings(self, e): template = toplevel [ sentence [self.format_names('author')], sentence [self.format_chapter_and_pages(e)], sentence [ field('publisher'), optional_field('address'), date, optional_field('note'), ] ] return template.format_data(e)
def format_phdthesis(self, e): template = toplevel [ sentence [self.format_names('author')], self.format_btitle(e, 'title'), sentence[ 'PhD thesis', field('school'), optional_field('address'), date, ], sentence(capfirst=False) [ optional_field('note') ], ] return template.format_data(e)
def format_techreport(self, e): template = toplevel[sentence( sep=" ")[self.format_names("author", False), join["(", date("report"), ")"], ], self.format_title(e, "title"), sentence[words[first_of[optional_field("type"), ], optional_field("number"), ], field("institution"), optional_field("address"), ], sentence[optional_field("note")], self.format_web_refs(e), ] return template.format_data(e)
def format_mastersthesis(self, e): template = toplevel [ sentence [self.format_names('author')], self.format_title(e, 'title'), sentence[ "Master's thesis", field('school'), optional_field('address'), date, ], sentence(capfirst=False) [ optional_field('note') ], ] return template.format_data(e)
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
def format_book(self, e): template = toplevel [ self.format_author_or_editor(e), self.format_btitle(e, 'title'), self.format_volume_and_series(e), sentence [ field('publisher'), optional_field('address'), self.format_edition(e), date ], sentence(capfirst=False) [ optional_field('note') ], ] return template.format_data(e)
def format_gsc(self, e): # based on urlbst format.gsc return words['GDR-Semiconductor:', href[join[ 'https://www-user.tu-chemnitz.de/~heha/basteln/Konsumg%C3%BCter/DDR-Halbleiter/', field('gsc')], field('gsc', apply_func=lambda x: x. split('/')[-1].split( '.', 1)[0])], join['(', sentence(capfirst=False, add_period=False)[ optional_field('gsctype'), optional_field('gscsize'), optional_field('gscdate')], ')']]
def format_mastersthesis(self, e): template = toplevel [ sentence [self.format_names('author')], self.format_title(e, 'title'), sentence[ "Master's thesis", field('school'), optional_field('address'), date, ], sentence(capfirst=False) [ optional_field('note') ], self.format_web_refs(e), ] return template.format_data(e)
def format_manual(self, e): # TODO this only corresponds to the bst style if author is non-empty # for empty author we should put the organization first template = toplevel [ optional [ sentence [ self.format_names('author') ] ], self.format_btitle(e, 'title'), sentence [ optional_field('organization'), optional_field('address'), self.format_edition(e), optional[ date ], ], sentence(capfirst=False) [ optional_field('note') ], ] return template.format_data(e)
def format_inproceedings(self, e): template = toplevel[ sentence[self.format_names("author")], self.format_title(e, "title"), words[ "In:", sentence(sep=" ")[first_of[field("eventtitle"), join[ 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_event_venue_date(e, "()"), ], ], sentence[optional_field("organization")], sentence[optional_field("note")], self.format_web_refs(e), ] return template.format_data(e)
def format_volume_and_series(self, e, as_sentence=True): # FIXME: evaluate the field 'language' and translate volume_and_series = optional [ words [ 'volume', field('volume'), optional [ words ['of', field('series')] ] ] ] number_and_series = optional [ words [ join(sep=Symbol('nbsp')) ['number', field('number')], optional [ words ['in', field('series')] ] ] ] series = optional_field('series') result = first_of [ volume_and_series, number_and_series, series, ] if as_sentence: return sentence(capfirst=True) [result] else: return result
def get_article_template(self, e): volume_and_pages = first_of[ # volume and pages, with optional issue number optional[ join[ field('volume'), optional['(', field('number'), ')'], ':', pages ], ], # pages only words['pages', pages], ] template = toplevel[ self.format_bold_title(e, 'title'), Symbol('newline'), self.format_names('author'), Symbol('newline'), sentence[ tag('em')[field('journal')], optional[volume_and_pages], date], sentence[optional_field('note')], self.format_web_refs(e), ] return template
def format_inbook(self, e): template = toplevel [ sentence [self.format_names('author')], sentence [self.format_chapter_and_pages(e)], self.format_volume_and_series(e), sentence [ field('publisher'), optional_field('address'), optional [ words [field('edition'), 'edition'] ], date, optional_field('note'), ] ] return template.format_data(e)
def get_article_template(self, e): # Required fields: author, title, journal, year # Optional fields: volume, number, pages, month, note, key volume_and_pages = first_of[ # Volume and pages, with optional issue number optional[ join[ self.format_volume(e, for_article=True), optional[', ', field('pages')] ], ], # Pages only pages, ] template = toplevel[ self.format_names('author'), sentence[ join["(", date, ")"] ], self.format_title(e, 'title'), sentence[ tag('em')[field('journal')], optional[volume_and_pages], ], sentence[optional_field('note')], self.format_web_refs(e), ] return template
def format_volume_and_series(self, e, as_sentence=True): volume_and_series = optional [ words [ 'volume', field('volume'), optional [ words ['of', field('series')] ] ] ] number_and_series = optional [ words [ join(sep=Symbol('nbsp')) ['number', field('number')], optional [ words ['in', field('series')] ] ] ] series = optional_field('series') result = first_of [ volume_and_series, number_and_series, series, ] if as_sentence: return sentence(capfirst=False) [result] else: return result
def format_misc(self, e): template = toplevel[optional[sentence[self.format_names('author')]], optional[self.format_title(e, 'title')], sentence[optional[field('howpublished')], optional[date], ], sentence(capfirst=False)[optional_field('note')], self.format_web_refs(e), ] return template.format_data(e)
def format_techreport(self, e): template = toplevel [ sentence [self.format_names('author')], self.format_title(e, 'title'), sentence [ words[ first_of [ optional_field('type'), 'Technical Report', ], optional_field('number'), ], field('institution'), optional_field('address'), date, ], sentence(capfirst=False) [ optional_field('note') ], ] return template.format_data(e)
def format_article(self, e): template = toplevel [ self.format_names('author'), self.format_title(e, 'title'), join [tag('emph') [field('journal')], ' ', tag('strong')[field('volume')], ', ', unsrt.pages, ' (', field('year'), ')'], sentence(capfirst=False) [ optional_field('note') ], self.format_web_refs(e), ] return template.format_data(e)
def format_misc(self, e): template = toplevel [ optional[ sentence [self.format_names('author')] ], optional[ self.format_title(e, 'title') ], sentence[ optional[ field('howpublished') ], optional[ date ], ], sentence(capfirst=False) [ optional_field('note') ], ] return template.format_data(e)
def format_incollection(self, e): template = toplevel [ sentence [self.format_names('author')], self.format_title(e, 'title'), words [ 'In', sentence(capfirst=False) [ 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, ], ] return template.format_data(e)
def format_inproceedings(self, e): template = toplevel [ sentence [self.format_names('author')], self.format_title(e, 'title'), words [ 'In', sentence(capfirst=False) [ 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(capfirst=False) [ optional_field('note') ], ] return template.format_data(e)
def format_article(self, e): volume_and_pages = first_of [ # volume and pages, with optional issue number optional [ join [ field('volume'), optional['(', field('number'),')'], ':', pages ], ], # pages only words ['pages', pages], ] template = toplevel [ self.format_names('author'), self.format_title(e, 'title'), sentence(capfirst=False) [ tag('emph') [field('journal')], optional[ volume_and_pages ], date], sentence(capfirst=False) [ optional_field('note') ], ] return template.format_data(e)
import re from pybtex.style.formatting import BaseStyle, toplevel from pybtex.style.template import ( join, words, field, optional, first_of, names, sentence, tag, optional_field ) from pybtex.richtext import Text, Symbol def dashify(text): dash_re = re.compile(r'-+') return Text(Symbol('ndash')).join(dash_re.split(text)) pages = field('pages', apply_func=dashify) date = words [optional_field('month'), field('year')] class Style(BaseStyle): name = 'unsrt' def format_names(self, role, as_sentence=True): formatted_names = names(role, sep=', ', sep2 = ' and ', last_sep=', and ') if as_sentence: return sentence(capfirst=False) [formatted_names] else: return formatted_names def format_article(self, e): volume_and_pages = first_of [ # volume and pages, with optional issue number optional [