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.

Install

pip install minibib

Usage

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

minibib <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}.


\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:

minibib 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.1.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.1-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: minibib-1.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 b26162b34ae935339909f598206dee581553fa3519412a2d4a8895ff42d45729
MD5 3272f457dd4d8534de6a0e41ab2a09ee
BLAKE2b-256 fc534d4fd551d977bae0b7b43eeb68841ab9bec31846a085d1cb644e6f97b532

See more details on using hashes here.

File details

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

File metadata

  • Download URL: minibib-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.7 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fca3a9cffef485fefdc4754fc2f7adfb22a09dd6c17484de154bdf9c98e54a4f
MD5 27ed6a4e7144bac8e400bf62eaa3cadf
BLAKE2b-256 38a8219d4ff03938ea4e2dac45ea31eaf1f7a54c32ca540d4f819db4ebeebed3

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