Add an "Open in Overleaf" button in HTML or React

Overleaf is a browser-based LaTeX editor, so readers can compile and edit a document without installing a TeX distribution. If you publish LaTeX examples, a button that opens the file straight in Overleaf saves readers from copying and pasting.
How it works
Section titled “How it works”Overleaf accepts files at https://www.overleaf.com/docs. There is no API key or authentication step on your side: you pass the location of the file in the snip_uri parameter, and Overleaf downloads it and creates a new project in the reader’s account (prompting them to log in if needed).
https://www.overleaf.com/docs?snip_uri=<url-encoded URL of a .tex or .zip file>Things to know:
- The file must be publicly reachable over HTTP or HTTPS, for example a
raw.githubusercontent.comURL. A GitHub page URL (github.com/.../blob/...) returns HTML, not the.texfile. snip_urican also point to a.zip, which is how you open a multi-file project (e.g. a.texfile plus images).- URL-encode the value. A file URL that contains its own
?or&will otherwise be cut off. - Optional parameters include
engine(pdflatex,xelatex,lualatex,latex_dvipdf) andmain_documentfor zips with more than one.texfile.
Plain HTML
Section titled “Plain HTML”<a href="https://www.overleaf.com/docs?snip_uri=https%3A%2F%2Fraw.githubusercontent.com%2FFriendlyUser%2FLatexDiagrams%2Fmaster%2FBlogDiagrams%2FbuildingDapp.tex" target="_blank" rel="noopener noreferrer" style="display: inline-block; background-color: green; color: white; padding: 8px 16px; border-radius: 4px; text-decoration: none; font-size: 16px;"> Open in Overleaf</a>Overleaf’s developer page also shows the same thing as a <form method="post"> with a snip_uri field, which avoids encoding the URL by hand.
From Python
Section titled “From Python”Handy for opening a generated file during development. quote(..., safe='') encodes the : and / in the file URL.
import webbrowserfrom urllib.parse import quote
file_url = "https://raw.githubusercontent.com/FriendlyUser/LatexDiagrams/master/BlogDiagrams/buildingDapp.tex"webbrowser.open(f"https://www.overleaf.com/docs?snip_uri={quote(file_url, safe='')}")React component
Section titled “React component”const defaultStyle = { display: "inline-block", backgroundColor: "green", color: "white", padding: "8px 16px", borderRadius: "4px", textDecoration: "none", fontSize: "16px",};
export function OverleafButton({ texUrl, engine, children = "Open in Overleaf", style = defaultStyle }) { const params = new URLSearchParams({ snip_uri: texUrl }); if (engine) params.set("engine", engine);
return ( <a href={`https://www.overleaf.com/docs?${params}`} target="_blank" rel="noopener noreferrer" style={style} > {children} </a> );}URLSearchParams does the encoding, so you can pass the raw file URL. In an MDX page (Next.js or Nextra) it is used like this:
<OverleafButton texUrl="https://raw.githubusercontent.com/FriendlyUser/LatexDiagrams/master/BlogDiagrams/buildingDapp.tex" />The earlier version of this component built the URL without encoding, appended .tex to whatever was passed in, and set target="\_blank" (with a stray backslash), which opened a window named \_blank instead of a new tab.
References
Section titled “References”© 2026 David Li · Home · Blog · RSS ·Classic site · Built with Astro, Starlight and three.js · Logos:Font Awesome Free (CC BY 4.0)