def format_inproceedings(self, e): template = toplevel [ tag('b') [self.format_title(e, 'title')], Symbol('br'), self.format_names('author'), Symbol('br'), words [ # 'In', # optional[ self.format_editor(e, as_sentence=False) ], # tag('conference') [self.format_btitle(e, 'booktitle', as_sentence=False)], tag('conference') [self.format_btitle(e, 'shorttitle', as_sentence=False)], # self.format_volume_and_series(e, as_sentence=False), # optional[ words [pages] ], # optional[ field('pages') ], # optional_field('pages',apply_func=dashify) # ABC ERROR #self.format_address_organization_publisher_date(e), Symbol('br'), ], optional [ words [ field('note'), Symbol('br') ] ], #self.format_web_refs(e), ] # print field('pages',apply_func=dashify) # ABC error return template.format_data(e)
def format_title(self, e, which_field, as_sentence=False): def protected_capitalize(x): """Capitalize string, but protect {...} parts.""" result = "" level = 0 for pos, c in enumerate(x): if c == '{': level += 1 elif c == '}': level -= 1 elif pos == 0: c = c.upper() elif level <= 0: c = c.lower() result += c return result # formatted_title = field(which_field) formatted_title = tag('pubtitle') [ tag('b') [field(which_field)]] # formatted_title = field( ABC ERROR # which_field, apply_func=protected_capitalize) if as_sentence: return sentence(capfirst=False) [tag('b') [ formatted_title ]] else: return formatted_title
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_title(e, 'title'), Symbol('br'), self.format_names('author'), Symbol('br'), tag('journal') [tag('b') [field('journal')]], optional[ volume_and_pages ], Symbol('br'), optional [ words [ field('note'), Symbol('br') ] ], #self.format_web_refs(e), #sentence(capfirst=False) [ optional_field('note') ], ] return template.format_data(e)
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 get_article_template(self, e): journal_and_volume = join[tag('em')[self.format_journal(e)], ' ', tag('strong')[self.format_volume(e)]] template = toplevel[self.format_author(e), self.format_title(e, 'title'), sentence[journal_and_volume, join[optional[self.format_pages(e)], ' (', field('year'), ')']]] return template
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_entries(self, entries): """Override for appending links before yielding ``FormattedEntries``. :param entries: `BibliographyData` entries :type entries: BibliographyData """ if 'groupby' in plugin_data: sorter = plugin_data['groupby'] group_name_dict = plugin_data.get('mapping_%s' % sorter, {}) grouped_entries = group_entries_by_key(entries, sorter, group_name_dict) else: grouped_entries = {'ALL': list(entries)} for group_name, group in grouped_entries.items(): sorted_entries = self.sort(group) labels = list(self.format_labels(sorted_entries)) for label, entry in zip(labels, sorted_entries): for persons in entry.persons.itervalues(): for person in persons: person.text = self.format_name(person, self.abbreviate_names) f = getattr(self, "format_" + entry.type) text = f(entry) bib = optional[join[ '[', tag('tt')[href[field('publipy_biburl', raw=True), 'bib']], ']']] pdf = optional[join[ '[', tag('tt')[href[field('publipy_pdfurl', raw=True), 'pdf']], ']']] abstract = optional[join[ '[', tag('tt')[href[field('publipy_abstracturl', raw=True), 'abstract']], ']']] www = join['[', tag('tt')[href[field('url_home', raw=True), 'www']], ']'] text += ' ' # make some space if entry.fields['url_home']: text += join(sep=' ')[bib, pdf, abstract, www].format_data(entry) else: text += join(sep=' ')[bib, pdf, abstract].format_data(entry) yield group_name, FormattedEntry(entry.key, text, label)
def get_article_template(self, e): volume_and_pages = first_of[optional[join[tag('b')[field('volume')], ', ', pages], ], words['pages', pages], ] template = toplevel[join[self.format_names('author'), ", "], join[tag('em')[field('journal')], " ", optional[volume_and_pages], " (", field('year'), ")"], ] return template def format_web_refs(self, e): # we just leave the doi return optional[join['doi:', field('doi', raw=True)]]
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_proceedings(self, e): template = toplevel [ first_of [ # there are editors optional [ join(' ')[ sentence(capfirst=True) [tag('b') [self.format_title(e, 'title')]], Symbol('br'), self.format_editor(e), #self.format_btitle(e, 'title', as_sentence=False), Symbol('br'), self.format_volume_and_series(e, as_sentence=False), self.format_address_organization_publisher_date(e), Symbol('br'), ], ], # 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') ], #self.format_web_refs(e), ] return template.format_data(e)
def format_btitle(self, e, which_field, as_sentence=True): formatted_title = tag('em')[field( which_field, apply_func=lambda text: process_latex(text))] if as_sentence: return sentence[formatted_title] else: return formatted_title
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_patent(self, e): template = toplevel [ self.format_names('author'), self.format_title(e, 'title'), join [tag('emph') [field('number')], ' ', '(', field('year'), ')'] ] return template.format_data(e)
def format_volume(self, e, for_article=False): prefix = "Vol." if for_article: return optional[tag('em')[field('volume')], optional['(', field('number'), ')'], ] else: return optional[together[prefix, field('volume')]]
def format_book(self, e): template = toplevel [ self.format_author_or_editor(e), tag('emph') [sentence [field('title')]], self.format_volume_and_series(e), sentence [field('publisher'), date], ] return template.format_data(e)
def format(self, person, abbr=False): res = super(CustomNameStyle, self).format(person, abbr=abbr) if person.rich_last_names == [Text('Winter')]: res = tag('b')[res] return res
def format_title(self, e, which_field, as_sentence=True): title_math_match = re.compile("\$(.*?)\$") title_raw = e.fields[which_field].lstrip("{").rstrip("}") title = title_math_match.sub(r"\(\1\)", title_raw) formatted_title = tag("em")[pybtex.richtext.Text(title)] if as_sentence: return sentence[formatted_title] else: return formatted_title
def format_chapter_and_pages(self, e): return join(sep=', ') [ field('title', apply_func=dquote), words [ optional [words ['chapter', field('chapter'), 'of']], tag('emph') [field('booktitle')] ], optional [words ['pages', pages]], ]
def format_title(self, e, which_field, as_sentence=True): "Override the UnsrtStyle format_title(), so we have the title hyperlinked." title = tag('strong')[super().format_title(e, which_field, as_sentence)] if self.detail_page_url: url = '/'.join((self.detail_page_url, e.label + '.html')) return href[url, title] else: return title
def format_misc(self, e): template = toplevel [ tag('pubtitle') [tag('b') [field('title')]], Symbol('br'), optional[ sentence [self.format_names('author')] ], Symbol('br'), optional [ words [ sentence [ field('note')], Symbol('br') ] ], #sentence[ #optional[ field('howpublished') ], #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'), self.format_edition(e), date], optional[sentence[self.format_isbn(e)]], optional[sentence[self.format_web_refs(e)]], tag('strong')[optional_field('note')], ] return template
def format_article(self, e): volume_and_pages = first_of [ join [field('volume'), optional [':', pages]], words ['pages', optional [pages]] ] template = toplevel [ self.format_names('author'), sentence [field('title')], sentence [ tag('emph') [field('journal')], volume_and_pages, date], ] return template.format_data(e)
def format_article(self, e): pages = first_of [ # article id with total pages optional [ join [ field('articleid'), optional [ '(',join[u'1–', optional_field('pagetotal')],')' ] ] ], # pages only field('pages', apply_func=dashify), ] volume_and_pages = first_of [ # volume and pages, with optional issue number optional [ join [ tag('strong') [field('volume')], optional['[', field('number'),']'], ' (', field('year'), ')', ' ', pages ], ], # pages only words ['pages', pages], ] template = toplevel [ self.format_names('author'), #self.format_title(e, 'title'), sentence(capfirst=False) [ tag('em') [field('journal')], optional[ volume_and_pages ], ], sentence(capfirst=False) [ optional_field('note') ], self.format_web_refs(e), ] return template.format_data(e)
def format_article(self, e): volume_and_pages = first_of [ join [ optional [ 'vol. ', field('volume'), ', '], optional [ words [ 'no.', field('number') ] ], optional [': ', pages] ], optional [ words ['pages', pages] ] ] template = toplevel [ self.format_names('author'), sentence [field('title', apply_func=dquote)], sentence [ tag('emph') [field('journal')], volume_and_pages, date], ] return template.format_data(e)
def get_article_template(self, e): template = toplevel[ first_name('author'), field('title'), '/', names('author', sep=', '), '//', sentence(sep='. – ')[ tag('em')[field('journal')], date, optional[join[words['V.', field('volume')], optional[words[', Is.', field('number')]], optional[words['. – P.', pages]]]]], sentence(sep=' ')[optional[self.format_doi(e)], optional[join['(', field('note'), ')']]] ] return template
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_names("author"), self.format_title(e, "title"), sentence[tag("em")[field("journal")], optional[volume_and_pages], date], self.format_web_refs(e), sentence[optional_field("note")], ] return template
def format_article(self, entry): #author = entry.fields['author'] if 'volume' in entry.fields: volume_and_pages = join [field('volume'), optional [':', 'pages']] else: volume_and_pages = words ['pages', optional ['pages']] #import pdb #pdb.set_trace() template = toplevel [ self.format_name(entry.persons['author'][0]), sentence [field('title')], sentence [ tag('emph') [field('journal')], volume_and_pages, field('year')], ] return template.format_data(entry)
def format_docushare(self, e): default_url = join['https://ls.st/', field('handle', raw=True)] template = toplevel[sentence[tag('b')['[', href[default_url, field('handle')], ']']], self.format_names('author'), self.format_title(e, 'title'), sentence[field('year')], sentence[optional_field('note')], # Use URL if we have it, else provide own first_of[optional[self.format_url(e)], # define our own URL sentence['URL', href[default_url, default_url]]]] return template.format_data(e)
def format_phdthesis(self, e): template = toplevel [ tag('pubtitle') [self.format_btitle(e, 'title')], Symbol('br'), sentence [self.format_names('author')], Symbol('br'), sentence[ 'PhD thesis', field('school'), optional_field('address'), date, ], sentence(capfirst=False) [ optional_field('note') ], Symbol('br'), #self.format_web_refs(e), ] return template.format_data(e)
def format_inbook(self, e): template = toplevel [ sentence [self.format_names('author')], sentence [ tag('emph') [field('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'), ] ] return template.format_data(e)
def get_article_template(self, e): pages = field('pages', apply_func=dashify) date = words[optional_field('month'), field('year')] 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[tag('em')[ first_of[optional[field('journal')], optional[field('journaltitle')], ], ], optional[volume_and_pages], date], sentence[optional_field('note')], self.format_web_refs(e), ] return template
def format_article(self, entry): """ Output: A. Firstauthor, B. Secondauthor, and C. Thirdauthor. <br> </br> <b>Title</b> <br> </br> <a href="http://arxiv.org/abs/1603.05981">arXiv:1603.05981</a> <br> </br> <a href="http://dx.doi.org/10.1093/mnras/stw1649">doi:10.1093/mnras/stw1649</a> <br> </br> Remove extra line breaks with `sed -i 's| </br>||g'` """ template = toplevel[words[self.format_names('author'), self.newline(), tag('b')[field('title')], self.newline(), self.format_web_refs(entry)]] return template.format_data(entry)
def get_article_template(self, e): arxiv_url = join["https://arxiv.org/abs/", field("eprint", raw=True)] doi_url = join["https://doi.org/", field("doi", raw=True)] journal_text = join(" ")[ field("journal"), tag("strong")[field("volume")], join["(", field("year"), ")"], pages, ] journal = first_of[ optional[ join[ href[doi_url, journal_text], " [", href[arxiv_url, field("eprint", raw=True)], "]", ] ], optional[ join[ journal_text, " [", href[arxiv_url, field("eprint", raw=True)], "]" ] ], optional[href[doi_url, journal_text]], optional[journal_text], optional[href[arxiv_url, join["arXiv:", field("eprint", raw=True)]]], ] template = toplevel[ sentence[self.format_author_or_editor(e)], self.format_title(e, "title"), optional[sentence[journal]], sentence[optional_field("note")], self.format_repository(e), ] return template
def format_btitle(self, e, which_field, as_sentence=True): formatted_title = tag('emph') [ field(which_field) ] if as_sentence: return sentence[ formatted_title ] else: return formatted_title
def format_web_refs(self, e): return tag(':bib-web_refs')[super().format_web_refs(e)]
def get_unpublished_template(self, e): return tag(':bib-unpublished')[super().get_unpublished_template(e)]
def get_techreport_template(self, e): return tag(':bib-techreport')[super().get_techreport_template(e)]
def get_proceedings_template(self, e): return tag(':bib-proceedings')[super().get_proceedings_template(e)]