Skip to content

latex

thmd.latex

Functions:

  • get_citekeys

    Extract all citekeys from a list of .tex files.

  • select_entries

    Select bibliography entries from a Bibtex .bib file

  • write_bibtex

    Write bibliography data to a Bibtex .bib file

  • minimize_bibtex

    Minimize the .bib file so that it contains only entries that are cited in the .tex files.

  • check_bibtex

    Check for missing fields in the bibtex entries. Based on the type of the entry, there are mandatory fields. This function is to check if any of mandatory fields is missing.

  • tex2doc

    Convert a Latex source .tex file to a Microsoft Word .docx file.

  • tex2pdf

    Convert a Latex source .tex file to a Microsoft Word .docx file.

  • replace_acronyms

    Check and replace if acronyms are used in a .tex file.

  • count_cited_journals

    Count the number of times each journal is cited in the .bib file.

get_citekeys(tex_files: Union[str, list]) -> list

Extract all citekeys from a list of .tex files.

Parameters:

  • tex_files (Union[str, list]) –

    paths to .tex files

Returns:

  • citekeys ( list ) –

    list of citekeys

select_entries(citekeys: list, bib_file: str) -> BibliographyData

Select bibliography entries from a Bibtex .bib file

Parameters:

  • citekeys (list) –

    list of citekeys

  • bib_file (str) –

    path to a .bib file

Returns:

write_bibtex(bib_data: BibliographyData, out_file: str = 'reference.bib') -> None

Write bibliography data to a Bibtex .bib file

Parameters:

  • bib_data (BibliographyData) –

    bibliography entries. See pybtex.database.BibliographyData

  • out_file (str, default: 'reference.bib' ) –

    path to the output .bib file

minimize_bibtex(tex_files: Union[str, list], bib_file: str, out_file: str = 'reference_min.bib') -> None

Minimize the .bib file so that it contains only entries that are cited in the .tex files.

Parameters:

  • tex_files (Union[str, list]) –

    path to .tex files

  • bib_file (str) –

    path to the original .bib file

  • out_file (str, default: 'reference_min.bib' ) –

    path to the new .bib file

check_bibtex(bib_file: str, verbose: bool = True, logfile: bool = False, lower_key=False) -> list

Check for missing fields in the bibtex entries. Based on the type of the entry, there are mandatory fields. This function is to check if any of mandatory fields is missing.

Parameters:

  • bib_file (str) –

    path to the original .bib file.

  • verbose (bool, default: True ) –

    print output to the console.

  • logfile (bool, default: False ) –

    write output to a log file.

  • lower_key (bool, default: False ) –

    convert the keys in bib_file to lower case.

Examples:

from thml.latex import check_bibtex
check_bibtex('reference.bib', verbose=True)

tex2doc(tex_file: str, out_file: str = 'output.docx', bib_file: str = None, **kwargs)

Convert a Latex source .tex file to a Microsoft Word .docx file. Need to install pandoc and panflute first.

condac install -c conda-forge pandoc
pip install panflute

Parameters:

  • tex_file (str) –

    path to the .tex file

  • out_file (str, default: 'output.docx' ) –

    path to the output .docx file

  • bib_file (str, default: None ) –

    path to the .bib file

Other Parameters:

  • cite_style (str = 'elsevier_vancouver.csl') –

    path to the citation style .cls' file. Can download from [here](https://github.com/citation-style-language/styles) or inZotero_folder/styles`

  • reference_doc (str) –

    path to the reference .docx file

  • resource_path (str = './figure') –

    path to the folder containing the figures and other resources.

  • verbose (bool = False) –

    print the output of the command

  • pandoc-crossref (bool = True) –

    use the pandoc-crossref extension for equation numbering

tex2pdf(tex_file: str, out_file: str = 'output.pdf', bib_file: str = None, **kwargs)

Convert a Latex source .tex file to a Microsoft Word .docx file.

Parameters:

  • tex_file (str) –

    path to the .tex file

  • out_file (str, default: 'output.pdf' ) –

    path to the output .docx file

  • bib_file (str, default: None ) –

    path to the .bib file

Other Parameters:

  • cite_style (str = 'elsevier_vancouver.csl') –

    path to the citation style `.cls' file. Can download from here

  • resource_path (str = './figure') –

    path to the folder containing the figures and other resources.

  • verbose (bool = False) –

    print the output of the command

replace_acronyms(tex_file: str, acronyms: dict) -> list

Check and replace if acronyms are used in a .tex file.

Not implemented yet.

count_cited_journals(bib_file: str) -> dict

Count the number of times each journal is cited in the .bib file.

Parameters:

  • bib_file (str) –

    path to the .bib file

Returns:

  • dict ( dict ) –

    a dictionary containing the journal names and the number of times they are cited.