Repository navigation
Render the formulas locally, the Wikimedia Math API is gone - #2847
Merged
Merged
Conversation
Member
|
Thank you @monosans. That's a shame the chemical formulas will now be left behind. Maybe at some point, a Python module will come out, who knows. |
ziamath has no mhchem support, so convert the plain formulas to TeX first: molecules, charges, bonds, hydrates, plus signs and arrows. The others still only work from the cache.
Contributor
Author
|
I gave it a go anyway: most |
Member
|
Super cool! |
This was referenced Nov 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Wikimedia has shut down the Math API (Mathoid). It was deprecated in August and the endpoints were planned to be off after September (announcement, changelog). Now every
POST /media/math/check/...gets an empty 403 from their HAProxy, on en.wikipedia.org and on wikimedia.org, whatever the User-Agent, while the other REST endpoints still answer. So every formula missing fromsvg.gzends up as raw TeX in the dictionaries. In the RU dump of 2026-11-01 that's 37 errors, e.g.y = kx + bin "линейная функция" ord(x_{n}, x_{m}) < \varepsilon\in "фундаментальная последовательность". A build I did on 2026-11-16 still had them as SVG.This renders them locally with ziamath (pure Python, MIT, ships the STIX Two Math font):
em, andvertical-alignputs the baseline of the formula on the one of the text, like the Mathoid SVGs did withexfill="currentColor": no<symbol>and no IDs, so several formulas in one article can't clashsvg.set()and the[new SVG]logziamath has no mhchem support, so
<chem>goes through a smallchem_to_tex()first. It covers the plain formulas: molecules, charges, bonds, hydrates, plus signs and arrows. Anything else (states like(l), braces, other arrows...) raises, so those formulas still only work from the cache and log the same error as before. I checked it against mhchemParser 4.2.1, the parser MathJax uses: the same TeX (minus its�phantomspacing) for the 172 chemical-looking formulas ofsvg.gz. The 3<chem>errors of the RU dump ((CH3)2SO,(CH3)2S,Mg2+) render now.The dead
WIKIMEDIA_URL_MATH_*constants are removed, and the tests no longer mock the API.While at it: scour ends every SVG with a newline, which shows as a space in the HTML, so a formula followed by a comma read "... formula , ..." (e.g. диметилсульфоксид).
svg.optimize()strips it now.Testing
python:3.13-slimwith this branch installed fromrequirements.txt(ziamath 0.13, ziafont 0.11, latex2mathml 3.81.1)<math>or<chem>errors left,[new SVG]x36 (33 math, 3 chem)\big(...\big)comes out a bit taller than in MathJaxpytest tests/test_2_utils.py -k "formula or convert", theutils.pydoctests,ruff format --check,ruff checkandmypypass