A Chrome (and Firefox) extension that lets you quickly copy LaTeX code (KaTeX or MathJax) from equations displayed on websites like ChatGPT, DeepSeek, or any blog using mathematical equations. It works simply by hovering over an equation and clicking to copy the LaTeX expression.
Version 1.1: Now it also works with with Wikipedia and Wikiwand images.
Version 1.2: Now it also works for MathJax v3 (when there is no LaTeX code in the HTML) via API.
Version 1.3: Dark mode enabled and replaced check emoji with SVG icon.
Version 1.4: New feature! Select text (that includes formulas), right click on it and a Copy as Markdown (with LaTeX) option will appear.
Version 1.5: Now with Typst support!
Version 1.6: A new config button in the popup UI that allows some basic customization (like choosing the theme or hiding the 'copy as' feature in the context menu).
You can use https://markdown-preview-katex.vercel.app/ to test this feature.
You can use https://typst-online.vercel.app/ to test this feature.
Generally any math, physics, or engineering-related blog or website. Some typical examples:
- KaTeX: ChatGPT, DeepSeek, Notion, Gemini...
- MathJax: Stack Exchange, ProofWiki...
You can check the javascript source code yourself. It loads after everything and is very fast and small sized. However if you want you can always customize in which hosts (websites) the extension loads or not:
This is done in chrome://extensions in the extension 'Details'.
Recommended websites to add
- https://chatgpt.com/*
- https://chat.deepseek.com/*
- https://math.stackexchange.com/*
- https://physics.stackexchange.com/*
- https://proofwiki.org/*
- https://*.wikipedia.org/*
- https://www.wikiwand.com/*
- https://mathoverflow.net/*
- https://*.notion.site/*
- https://publish.obsidian.md/*
- https://nbviewer.org/*
- https://gemini.google.com/*
- https://www.phind.com/*
- https://chat.mistral.ai/*
- https://librechat-librechat.hf.space/*
- https://www.perplexity.ai/*
- https://phys.libretexts.org/*
-
Content Script (
content.js):- For KaTeX
- Automatically detects all
<span class="katex">elements on the page. - Extracts the LaTeX code from
<annotation encoding="application/x-tex">.
- Automatically detects all
- For Gemini KaTeX
- Extracts LaTeX inside
data-mathattribute.
- Extracts LaTeX inside
- For MathJax
- Extracts LaTeX inside
<script type="math/tex">elements.
- Extracts LaTeX inside
- For MathJax v3/v4
- Injects page script (
mathjax-api.js) to extract LaTeX frommjx-containerelements via MathJax's API. Only possible via API and inject script because no LaTeX code present in the generated HTML.
- Injects page script (
- For Wikipedia
- Extracts LaTeX from
altattributes of images.
- Extracts LaTeX from
- For all of them
- Shows an overlay when hovering over the equation.
- Allows clicking to copy the code to clipboard using
navigator.clipboard.writeText(). - Uses an inline
<svg>to avoid external file dependencies.
- For KaTeX
-
CSS (
overlay.css):- Overlay styling: white background, subtle border and shadow.
- Large, readable text.
- Centered over the KaTeX formula.
pointercursor.
-
Extension declaration
manifest.json:- Injects
content.js,overlay.cssand the other scripts. - Sets information and permissions of the extension.
- Injects
-
Background script
background.js:- Handles context menu (right click). Needed to display the "Copy as Markdown" option when right clicking the selected text.
-
Selection script
selection-to-markdown.js:- A set of functions, workers and utilities to convert HTML to markdown while preserving our extracted LaTeX. Under the hood uses the
turndown.jslibrary and theturndown-plugin-gfm.jsGitHub-flavored markdown plugin for converting HTML to Markdown.
- A set of functions, workers and utilities to convert HTML to markdown while preserving our extracted LaTeX. Under the hood uses the
- Download the
srcdirectory (using for example download-directory.github.io). Rename it if you want. - Then go to
chrome://extensions(as if it were an URL) and in the top left click the 'Load unpacked' button and select thesrc(or whatever is named now) folder.
- Chrome Add-on page: https://chromewebstore.google.com/detail/copy-latex-katex-mathjax/lmhdbdfaadjfjclobmodomehekpjpkgn
- GitHub Repo: https://github.com/Mapaor/copy-latex-chrome-extension
- README as a website: https://mapaor.github.io/copy-latex-chrome-extension/
There is also a Firefox version of this extension: https://github.com/Mapaor/copy-latex-fireofx-extension
You can also use this extension in Brave and Arc (they support Chrome extensions by default).
I also plan to adapt this code for Edge and Opera and publish in their respective places.
A Safari version is not planned because publishing in Safari is ridiculously expensive.
Credits to @leander-ow for his dark mode contribution and to @ashigirl96 for suggesting and providing a working code implementation for the copy selection as Markdown feature.
This extension also works thanks to the following open source projects:
- Turndown - Library for converting HTML to Markdown
- tex2typst - Library for converting LaTeX to Typst
- markdown2typst - Library for converting Markdown to Typst
MIT License.
It is MIT Licensed so that anyone can customize it to their needs but please don't just copy-cat the code and publish it with a new name, it's weird.
If you have an idea for a new feature open an issue and let me know! Also if you have the time to implement a feature you want it would be great if you made a pull request.
Some minor things to fix or improve (for when I have the time):
- In the copy selection (both to Markdown and to Typst) feature fix the Wikipedia case (don't detect images that contain the
mwe-mathrelated classes as images). - Improve the documentation of the extension (the screenshots and GIFs are of previous versions).
- Text selection to Markdown: Select some text that includes equations, right click and a new option "[Extension Icon] Copy as Markdown" appears.
- Typst support: Pop up with a toggle between LaTeX and Typst
- Theme selection: Config option to choose the theme (light, dark or system)
- Hide option in context menu: Allow users to hide the copy selection feature when right-clicking (for those who don't need it and want a less clustered context menu).
- Custom delimiters:
Config option to chose between no delimiters (default),
$and$$,\(and\[, always$, or always$$. - Custom translations. Allow to replace the 'Click to copy', 'Copied!', 'Copy as Markdown' and 'Copy as Typst' messages to be replaced by custom ones.






