Zum Inhalt springen

Do you have your own LaTeX site? Would you like to add "Open in Overleaf" functionality to help it stand out? If so, you're at the right place!

Looking to quickly add a link from your blog? Easy options on our partners page.

One-click to open in Overleaf…

We've developed the tools you need to load LaTeX code and files from your website or blog directly into Overleaf.

See it in action: you can explore this feature on LearnLaTeX.org and throughout the examples available in our documentation.

To add similar functionality to your site, take a look at the sections below. If you have questions, please contact support and we'll be happy to help.


You can load a code snippet into Overleaf by passing it (or its URI) to https://www.overleaf.com/docs using a form or a link.

The most basic approach is to use a link:


You may also link to a project instead of a single LaTeX snippet by passing the location of a zip file for the parameter

Here are some links in action:
A LaTeX code snippet - A zipped project

Some more advanced methods of embedding and opening LaTeX content are listed below in the implementations section below. There are also a number of customisable features that can tailor the "Open in Overleaf" functionality to your needs. These can be found in the features section below.

Please contact support with any questions.


Post a Snippet by URI (URL)

You can post the URI of a file, and Overleaf will download the file and import it as the main file of the project. Here we pass the full path to this file for the snip_uri parameter. The file must be accessible from our servers. The file will be fetched using either HTTP or HTTPS, depending on the URI that you give it; other protocols are not yet supported. Files should be LaTeX files or zip format.

Here we pass the full path to this file for the snip_uri parameter:

This form can be implemented with the following code:

<form action="https://www.overleaf.com/docs" method="post" target="_blank">
<input type="text" name="snip_uri"
<input type="submit" value="Open in Overleaf">

Alternatively you can just use a link as described in the Overview section above. We recommend that you use encodeURIComponent, or an equivalent method on the server side to escape each parameter, but this is not absolutely necessary.

You can also upload multiple files using snip_uri[] array parameters like this:


And there's a snip_name parameter that you can use to override the name of each uploaded file, like this:


Base64 Data URL

It is possible to use data URL with base64 string as the snip_uri value:


For example, this is the same helloworld.tex file but encoded as base64:

This form can be implemented with the following code:

<form action="https://www.overleaf.com/docs" method="post" target="_blank">
<input type="text" name="snip_uri"
<input type="submit" value="Open in Overleaf">

Base64 strings can also represent compressed zip files containing multiple files. For instance, here's a simple case with two .tex files and a single .bib file:

This form can be implemented with the following code:

<form action="https://www.overleaf.com/docs" method="post" target="_blank">
<input type="text" name="snip_uri"
<input type="submit" value="Open in Overleaf">

URL-encoded snippet

URL encoding is useful if you submit using a hidden input field, as in this example. This avoids problems with newlines in the TeX source. This example posts the result of the PHP5 code:

urlencode("\\documentclass{article}\n\\begin{document}\nHello \$i\$ \& \$j\$.\n\\end{document}\n");

in the encoded_snip parameter. If using javascript, the encodeURIComponent function should be used (not the escape function, which has problems with internationalisation).

Raw snippet

If you submit from the server side or with AJAX you can use the snip parameter, which assumes no encoding. Another use case is submission from a textarea (which could be hidden using CSS); in this case you must escape HTML entities in the HTML source.

This form can be implemented with the following code:

<form action="https://www.overleaf.com/docs" method="post" target="_blank">
<textarea rows="8" cols="60" name="snip">

Bla bla bla bla :
A &amp;= B + C - D \\ \\
&amp;\phantom{= B + C \;}
+ D - E \\ \\
&amp;= F + G - H.
<input type="submit" value="Open in Overleaf">

Post from Formatted Code Box

This example shows how to extract the unformatted code from a CSS-styled code box and submit it to Overleaf. The key components are:

  1. The Javascript that defines the openInOverleaf() function.
  2. The form with id ol_form, which is used to POST the source as a URL-encoded snippet. Note that in this case you only need one form on the page, even if you have multiple codeboxes.
  3. The link in the code box that actually calls openInOverleaf().


Code: Open in Overleaf
g :=\left(
\mathbf{2^D} & \textbf{1} \\ \hline
\textbf{1} & \begin{array}{cc}
\boldsymbol{1^\alpha} & \textbf{0} \\
\textbf{0} & \boldsymbol{1^\beta}
\end{array} \\
Code: Open in Overleaf
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm,
  thick,main node/.style={circle,fill=blue!20,draw,font=\sffamily\Large\bfseries}]

  \node[main node] (1) {1};
  \node[main node] (2) [below left of=1] {2};
  \node[main node] (3) [below right of=2] {3};
  \node[main node] (4) [below right of=1] {4};

  \path[every node/.style={font=\sffamily\small}]
    (1) edge node [left] {0.6} (4)
        edge [bend right] node[left] {0.3} (2)
        edge [loop above] node {0.1} (1)
    (2) edge node [right] {0.4} (1)
        edge node {0.3} (4)
        edge [loop left] node {0.4} (2)
        edge [bend right] node[left] {0.1} (3)
    (3) edge node [right] {0.8} (2)
        edge [bend right] node[right] {0.2} (4)
    (4) edge node [left] {0.2} (3)
        edge [loop right] node {0.6} (4)
        edge [bend right] node[right] {0.2} (1);


The HTML required to add the examples above is:

<form id="ol_form" action="https://www.overleaf.com/docs" method="post" target="_blank">
  <input id="ol_encoded_snip" type="hidden" name="encoded_snip">
<dl class="codebox">
  <dt>Code: <a href="#" onclick="openInOverleaf(this); return false;">Open in Overleaf</a></dt>
      <code class="tex">

The JavaScript code for the openInOverleaf method, which should be included in a script tag is:

function openInOverleaf(a) {
  * Get the unformatted code from the formatted code box.
  * Using the browser's selection isn't ideal, because it clobbers whatever
  * the user may have had in their clipboard.
  * It's almost possible to use innerText, but that does not work on FF.
  * FF supports textContent, but that discards the newlines, which are
  * represented by BR tags in the formatted code. So, we have to walk the DOM.
  function unformat(e) {
    var ret = "";
    if (e.nodeType === 1) { // element node
      if (e.tagName === "BR") {
        return "\n";
      } else {
        for (e = e.firstChild; e; e = e.nextSibling) {
            ret += unformat(e);
        return ret;
    } else if (e.nodeType === 3 || e.nodeType === 4) { // text node
        return e.nodeValue;
  var code = a.parentNode.parentNode.getElementsByTagName('CODE')[0];
  document.getElementById('ol_encoded_snip').value =

The syntax highlighting in the code boxes is generated by highlight.js, but you can add your own manually with span elements if you prefer.


The features below are included to aid usability of the "Open in Overleaf" implementations, and may be customized to suit your preferences.


The code must be wrapped with a valid document in order to compile. If the code snippet does not have a \documentclass tag, it is wrapped in a standard document when it is imported:



The submitted snippet should be encoded using UTF-8. Windows newlines are converted to unix newlines.

TeX Engine

By default, Overleaf tries to detect which TeX engine to use, and it usually chooses pdflatex. If you would like to set the engine explicitly for your new project, you can pass an engine parameter with one of the following values: latex_dvipdf, pdflatex, xelatex or lualatex.

Main Document

By default, Overleaf tries to detect which document to use as the main .tex file, based on whether it contains a \documentclass. If you would like to override this behaviour, you can pass a main_document parameter with the name of the file. When supplying an array of snippets, you must also pass an array of filenames for this to work reliably.

Rich Text

There are two editing modes in Overleaf: Source mode and Rich Text mode. By default, new project are displayed in Source mode.

You can mark a project to default to Rich Text mode by passing a rich_text parameter with value true.

Note that the user can always switch between editing modes with one click, and their preference for each project is stored and has higher precedence over the default setting.


We add a short 'welcome' comment at the top of the snippet:

% Welcome to Overleaf --- just edit your LaTeX on the left,
% and we'll compile it for you on the right. If you open the
% 'Share' menu, you can invite other users to edit at the same
% time. See www.overleaf.com/learn for more info. Enjoy!