Making your first PDF with LaTeX and Sublime Text 2

This tutorial will walk you through the installation and setup of Sublime Text 2 for working with LaTeX. After installation we will create a simple PDF to make sure everything has been setup correctly. These instructions follow my steps installing Sublime Text 2 and setting it up for working with LaTeX on my PC running Windows 7. See Chaning’s tutorial for Mac-specific instructions. If you are one of the many moving from Sublime Text to Atom check out our new Atom tutorial on the same topic: Creating Your First PDF with LaTeX and Atom

Why Sublime Text 2?

Sublime Text 2 is a fast cross-platform text editor. For a preview of the beautiful editing/coding/writing future that awaits you go to Sublime is free to try, though you will occasionally be encouraged to purchase a license for $59.

Why LaTeX?

LaTeX is the standard for professional typesetting.

Installing LaTeX

[EDIT: This section was added to answer several comments] Installing LaTeX varies depending on your operating system. On Windows, TeX Live is recommended, but MiKTeX will also work. Here, we’re going to use TeX Live, simply click the link above and then download the file “” (see screenshot below). tug Next, find the file in your Downloads folder, right-click it, then select “Extract All …”. Confirm by clicking the “Extract” button. After the extraction is completed, the extracted folder should be displayed. Open the only folder (should start with “install-tl-” and end with the date you downloaded it). In theory you can run the Windows batch file “install-tl”; however, I received the “perl.exe has stopped working” error. What worked for me was to install using “install-tl-advanced” (see screenshot below), I also chose to “Run as administrator” (in the right-click menu) to install this for all users of my computer. install_tl Once the advanced wizard pops up, tweak any features you want to change. I toggled “Default paper size” from “a4” to “letter” and “Installation for all users” from “No” to “Yes”. Once you have made your adjustments, click on “Install TeX Live” (see below). install_tl_advanced Grab some coffee, this could take some time.

Install Sumatra PDF

Download Sumatra PDF from here (see below). sumatrapdf Double-click the downloaded file to install Sumatra PDF.

Add SumatraPDF to the path

For Sublime to open SumatraPDF for you when you build your PDF, we need to add the PDF viewer to your path. Adding SumatraPDF to your path allows your programs to open SumatraPDF without having to know exactly where you installed it. To add SumatraPDF to your path, right-click Computer from the desktop or the Start menu. Choose the “Properties” option. Select “Advanced system settings” from the menu on the left. Choose the “Advanced” tab and click the “Environmental Variables…” button near the bottom. In the “System variables” section, click on the variable named “PATH” and click the “Edit…” button. Place your cursor at the end of the text in the “Variable value:” field, add a semicolon, “;”, and enter the path to SumatraPDF. For me, the path was “C:\Program Files (x86)\SumatraPDF”. Click “OK” to accept your changes.

Install Sublime Text 2

Download Sublime Text 2 from Click on the appropriate version for your OS to begin the download (see below). st2 Install Sublime Text 2 (e.g., double-click the downloaded *.exe file).

Install Package Control

Install Sublime Package Control by copying the text below or by going here and following the instructions.

import urllib2,os,hashlib; h = 'eb2297e1a458f27d836c04bb0cbaf282' + 'd0e7a3098092775ccb37ca9d6b2e4b7d'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); os.makedirs( ipp ) if not os.path.exists(ipp) else None; urllib2.install_opener( urllib2.build_opener( urllib2.ProxyHandler()) ); by = urllib2.urlopen( '' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); open( os.path.join( ipp, pf), 'wb' ).write(by) if dh == h else None; print('Error validating download (got %s instead of %s), please try manual install' % (dh, h) if dh != h else 'Please restart Sublime Text to finish installation')

After copying the above text, open up Sublime Text 2, press CTRL+`, paste the copied text (CTRL+V), and press enter. You will need to restart Sublime Text 2 to complete the installation.

Install LaTeXTools

Open Sublime Text 2. Enter CTRL+SHIFT+P, to open the Command Palette. Start typing “install” then hit ENTER to select “Package Control: Install Package”.

Install Package
Type “install” in the Command Palette to pull up the Install Package option.
Once the new option list pops up (press CTRL+SHIFT+P if it is not open), type “latextools” until you see the LaTeXTools plugin selected. Hit ENTER to install LaTeXTools. [IMPORTANT: If you are having any issues, check the ReadMe link for OS-specific setup instructions.]

Directing the builder to TeXLive

The default within LaTeXTools is to build your PDF using the program from MikTeX. This is perfect if you installed MikTeX. However, if you installed TeXLive, you need to do one more thing to get things up and running. In Sublime Tex 2, go to the “Preferences > Browse Packages …” menu item. Open the LaTeXTools folder. Open the file “LaTeX.sublime-build”. Find the section that says:

 // *** BEGIN MikTeX 2009 *** "cmd": ["texify", "-b", "-p", "--tex-option=\"--synctex=1\"" ], "path": "", // *** END MikTeX 2009 *** 

Comment out the lines between “BEGIN MikTeX 2009” and “END MikTeX 2009” by selecting them, then pressing CTRL+/ (these were lines 72 through 77 for me). Scroll down to the TeXLive section and uncomment the lines between “BEGIN TeXLive 2011” and “END TeXLive 2011” (these were lines 89 through 94 for me) by selecting them and then pressing CTRL+/. Your build file should now look match the following snippet:

 // *** BEGIN TeXLive 2011 *** "cmd": ["latexmk", "-cd", "-e", "\\$pdflatex = 'pdflatex %O -interaction=nonstopmode -synctex=1 %S'", //"-silent", "-f", "-pdf"], "path": "C:\\texlive\\2011\\bin\\win32;$PATH", // *** END TeXLive 2011 *** 

Now, save the sublime-build file.

Your First PDF

Now that you have installed Sublime Text 2 (ST2) and LaTeXTools, open a new file in ST2 (using the menu or CTRL+N,CMD+N). Copy and paste the following LaTeX source into your new file:

\documentclass{article} \title{Title} \author{Your Name} \begin{document} \maketitle{} \section{Introduction} This is where you will write your content. \end{document}

Save the file (using the menu File>Save or CTRL+S,CMD+S on OS X) as first.tex. After saving, build the PDF (using the menu Tools>Build or CTRL+B, CMD+B on OS X). You should see the PDF previewer display your first PDF. Congratulations!

Next Steps

Create and use snippets in our next tutorial to increase your productivity.

LaTeX References