Skip to main content

Convert PDF to Markdown using Google Gemini. Optimized for academic papers with math.

Project description

gemmd

Convert PDF to Markdown using Google Gemini. Built for academic papers and textbooks with heavy math.

Why gemmd?

Most PDF-to-Markdown tools rely on OCR or layout analysis, which butcher mathematical notation. gemmd takes a different approach: it feeds PDF pages directly to Gemini's multimodal model, which reads the document like a human would — understanding structure, math, and context all at once.

Designed for:

  • Research papers with LaTeX-heavy equations
  • Textbooks with theorems, proofs, and definitions
  • Any PDF where math fidelity matters

Key features:

  • Inline ($...$) and block ($$...$$) math preservation with \tag{} numbering
  • Concurrent chunk processing with correct ordering
  • Smart sentence-boundary merging across page breaks
  • Batch mode — convert an entire folder in one command
  • Graceful partial failure handling (failed chunks get visible markers, not silent drops)
  • Post-conversion verification (page coverage + PDF outline section check)
  • Academic post-processing: theorem/lemma normalization, duplicate heading removal, notation cleanup
  • Cross-platform: works on macOS, Linux, and Windows

Installation

Requirements: Python >= 3.9

pip install gemmd

Or install from source:

git clone https://github.com/ktl-ao/gemmd.git
cd gemmd
pip install -e .

Setup

gemmd requires a Google Gemini API key. Get one for free at Google AI Studio.

Quick start (interactive):

gemmd setup

This will prompt you for your API key and preferred default model, then save to ~/.config/gemmd/config.

Or configure individually:

gemmd config key YOUR_API_KEY          # set API key
gemmd config model gemini-2.5-pro      # set default model
gemmd config                           # view current config

You can also use environment variables (GEMINI_API_KEY, GEMMD_MODEL) or a .env file in your working directory.

Config resolution order

Setting Flag Env / Config key Default
Model --model GEMMD_MODEL gemini-2.5-flash
API Key GEMINI_API_KEY

Priority: CLI flags > local .env > ~/.config/gemmd/config > defaults.

Usage

Single file

gemmd paper.pdf                          # → paper.md
gemmd paper.pdf -o notes.md              # custom output path
gemmd paper.pdf -m gemini-2.5-pro        # use a different model
gemmd paper.pdf --chunk-size 5           # 5 pages per chunk (default: 3)
gemmd paper.pdf -c 10                    # limit to 10 concurrent requests

Batch mode

Run gemmd with no arguments to convert all PDFs in the current directory:

cd ~/papers
gemmd
  • Skips files that already have a corresponding .md
  • Continues on failure — check output files for [!!! MISSING CONTENT !!!] markers

List available models

gemmd --list-models

Options

Flag Short Default Description
--output -o <input>.md Output file path
--model -m gemini-2.5-flash Gemini model to use
--concurrency -c 20 Max concurrent API requests
--chunk-size 3 Pages per chunk
--list-models List available Gemini models and exit

Commands

Command Description
gemmd setup Interactive first-time configuration
gemmd config View current configuration
gemmd config key <KEY> Set API key
gemmd config model <MODEL> Set default model

How it works

  1. Split — PDF is divided into chunks (default: 3 pages each)
  2. Transcribe — Chunks are uploaded to Gemini concurrently with a carefully tuned prompt for academic content
  3. Merge — Results are reassembled in order with intelligent sentence-boundary detection
  4. Post-process — Regex pipeline normalizes theorems, deduplicates headings, fixes LaTeX artifacts
  5. Verify — Page coverage check + PDF outline cross-reference to detect missing sections

If any chunks fail (rate limits, timeouts, etc.), gemmd inserts visible [!!! MISSING CONTENT !!!] markers and exits with code 1, so you can re-run to fill gaps.

Cost

Using gemini-2.5-flash (default), converting a typical 30-page paper costs fractions of a cent. The Gemini API free tier is generous enough for most personal/research use.

License

MIT

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

gemmd-0.1.0.tar.gz (15.6 kB view details)

Uploaded Source

Built Distribution

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

gemmd-0.1.0-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file gemmd-0.1.0.tar.gz.

File metadata

  • Download URL: gemmd-0.1.0.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.23

File hashes

Hashes for gemmd-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b0f3527010ba480259648a97ca48ef680cf197485489c0c294479dbf9748a3a3
MD5 c49dff3359bcfbc9a20ad3930bab34f6
BLAKE2b-256 c7e380f0f248019ddaa5ef10bd5d20deb39e15764f6c1301230a313d9336383f

See more details on using hashes here.

File details

Details for the file gemmd-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: gemmd-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.23

File hashes

Hashes for gemmd-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 82fd8aa59005713319cecb65d72412f6287ad3b00eb6685d36879aa1d2e5b91e
MD5 a9560530b2f8edd9ea62b9e0397f3530
BLAKE2b-256 d54c8400753dad8e3162749e02e4c786fa042032d7f49239b8d16336b14b7e3e

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