Oh, sure, because who doesn't love manually cleaning up messy .bib files? bib_optimizer.py heroically steps in to remove those lazy, unused citations and reorder the survivors exactly as they appear in the .tex file—because, clearly, chaos is the default setting for bibliographies.
In layman's terms, it automates bibliography management by:
- removing unused citations,
- reordering the remaining ones to match their order of appearance in the
.texfile.
Input Files:
main.tex– The LaTeX source file.ref.bib– The original bibliography file.
These input files will remain unchanged.
Output File:
ref_opt.bib– A placeholder filename for the newly generated, cleaned, and ordered bibliography file.
Create and activate a virtual environment, then install the latest release from PyPI:
python -m venv .venv
# Linux/macOS
source .venv/bin/activate
# Windows
.venv\Scripts\activate
python -m pip install --upgrade bib_optimizerAlternatively, install the command in an isolated environment with uv:
uv tool install bib_optimizerAfter either installation method, the bibopt command is available in your terminal.
This repository uses uv for project and dependency management.
-
Clone the repository
git clone https://github.com/kwyip/bib_optimizer.git cd bib_optimizer -
Install environment
# This creates the virtual environment and installs all dependencies uv sync -
Activate environment
# Linux/MacOS source .venv/bin/activate # Windows .venv\Scripts\activate
🐍 This requires Python 3.8 or newer versions
-
Prepare the input files (e.g., by downloading them from Overleaf).
-
Run the command to generate a new
.bibfile (for example, you may name itref_opt.bib):bibopt main.tex ref.bib ref_opt.bib -
Use the Cleaned Bibliography
Replaceref.bibwithref_opt.bibin your LaTeX project.
You may test the installation using the sample input files (sample_main.tex and sample_ref.bib) located in the test folder.
sample_main.tex and sample_ref.bib
A sample ref_opt.bib created after running bibopt sample_main.tex sample_ref.bib ref_opt.bib
Download SKILL.md, then upload these files to your AI agent:
SKILL.md,- the root
.texfile, - the source
.bibfile, and if any: - every
.texfile referenced through\inputor\include.
Tip
Use this prompt:
Use the attached `SKILL.md` to optimize the attached LaTeX and BibTeX files.
Return only the optimized `.bib` file.
agentic_example.mp4
If the main.tex calls inputs from other .tex (e.g., with \input{...}), the newly generated ref_opt.bib will preserve the order of appearances in the main.tex with each inputted .tex as well.
(The dependent .tex files need to be placed in the same directory as main.tex.)
On top of version 0.4, skip any \input .tex file if not found.
Added support for the \include{...} command in addition to \input{...}, fixing missing citations when a LaTeX project uses \include to split its content across files.
Added Python 3.14 support and constrained bibtexparser to the compatible 1.x release series, fixing ModuleNotFoundError: No module named 'bibtexparser.bwriter' during fresh installations.
Add code-free SKILL.md
♥ Lastly executed on Python 3.14 on 2026-09-29.



