Maxwell's Treatise on Electricity and Magnetism, in Python

· 5 min read · maxwell, electromagnetism, python, open-source, physics

I digitized Maxwell's 1873 Treatise into three repos: a source edition, an OCR pipeline, and maxwell-modernized — a Python library covering all 866 articles.

In 1873, James Clerk Maxwell published A Treatise on Electricity and Magnetism. It unified electricity, magnetism, and light. One of its quiet punches is still easy to miss in the prose: the ratio of electromagnetic to electrostatic units is the speed of light.

I wanted that claim to be a function I could call.

from maxwell.config.constants import C
from maxwell.core.units import verify_speed_of_light_relationship

print(C)  # 2.9979e+10 cm/s
print(verify_speed_of_light_relationship())  # 1.0

That is Arts. 771–782, still answering in CGS-EMU — the unit system Maxwell used. The rest of the project exists so this is not a party trick. It is one article in a chain of 866.

The problem was not “write some Maxwell code”

Classical electromagnetism is not scarce. What is scarce is a path from the primary source to a result you can reproduce, with a citation you can argue with.

Scans drift. OCR invents glyphs. Article numbers get paraphrased away. A notebook that “does Faraday” is not the same as Art. 528.

I did not want a highlight reel. I wanted a pipeline you can inspect: scan → structure → executable math.

That is why this is three public repos, not one.

Three repos, three failure modes

Part Repo Job
1 Maxwell-Latex-Books Source edition of the 1892 Third Edition: article indexes, OCR extracts, architecture maps
2 maxwell-em-processor OCR + classification of the 1873 scanned volumes
3 MAXWELL-MODERNIZED-PROGRAM The product: Python re-implementation (pip install maxwell-modernized)

Despite the books repo name, there is no LaTeX edition in that tree. Indexes and maps. Not typeset volumes.

I split them because they fail for different reasons:

  • The books repo can be wrong about what article 528 is
  • The processor can be wrong about what the scan said
  • The program can be wrong about what the math does

A citation bug should not hide inside a multi-thousand-function tree. A Mathpix retry should not live next to Faraday induction.

Act I — get the words off the page

maxwell-em-processor is the unglamorous middle.

Input PDFs → Mathpix OCR → table-of-contents analysis → optional AI classification → organized output.

It keeps Maxwell’s own hierarchy: volume, part, chapter, article. It caches Mathpix so a 400-page rerun does not bill you twice. Retry plus a circuit breaker so a flaky API does not kill a weekend job. --simple if you do not want the classifier.

The 1873 scans (Archive.org Vol. I, Vol. II) and a readable OCR edition ship in the repo. Maxwell’s wording is public domain. I claim no copyright in the scans or the mechanical OCR.

This stage is where most “digitize the Treatise” projects stall: you have text, but you do not yet have articles.

Act II — know where you are in the book

Maxwell-Latex-Books is the edition layer. It is how I refuse to get lost.

What is actually in there:

  • Version-3 Markdown indexes for Parts I–IV — article numbers, titles, original pages
  • Architecture maps that send each article toward a Python module path
  • Structured OCR JSON for the 1892 Third Edition
  • First-edition OCR in the archive, from the same Archive.org volumes

Honest gap, said plainly: those Version-3 files are a navigational skeleton. They do not yet contain cleaned running text or equation bodies. The 1881 second edition is not processed. Next editorial phase is attaching cleaned text under those headings. That work is not done.

Maxwell 1892 is public domain. The modernization layer is CC BY 4.0.

If you want to argue with an article number, start here — not in the Python package.

Act III — make the Treatise run

MAXWELL-MODERNIZED-PROGRAM is the thing I want people to use. It shipped v1.0.0 on 2026-08-18.

pip install maxwell-modernized

The PyPI name is maxwell-modernized because maxwell was taken. The import stays maxwell.

The package layout follows the Treatise itself:

  • Part I Electrostatics → maxwell/electrostatics/
  • Part II Electrokinematics → maxwell/electrokinematics/
  • Part III Magnetism → maxwell/magnetism/
  • Part IV Electromagnetism → maxwell/electromagnetism/

Units stay CGS-EMU. Every public function is supposed to carry @maxwell_cite, so “which article is this?” is a query, not a comment you hope someone left.

Coverage the repo currently states (I have not re-run the suite in this writeup):

  • 866 / 866 articles
  • 1795 tests, 50 math validation checks, 66 SymPy verifiers
  • JAX adapters for batch evaluation and jax.grad

There is not a paper to cite yet. The library is the citeable artifact — see CITATION.cff in the repo.

Who this is for

Two audiences, same source:

  • Scholars and historians who want Maxwell as executable mathematics, not only prose
  • Developers and physicists who need a traced implementation of classical electromagnetic theory

If you came for a modern SI textbook in NumPy, this is the wrong tree. If you came to watch c fall out of the unit ratio, or to walk Faraday induction back to Arts. 528–530, it is the right one.

Why I keep projects like this

Same habit as the rest of my work: traceability under a hard budget. Here the budget is fidelity to a 19th-century primary source.

I would rather ship three honest repos — including the gaps — than one repo that pretends the OCR, the edition, and the physics are the same job.

Live URL once this is published: anthonymikinka.com/posts/maxwell-treatise-electricity-magnetism-python/