diff --git a/bibtexparser/entrypoint.py b/bibtexparser/entrypoint.py index 5ecf871..3feb648 100644 --- a/bibtexparser/entrypoint.py +++ b/bibtexparser/entrypoint.py @@ -125,6 +125,7 @@ def write_file( parse_stack: Optional[Iterable[Middleware]] = None, append_middleware: Optional[Iterable[Middleware]] = None, bibtex_format: Optional[BibtexFormat] = None, + encoding: str = "UTF-8", ) -> None: """Write a BibTeX database to a file. @@ -134,7 +135,8 @@ def write_file( If None, a default stack will be used. :param append_middleware: List of middleware to append to the default stack. Only applicable if `parse_stack` is None. - :param bibtex_format: Customized BibTeX format to use (optional).""" + :param bibtex_format: Customized BibTeX format to use (optional). + :param encoding: Encoding for the .bib file. Default encoding is "UTF-8".""" bibtex_str = write_string( library=library, unparse_stack=parse_stack, @@ -142,7 +144,7 @@ def write_file( bibtex_format=bibtex_format, ) if isinstance(file, str): - with open(file, "w") as f: + with open(file, "w", encoding=encoding) as f: f.write(bibtex_str) else: file.write(bibtex_str)