Skip to content

Custom writer example in docs #337

Description

@mscheltienne

Currently, defining a custom writer is possible but not straightforward.

  1. It is not clear that you have to initialize a writer and then change the attributes that were initialized. Having the attributes exposed as arguments of __init__(), with detailed docstrings used by the sphinx-build, might improve the experience. Example using numpy style docstrings:
class BibTexWriter(object):
    """
    Writer to convert a :class:`BibDatabase` object to a string or file formatted as a BibTeX file.

    Parameters
    -----------
    param1 : type
        description
    param2 : type
        description
    ...
    """

    def __init__(self, param1, param2, ...):
        pass
  1. Sorting of the fields is hidden in the undocumented SortingStrategy class.

  2. Most people will not define a custom writer and are simply going to use the dump function. The most common configuration should be accessible directly at the dump function level, e.g. sorting of entries and sorting of fields. Example:

def dump(
    bib_database: BibDatabase, 
    bibtex_file: TextIO, 
    writer: Optional[BibTexWriter] = None,
    order_entries: Optional[Tuple[str]] = None,
    order_fields: Optional[str] = None,
):
    pass

In the example above, None corresponds to "preserve" order. order_entries corresponds to the writer's attribute order_entries_by and order_fields corresponds to the writer's attribute display_order_sorting.

Originally posted in #336
x-ref with v2: #318

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions