Chrome extension that prevents machine translation from corrupting mathematical notation and repairs recognized translated LaTeX text/units.
Try the unit-repair demo · Reproduce the unit repair · Broader v2 implementation (test)
| Input LaTeX | Output from main |
|---|---|
v = 12\,\mathrm{км}/\mathrm{с} |
v = 12\,\mathrm{km}/\mathrm{s} |
R = 4\,\mathrm{кОм} |
R = 4\,\mathrm{k\Omega} |
E = mc^2 + \alpha |
unchanged |
These examples execute the actual transformation functions with no translation service. They show recognized unit normalization, not a simulated browser-translation result.
Reading a translated physics problem should not require deciphering damaged notation. MathShield separates rendered formulas from prose translation, then repairs selected unit symbols and text commands in the underlying LaTeX.
flowchart LR
A[Rendered MathJax nodes] --> B[Mark notranslate]
C[Browser translation detected] --> D[Inspect LaTeX scripts]
D --> E[Normalize units and selected text]
E --> F[Reprocess with MathJax v2]
- A MutationObserver protects existing and newly inserted
.MathJax,.MathJax_Previewand.MathJax_Displaynodes. - Prefix-plus-base-unit matching normalizes selected Cyrillic forms, including
км,сandкОм. - Text handling is restricted to selected LaTeX commands;
\mathrmis excluded from word translation. - The MV3 background worker requests MathJax v2 reprocessing in the page's main JavaScript world only after source changes.
node scripts/demo.cjs
node --test scripts/translation-observer.test.cjs
node --check content.js
node --check background.jsThe fixture reports three passing examples, including an unchanged formula. It tests pure transformations, not Chrome's translation UI or an installed extension.
Clone this repository, open chrome://extensions/, enable Developer mode, choose Load unpacked, and select the repository directory. Translate a page containing MathJax v2 source scripts to exercise the runtime flow.
main targets MathJax v2 reprocessing and selected Cyrillic mappings. It does not provide universal MathJax, KaTeX or language support. Regex text extraction does not parse arbitrary nested LaTeX. Browser translation detection relies on translated-ltr/translated-rtl classes. The translation observer handles both already-translated pages and later class changes.
The current text translation path sends extracted Cyrillic words to translate.googleapis.com using the browser language. Failed translations are silently skipped. Review the broad page permissions in manifest.json before installing.
The separate test branch implements a broader parser, a generated locale-aware unit database and browser regression fixtures. Its database validator passed during the audit; that does not certify all locale/engine combinations or make those features part of main. No branch was automatically promoted.
AI tools were used during development for debugging, brainstorming and the project logo, as disclosed in the previous README.