author_key = None return (-int(entry.fields.get('year', '')), author_key, entry.fields.get('title', '')) def persons_key(self, persons): return ' '.join(self.person_key(person) for person in persons) def person_key(self, person): return ' '.join(( ' '.join(person.prelast() + person.last()), ' '.join(person.first() + person.middle()), ' '.join(person.lineage()), )).lower() def author_editor_key(self, entry): if entry.persons.get('author'): return self.persons_key(entry.persons['author']) elif entry.persons.get('editor'): return self.persons_key(entry.persons['editor']) class ReverseDate(UnsrtStyle): name = 'reversedate' default_sorting_style = 'year_author_title' default_label_style = 'reverse_number' register_plugin('pybtex.style.formatting', 'reversedate', ReverseDate) register_plugin('pybtex.style.sorting', 'year_author_title', ReverseSortingStyle) register_plugin('pybtex.style.labels', 'reverse_number', ReverseNumber)
#} autodoc_member_order = "bysource" #'members', 'undoc-members', 'private-members', 'special-members', 'inherited-members' and 'show-inheritance'. #autodoc_default_flags = ["show-inheritance", "inherited-members", "special-members"] # From https://sphinxcontrib-bibtex.readthedocs.io/en/latest/usage.html#custom-formatting-sorting-and-labelling # pybtex provides a very powerful way to create and register new styles, using setuptools entry points, # as documented here: http://docs.pybtex.org/api/plugins.html from pybtex.style.formatting.plain import Style from pybtex.style.labels.alpha import LabelStyle class AbiPyLabelStyle(LabelStyle): def format_label(self, entry): return entry.key class AbiPyStyle(Style): default_label_style = 'abipy' from pybtex.plugin import register_plugin register_plugin('pybtex.style.labels', 'abipy', AbiPyLabelStyle) register_plugin('pybtex.style.formatting', 'abipystyle', AbiPyStyle) # This is for releases http://releases.readthedocs.io/en/latest/usage.html releases_github_path = "abinit/abipy"
# api_url' : (settings.BASE_URL + '%s', settings.BASE_URL) #} autodoc_member_order = "bysource" #'members', 'undoc-members', 'private-members', 'special-members', 'inherited-members' and 'show-inheritance'. #autodoc_default_flags = ["show-inheritance", "inherited-members", "special-members"] # From https://sphinxcontrib-bibtex.readthedocs.io/en/latest/usage.html#custom-formatting-sorting-and-labelling # pybtex provides a very powerful way to create and register new styles, using setuptools entry points, # as documented here: http://docs.pybtex.org/api/plugins.html from pybtex.style.formatting.plain import Style from pybtex.style.labels.alpha import LabelStyle class AbiPyLabelStyle(LabelStyle): def format_label(self, entry): return entry.key class AbiPyStyle(Style): default_label_style = 'abipy' from pybtex.plugin import register_plugin register_plugin('pybtex.style.labels', 'abipy', AbiPyLabelStyle) register_plugin('pybtex.style.formatting', 'abipystyle', AbiPyStyle) # This is for releases http://releases.readthedocs.io/en/latest/usage.html releases_github_path = "abinit/abipy"
if 'author' in entry.persons: label = self.format_author_or_editor_names(entry.persons['author']) elif 'editor' in entry.persons: label = self.format_author_or_editor_names(entry.persons['editor']) elif 'organization' in entry.fields: label = entry.fields['organization'] if label.startswith("The "): label = label[4:] if 'year' in entry.fields: return "{}, {}".format(label, entry.fields['year']) else: return "{}, n.d.".format(label) def format_author_or_editor_names(self, persons): if len(persons) is 1: return _strip_nonalnum(persons[0].last_names) elif len(persons) is 2: return "{} & {}".format(_strip_nonalnum(persons[0].last_names), _strip_nonalnum(persons[1].last_names)) else: return "{} et al.".format(_strip_nonalnum(persons[0].last_names)) class APAStyle(UnsrtStyle): default_label_style = APALabelStyle register_plugin('pybtex.style.formatting', 'apa', APAStyle) # # ====================================================================
html_theme = 'sphinx_rtd_theme' html_static_path = ['_static'] html_logo = 'imgs/logo.jpg' html_favicon = 'imgs/favicon.ico' html_show_copyright = True html_show_sphinx = False html_show_sourcelink = False html_scaled_image_link = False html_css_files = [ 'style.css', ] html_sidebars = {'**': ['globaltoc.html']} html_theme_options = { 'canonical_url': '', 'logo_only': False, 'display_version': True, 'prev_next_buttons_location': None, 'style_external_links': True, 'style_nav_header_background': 'white', 'collapse_navigation': False, 'sticky_navigation': True, 'navigation_depth': 4, 'includehidden': True, 'titles_only': False } register_plugin('pybtex.style.formatting', 'gost_style', GOSTStyle)
# included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # from pkgutil import extend_path __path__ = extend_path(__path__, __name__) # See: https://www.python.org/dev/peps/pep-0328/ # Relative imports must always use from <> import ; import <> is always # absolute. Of course, absolute imports can use from <> import by omitting # the leading dots. from .kcsalpha import Style as KCSystemsAlphaStyle from .kcsplain import Style as KCSystemsPlainStyle from .kcsunsrt import Style as KCSystemsUnsrtStyle from .kcsunsrtalpha import Style as KCSystemsUnsrtAlphaStyle from pybtex.plugin import register_plugin register_plugin('pybtex.style.formatting', 'kcsalpha', KCSystemsAlphaStyle) register_plugin('pybtex.style.formatting', 'kcsplain', KCSystemsPlainStyle) register_plugin('pybtex.style.formatting', 'kcsunsrt', KCSystemsUnsrtStyle) register_plugin('pybtex.style.formatting', 'kcsunsrtalpha', KCSystemsUnsrtAlphaStyle)
from pybtex.plugin import register_plugin class YearSortingStyle(SortingStyle): def sorting_key(self, entry): if entry.type in ('book', 'inbook'): author_key = self.author_editor_key(entry) elif 'author' in entry.persons: author_key = self.persons_key(entry.persons['author']) else: author_key = '' return (-int(entry.fields.get('year', '')), author_key, entry.fields.get('title', '')) register_plugin('pybtex.style.sorting', 'year_author_title', YearSortingStyle) markdown = pybtex.format_from_file(sys.argv[1], style='plain', output_backend='markdown', sorting_style='year_author_title', abbreviate_names=True) markdown = re.sub('(\[\d+\])', '\n\\1', markdown) # markdown, _ = re.subn(r'\\textbf \\underline N\\., Sonnenschein', '**<u>N., Sonnenschein</u>**', markdown) markdown, _ = re.subn(r'\\\\textbf.*underline.*Sonnenschein', '**<u>N. Sonnenschein</u>**', markdown) markdown, _ = re.subn(r'\\\\textbf.*Sonnenschein', '**N. Sonnenschein**', markdown) markdown, _ = re.subn(r'\\\\emph\s*', '', markdown) print(markdown)
if what == "module": del lines[:] def setup(app): app.connect("autodoc-process-docstring", remove_module_docstring) # -- Options for bibliography style ------------------------------------------------- # We want the top level bibliography to look like in-line bibliography. # Source: https://stackoverflow.com/a/56030812/10668706 class KeyLabelStyle(AlphaLabelStyle): def format_label(self, entry): label = entry.key return label class CustomStyle(UnsrtStyle): default_sorting_style = "author_year_title" def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.label_style = KeyLabelStyle() self.format_labels = self.label_style.format_labels register_plugin("pybtex.style.formatting", "custom", CustomStyle)
"example": "Example", "lemma": "Lemma", "observation": "Observation", "proof": "Proof", "property": "Property", "theorem": "Theorem", "application": "Application", } proof_html_nonumbers = ["application"] from pybtex.plugin import register_plugin # noqa from pybtex.style.formatting.unsrt import Style as UnsrtStyle # noqa from pybtex.style.labels.alpha import LabelStyle as AlphaLabelStyle # noqa class CustomLabelStyle(AlphaLabelStyle): def format_label(self, entry): label = entry.persons["author"][0].last()[-1] if "year" in entry.fields: label += ", " + entry.fields["year"] return label class CustomStyle(UnsrtStyle): default_label_style = "customlabel" register_plugin("pybtex.style.labels", "customlabel", CustomLabelStyle) register_plugin("pybtex.style.formatting", "custom", CustomStyle)
# included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # from pkgutil import extend_path __path__ = extend_path(__path__, __name__) # See: https://www.python.org/dev/peps/pep-0328/ # Relative imports must always use from <> import ; import <> is always # absolute. Of course, absolute imports can use from <> import by omitting # the leading dots. from .ldspalpha import Style as LDSPAlphaStyle from .ldspplain import Style as LDSPPlainStyle from .ldspunsrt import Style as LDSPUnsrtStyle from .ldspunsrtalpha import Style as LDSPUnsrtAlphaStyle from pybtex.plugin import register_plugin register_plugin('pybtex.style.formatting', 'ldspalpha', LDSPAlphaStyle) register_plugin('pybtex.style.formatting', 'ldspplain', LDSPPlainStyle) register_plugin('pybtex.style.formatting', 'ldspunsrt', LDSPUnsrtStyle) register_plugin('pybtex.style.formatting', 'ldspunsrtalpha', LDSPUnsrtAlphaStyle)
# This pattern also affects html_static_path and html_extra_path. exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] # -- Options for HTML output ------------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # html_theme = 'sphinx_rtd_theme' # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ['_static'] # a simple label style which uses the bibtex keys for labels class NumberedLabelStyle(BaseLabelStyle): def format_labels(self, sorted_entries): for entry in sorted_entries: # Add one since refs usually start at 1 not 0 yield str(sorted_entries.index(entry) + 1) class PydroBibStyle(UnsrtStyle): default_label_style = NumberedLabelStyle register_plugin('pybtex.style.formatting', 'PydroStyle', PydroBibStyle)
from pybtex.style.formatting.unsrt import Style as UnsrtStyle from pybtex.style.labels.alpha import LabelStyle as AlphaLabelStyle from pybtex.plugin import register_plugin extensions = ['sphinxcontrib.bibtex'] exclude_patterns = ['_build'] class ApaLabelStyle(AlphaLabelStyle): def format_label(self, entry): return "APA" class ApaStyle(UnsrtStyle): default_label_style = 'apa' register_plugin('pybtex.style.labels', 'apa', ApaLabelStyle) register_plugin('pybtex.style.formatting', 'apastyle', ApaStyle)
"""Citation label used in text, and before each item in the References section""" re_char_nums = re.compile(r'^[\d\w]+$') def format_label(self, entry): """Returns BibTeX key for label Raises KeyError if BibTeX key has other characters other than letters and numbers. """ label = entry.key if not self.re_char_nums.match(label): raise KeyError( 'BibTeX key must contain only letters and numbers ' '(found {0!r})'.format(label)) return label class CustomStyle(UnsrtStyle): """Citation style in the References section""" default_label_style = 'linklabel' default_name_style = 'lastfirst' default_sorting_style = 'author_year_title' # TODO: Make more Harvard-like, i.e. year after name(s) register_plugin('pybtex.style.labels', 'linklabel', LinkLabelStyle) register_plugin('pybtex.style.formatting', 'customstyle', CustomStyle)
from pybtex.style.formatting.unsrt import Style as UnsrtStyle from pybtex.style.labels import BaseLabelStyle from pybtex.plugin import register_plugin class MyLabelStyle(BaseLabelStyle): def format_labels(self, sorted_entries): for entry in sorted_entries: yield entry.key class MyStyle(UnsrtStyle): default_label_style = MyLabelStyle register_plugin("pybtex.style.formatting", "bibtexlabels", MyStyle) source_suffix = [".rst", ".md"] autodoc_mock_imports = ["pandas", "seaborn", "pathos", "yaml"] # Read in all required packages and add them to a list import requirements with open("../requirements.txt", "r") as fd: for req in requirements.parse(fd): autodoc_mock_imports.append(req.name) autodoc_mock_imports = autodoc_mock_imports # Add any paths that contain templates here, relative to this directory.
return super().format_eprint(e) def format_url(self, e: Entry) -> Node: if "doi" in e.fields or "eprint" in e.fields: return "" return words[href[field("url", raw=True), field("url", raw=True, apply_func=remove_http), ]] def format_isbn(self, e: Entry) -> Node: return href[join[ "https://isbnsearch.org/isbn/", field("isbn", raw=True, apply_func=remove_dashes_and_spaces), ], join["ISBN:", field("isbn", raw=True), ], ] def remove_dashes_and_spaces(isbn: str) -> str: to_remove = ["-", " "] for remove in to_remove: isbn = isbn.replace(remove, "") return isbn def remove_http(url: str) -> str: to_remove = ["https://", "http://"] for remove in to_remove: url = url.replace(remove, "") return url register_plugin("pybtex.style.formatting", "unsrt_et_al", MyStyle)
summary = e.fields.get('cosmomvpa-summary', None) if summary is not None: summary_text = Tag('emph', Text('[ %s ]' % summary)) text.extend([Symbol('newblock'), summary_text]) return text default_name_style = 'abbr_lastfirst' class AbbrLastFirstNameStyle(AuthorNameStyle): def format(self, person, abbr=True): return super(AbbrLastFirstNameStyle, self).format(person, True) register_plugin('pybtex.style.names', 'abbr_lastfirst', AbbrLastFirstNameStyle) register_plugin('pybtex.style.formatting', 'cosmoref', CoSMoRefStyle) # -- Options for HTML output --------------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. ##html_theme = 'sphinxdoc' # NNO html_theme = 'nature' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. #html_theme_options = {}
numfig = True # on_rtd is whether we are on readthedocs.org, this line of code grabbed from # docs.readthedocs.org on_rtd = os.environ.get("READTHEDOCS", None) == "True" if not on_rtd: # only import and set the theme if we're building docs locally import sphinx_rtd_theme html_theme = "sphinx_rtd_theme" html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] # make a pybtex style which uses the bibtex key for labels from pybtex.style.formatting.unsrt import Style as UnsrtStyle from pybtex.style.labels.alpha import LabelStyle as AlphaLabelStyle from pybtex.plugin import register_plugin class KeyLabelStyle(AlphaLabelStyle): def format_label(self, entry): return entry.fields["key"] class KeyStyle(UnsrtStyle): default_label_style = "key" register_plugin("pybtex.style.labels", "key", KeyLabelStyle) register_plugin("pybtex.style.formatting", "keystyle", KeyStyle)
extensions = ['sphinxcontrib.bibtex'] exclude_patterns = ['_build'] # create and register pybtex plugins from pybtex.style.formatting.unsrt import Style as UnsrtStyle from pybtex.style.template import words from pybtex.plugin import register_plugin class NoWebRefStyle(UnsrtStyle): def format_web_refs(self, e): # the following is just one simple way to return an empty node return words[''] register_plugin('pybtex.style.formatting', 'nowebref', NoWebRefStyle)
exclude_patterns = ['README.rst', '_build'] source_encoding = 'utf-8' class LSSTStyle(PlainStyle): """Add a new style that understands DocuShare entries""" 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) register_plugin('pybtex.style.formatting', 'lsst_aa', LSSTStyle) # Intersphinx configuration. # http://www.sphinx-doc.org/en/stable/ext/intersphinx.html intersphinx_mapping = {}
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_doi(self, e): return href [ join [ 'https://doi.org/', field('doi') ], join [ 'doi:', field('doi') ] ] register_plugin('pybtex.style.sorting', 'cite', CiteStyle) register_plugin('pybtex.style.formatting', 'molcas', MolcasStyle)
# this should possibly be moved to the sphinxext directory as a standalone .py file # -- custom style for pybtex output ------------------------------------------- from pybtex.style.formatting.unsrt import Style as UnsrtStyle from pybtex.style.labels.alpha import LabelStyle as AlphaLabelStyle from pybtex.plugin import register_plugin # I seem to be unable to figure out how to control what is used for the label. It would # make sense if it were fed into this function, which then just formatted it, but I can't figure out from where # class MyLabel(AlphaLabelStyle): # def format_label(self, entry): # # return entry.fields.get('comment') # return entry.key class MyStyle(UnsrtStyle): name = "mystyle" default_name_style = "lastfirst" # 'lastfirst' or 'plain' # default_label_style = "mylabel" # 'number' or 'alpha' default_sorting_style = "author_year_title" # 'none' or 'author_year_title' def __init__(self, *args, **kwargs): super(MyStyle, self).__init__(*args, **kwargs) # self.label_style = MyLabel() # self.format_labels = self.label_style.format_label # register_plugin("pybtex.style.labels", "mylabel", MyLabel) register_plugin("pybtex.style.formatting", "mystyle", MyStyle)
text=super(CoSMoRefStyle,self).format_article(e) summary=e.fields.get('cosmomvpa-summary',None) if summary is not None: summary_text=Tag('emph',Text('[ %s ]' % summary)) text.extend([Symbol('newblock'),summary_text]) return text default_name_style = 'abbr_lastfirst' class AbbrLastFirstNameStyle(AuthorNameStyle): def format(self, person, abbr=True): return super(AbbrLastFirstNameStyle,self).format(person,True) register_plugin('pybtex.style.names','abbr_lastfirst',AbbrLastFirstNameStyle) register_plugin('pybtex.style.formatting', 'cosmoref', CoSMoRefStyle) # -- Options for HTML output --------------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. ##html_theme = 'sphinxdoc' # NNO html_theme = 'nature' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. #html_theme_options = {}
def setup(app): register_plugin('pybtex.style.labels', 'myapa', MyAPALabelStyle) register_plugin('pybtex.style.formatting', 'myapastyle', MyAPAStyle)
default_label_style = 'key' class CustomBibtexStyle2(UnsrtStyle): default_sorting_style = 'year_author_title' default_label_style = 'key' class KeyLabelStyle(BaseLabelStyle): def format_labels(self, sorted_entries): return [entry.key for entry in sorted_entries] class YearAuthorTitleSort(SortingStyle): def sorting_key(self, entry): author_key, year, title = super().sorting_key(entry) return (year, author_key, title) class KeySort(SortingStyle): def sorting_key(self, entry): return entry.key register_plugin('pybtex.style.formatting', 'custom1', CustomBibtexStyle1) register_plugin('pybtex.style.formatting', 'custom2', CustomBibtexStyle2) register_plugin('pybtex.style.labels', 'key', KeyLabelStyle) register_plugin('pybtex.style.sorting', 'key', KeySort) register_plugin('pybtex.style.sorting', 'year_author_title', YearAuthorTitleSort)
def format_url(self, e): # based on urlbst format.url return href [ field('url'), 'url' ] def format_adsurl(self, e): # based on urlbst format.url return href [ field('adsurl'), 'ads link' ] register_plugin('pybtex.style.formatting', 'mystyle', MyStyle) # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. sys.path.insert(0, os.path.abspath('../Cosmo/src')) # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. #needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones.
return template.format_data(e) def format_inproceedings(self, e): myurl = first_of [ optional_field('adsurl'), optional [join ['http://arxiv.org/abs/', field('eprint')]], optional_field('url'), optional [join ['https://doi.org/', field('doi')]] ] template = toplevel [ sentence [self.format_names('author')], href [myurl, self.format_title(e, 'title')] \ if len(myurl.format_data(e)) > 0 \ else tag('strong') [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) register_plugin('pybtex.style.formatting', 'adsarxiv', ADSArxivStyle)
if entry.type == "book" or entry.type == "inbook": label = self.author_editor_key_label(entry) elif entry.type == "proceedings": label = self.editor_key_organization_label(entry) elif entry.type == "manual": label = self.author_key_organization_label(entry) else: label = self.author_key_label(entry) # add full year comma separated if "year" in entry.fields: return '{0}, {1}'.format(label, entry.fields["year"]) else: return label def format_lab_names(self, persons): numnames = len(persons) person = persons[0] result = _strip_nonalnum(person.prelast_names + person.last_names) if numnames > 1: result += " et al." return result class WradlibStyle(Style): default_label_style = 'wrl' register_plugin('pybtex.style.labels', 'wrl', WradlibLabelStyle) register_plugin('pybtex.style.formatting', 'wrlstyle', WradlibStyle)
sorted_keys = sorted(entry_dict, reverse = True) sorted_entries = [entry_dict[key] for key in sorted_keys] return sorted_entries class CustomNameStyle(NameStyle): 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 register_plugin('pybtex.style.formatting', 'customstyle', CustomStyle) register_plugin('pybtex.style.labels', 'customlabels', CustomLabelStyle) register_plugin('pybtex.style.sorting', 'customsorting', CustomSortingStyle) register_plugin('pybtex.style.names', 'customnames', CustomNameStyle) # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. #needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = ['sphinxcontrib.bibtex', 'sphinxcontrib.rawfiles'] # Files you want to copy
from pybtex.style.formatting.unsrt import Style as UnsrtStyle from pybtex.style.template import words from pybtex.plugin import register_plugin extensions = ['sphinxcontrib.bibtex'] exclude_patterns = ['_build'] bibtex_bibfiles = ['test.bib'] bibtex_default_style = 'nowebref' class NoWebRefStyle(UnsrtStyle): def format_web_refs(self, e): # the following is just one simple way to return an empty node return words[''] register_plugin('pybtex.style.formatting', 'nowebref', NoWebRefStyle)
def register(): logger.info("Registering astro-style pybtex formatting...") register_plugin('pybtex.style.formatting', 'astrostyle', AstroStyle)
result = result[4:] return result def names2label(self, persons): numnames = len(persons) if numnames == 1: result = lastname(persons[0]) elif numnames == 2: result = '{:s} and {:s}'.format(lastname(persons[0]), lastname(persons[1])) elif numnames == 3: result = '{:s}, {:s}, and {:s}'.format(lastname(persons[0]), lastname(persons[1]), lastname(persons[2])) else: result = '{:s} et al.'.format(lastname(persons[0])) return result class AuthorListPlainStyle(PlainStyle): default_label_style = AuthorsLabelStyle class AuthorListUnsrtStyle(UnsrtStyle): default_label_style = AuthorsLabelStyle register_plugin('pybtex.style.formatting', 'authorlist', AuthorListPlainStyle) register_plugin('pybtex.style.formatting', 'authorlist_unsrt', AuthorListUnsrtStyle)
return ' '.join(( ' '.join(person.prelast_names + person.last_names), ' '.join(person.first_names + person.middle_names), ' '.join(person.lineage_names), )).lower() def author_editor_key(self, entry): if entry.persons.get('author'): return self.persons_key(entry.persons['author']) elif entry.persons.get('editor'): return self.persons_key(entry.persons['editor']) else: return '' register_plugin('pybtex.style.sorting', 'date', DateSortingStyle) class NoWebRefStyle(UnsrtStyle): default_sorting_style = 'date' def format_web_refs(self, e): return sentence[optional[self.format_doi(e)], ] register_plugin('pybtex.style.formatting', 'nowebref', NoWebRefStyle) # -- Options for HTML output ---------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes.
return template.format_data(e) def format_inproceedings(self, e): myurl = first_of[optional_field('adsurl'), optional[join['http://arxiv.org/abs/', field('eprint')]], optional_field('url'), optional[join['http://dx.doi.org/', field('doi')]]] template = toplevel [ sentence [self.format_names('author')], href [myurl, self.format_title(e, 'title')] \ if len(myurl.format_data(e)) > 0 \ else tag('strong') [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) register_plugin('pybtex.style.formatting', 'adsarxiv', ADSArxivStyle)
authors += author.last_names[0][0] if len(entry.persons["author"]) > author_limit: authors += "+" processed_entries.append("%s%s" % (authors, year)) # Mark duplicates with incremental alphabet counts = Counter(processed_entries) marked = Counter() out_entries = [] for entry in processed_entries: if counts[entry] > 1: marked[entry] += 1 entry += _number_to_alphabet(marked[entry] - 1) out_entries.append(entry) return out_entries def _number_to_alphabet(number): out = chr((number % 26) + 97) if number >= 26: out = _number_to_alphabet(number // 26 - 1) + out return out class AuthorYearStyle(UnsrtStyle): default_label_style = AuthorYearLabelStyle register_plugin('pybtex.style.formatting', 'authoryearstyle', AuthorYearStyle)