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)
Example #2
0
 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,
         ],
     ]
Example #3
0
 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)
Example #4
0
 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')],
     ]
Example #5
0
 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)
Example #6
0
 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
Example #7
0
 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
Example #8
0
 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)
Example #10
0
 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'), ], ')']]
Example #11
0
 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
Example #12
0
 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)
Example #13
0
 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)
Example #14
0
 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
Example #15
0
 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)
Example #16
0
 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'), ]]
Example #17
0
 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')], ')']]
Example #18
0
 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)
Example #19
0
 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')], ')']]
Example #20
0
 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
Example #21
0
 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)
Example #22
0
 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)
Example #23
0
 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)
Example #24
0
 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)
Example #25
0
 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)
Example #26
0
 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
Example #27
0
 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)
Example #28
0
 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')], ')']]
Example #29
0
 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)
Example #30
0
 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)
Example #31
0
 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)
Example #32
0
 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
Example #33
0
 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
Example #34
0
 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)
Example #35
0
 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
Example #36
0
 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
Example #37
0
 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)
Example #38
0
 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)
Example #40
0
 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)
Example #41
0
 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)
Example #42
0
 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)
Example #43
0
 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)
Example #44
0
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 [