Skip to main content

A simple script to create a clean `.bib` file containing only the references cited in your `.tex` document.

Project description

BibTeX Entry Extractor for LaTeX

A simple yet powerful Python script to create a clean .bib file containing only the references cited in your .tex document. This is perfect for cleaning up your bibliography before sharing your project or submitting it to a journal.

Features

  • Extracts Only Used References: Scans your .tex file and pulls only the cited entries from your master .bib file.

  • Handles Various Cite Commands: Correctly identifies keys from a wide range of citation commands, including \cite, \citep, \citet, \citealt, etc.

  • Parses Complex Citations: Intelligently handles citations with pre-notes and post-notes, like \citep[see][p. 5]{key}.

  • Ignores Commented Citations: The script detects citations in commented-out lines (e.g., % \cite{key}) and excludes them from the final bibliography.

  • User-Friendly Warnings:

    • Notifies you if a cited key is present in the .tex file but missing from the .bib file.

    • Lists all the citation keys that were found in comments and therefore ignored.

Prerequisites

  • Python 3

No external libraries are needed.

Usage

Run the script from your terminal using the following command structure:

python minibib.py <path_to_tex_file> <path_to_bib_file> [options]

Arguments

  • tex_file: The path to your main .tex file.

  • bib_file: The path to your master .bib file.

  • -o, --output: (Optional) The name of the new, cleaned .bib file. Defaults to minibib_output.bib.

Example

Imagine you have the following files:

my_paper.tex:

\documentclass{article}

\begin{document}

This paper references the work of \citet{Doe2021}.
We also build on previous results \citep[see Chapter 3]{Smith2019}.

% A future version might include this: \cite{Jones2022}

\bibliography{references}
\bibliographystyle{plain}

\end{document}

references.bib:

@article{Doe2021,
    author  = {Doe, John},
    title   = {A Groundbreaking Study},
    journal = {Journal of Important Research},
    year    = {2021},
    volume  = {10},
    pages   = {1-20}
}

@book{Smith2019,
    author    = {Smith, Jane},
    title     = {Foundations of Modern Science},
    publisher = {Academic Press},
    year      = {2019}
}

@misc{Jones2022,
    author = {Jones, Sam},
    title  = {Preliminary Thoughts},
    year   = {2022},
    note   = {Unpublished}
}

To generate your clean bibliography, run:

python minibib.py my_paper.tex references.bib -o final_references.bib

Console Output:

Warning: The following citation keys were found in comments and will be ignored:
  - Jones2022

Found 2 unique active citation keys in 'my_paper.tex'.
Found 3 entries in 'references.bib'.

Successfully created new .bib file: 'final_references.bib'

The resulting final_references.bib will contain:

@article{Doe2021,
    author  = {Doe, John},
    title   = {A Groundbreaking Study},
    journal = {Journal of Important Research},
    year    = {2021},
    volume  = {10},
    pages   = {1-20}
}

@book{Smith2019,
    author    = {Smith, Jane},
    title     = {Foundations of Modern Science},
    publisher = {Academic Press},
    year      = {2019}
}

License

This project is open-source under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

minibib-1.0.0.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

minibib-1.0.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file minibib-1.0.0.tar.gz.

File metadata

  • Download URL: minibib-1.0.0.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.13

File hashes

Hashes for minibib-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f8425cd0abfc08d66dc8f8866b3f629e8cb2c07d32b44e44834e299178f37819
MD5 ac0106f50917457fb36e50d19c43ed6b
BLAKE2b-256 3a8926cd8bd79d5c8fcf2f89c4b8e0f97f149b6b890cf1530d6f9ca025991660

See more details on using hashes here.

File details

Details for the file minibib-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: minibib-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.13

File hashes

Hashes for minibib-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bb0085926a151aa13e806d2340d1027b08b7237ba7cbf6e6dcd5efcdc975f2ae
MD5 b181034aa71277f9785f81640c89d78c
BLAKE2b-256 955428e84f4cc867be42bf098117c6f01f7144ca2542d78c5eb4864002de5895

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page