Setting up LaTeX on Mac OS X
Update (21 Sep 2007): TextMate’s LaTeX bundle has been significantly improved and can now be configured using a Preferences dialog which is available from the Gear menu. My recommended preferences: set default Engine to pdflatex, enable use Latexmk.pl, set “View in” to Skim, enable “Show PDF automatically” and “Keep log window open”.
I will write an updated article that includes all these changes when time permits.
Update (3 Aug 2007): PDFView, the PDF viewer application that has been recommended in a previous version of this article been discontinued. I have updated the article to use the Skim viewer, which is an excellent replacement for PDFView.
For using LaTeX on any computer system, you need 3 essential pieces of software:
- a text editor for editing your LaTeX source files,
- the LaTeX program for processing your LaTeX source files into typeset PDF documents, and
- a PDF viewer program for previewing and printing your documents.
There are plenty of text editors, PDF previewers and LaTeX distributions available for Mac OS X platform.
My suggestion is to base your LaTeX environment on the TextMate editor. TextMate is not only a highly customizable, general purpose text editor, it also provides excellent LaTeX support and integrates tightly with the Skim previewer. This combination of tools, lets you use LaTeX in a convenient and Mac-like way.
Installing the software
Install LaTeX
LaTeX is open-source software, hence you can download and install LaTeX for free. If you are already using Macports or Fink for installing Unix software under OS X, I recommend to install LaTeX using these package managers. Macport users install LaTeX with port install tetex, Fink users use the command fink install tetex.
If you are neither using Macports nor Fink, I recommend to download MacTeX, which is a precompiled LaTeX distribution for OS X. MacTeX provides a full LaTeX installation plus a number of additional tools. Quoting from the MacTex website:
MacTeX.dmg is an install package for Apple’s installer. The package contains the complete TeX Live 2007 distribution of TeX, Ghostscript, ImageMagick, and the following front end programs : TeXShop, LaTeXiT, BibDesk, Excalibur, and i-Installer. A custom install option allows users to bypass some of these packages if desired.
Install Skim
I highly recommend to use Skim for viewing PDF files generated by LaTeX, since it supports tight integration with your LaTeX text editor. Skim is also an open-source application can be downloaded from the Skim website. Download and install Skim. Open Skim’s preferences dialog, select the Sync tab and make sure that the “Check for file changes” option is enabled and that PDFSync support is set to the TextMate preset.
Install TextMate
TextMate is a popular text editor for OS X. While the editor itself is commercial, TextMate has a very lively open-source developer community that provides extensions, called bundles, for many different purposes. By default, TextMate ships with an excellent LaTeX bundle. You can download a free trial version from the Textmate Website and purchase a full version for 39€.
For my recommended setup you need to set a few preferences for TextMate and the LaTeX bundle. Open TextMates Preferences dialog and make the following settings:
In the Software Update dialog, enable automatic updates to the Cutting-Edge version for TextMate. This configures TextMate to update always to the latest versions of the application and the bundles. Don’t be affraid, TextMate’s cutting-edge versions are generally very stable.
In the Advanced menu and select the Shell Variables tab. Use the plus button to add two variables named TM_LATEX_COMPILER and TM_LATEX_VIEWER. Set TM_LATEX_COMPILER to the value “latexmk.pl” and set TM_LATEX_VIEWER to “Skim” (both without double quotes).
Your LaTeX editing environment is now setup and ready to be used.
Edit and compile your LaTeX documents to PDF
Run TextMate and start editing your LaTeX document. You may either start from an empty file or use one of the templates provided in the “File → New from Template → LaTeX” menu.
You can see the actions provided by the LaTeX bundle by clicking the gear symbol in the status bar
and selecting the LaTeX bundle. Each command is also labeled with its keyboard shortcut.Make sure, that the LaTeX language mode is enabled. You can select the language mode in the dropdown menu of TextMate’s status bar.
For compiling your document with LaTeX press ⌘R. Alternatively, you could also select “Typeset & View PDF” in the LaTeX bundle menu. TextMate shows the log messages, warnings and errors generated during the compilation in a popup window. TextMate automatically opens Skim if the LaTeX compilation was successful.
If errors were raised during compilation, you can jump to the respective line in your LaTeX source by clicking on the error message in the compilation popup window.
For enabling the integration of TextMate and Skim you need to use the pdfsync package by including \usepackage{pdfsync} in the preamble of your document. With pdfsync enabled you can press ⌃⌥⌘O (or use the bundle’s “Show in PDFViewer (pdfsync) command”) to jump to the matching place in the PDF file. Vice versa, when Shift-Command-clicking on a location in Skim TextMate is showing the matching paragraph in the LaTeX source.
Detailed documentation on the LaTeX bundle and its configuration is available with the “Help” action of the LaTeX bundle.
Various remarks:
- TextMate provides very good support for UTF8 encoded text. If you are writing LaTeX texts in languages requiring accented letters or umlauts, you should add the following preamble to your document (replace french with your language):
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage[T1]{fontenc}
The inputenc package allows you to directly type accented characters in the LaTeX source, i.e., you can simply type ä instead of \"a. Further, the fontenc package ensures that hyphenation also works with words with accented letters.
- Since PDF is the standard file format for vector graphics and text in OS X it is natural to use the PDF-based pdflatex tool-flow, as suggested in this article. This implies, that all the graphics you are including with \includegraphics in the LaTeX document are expected to be also in PDF format.
Nice info, thanks for the post!
Thanks for this post. I translated article to spanish.
Regards,
Nelson Piedra
nopiedra.wordpress.com
[...] Quieres escribir Papers, ven a Instalando LaTeX para MacOSX Junio 26th, 2007 — nopiedra [...]
Very nice article! Just one remark: pdfview is superseded by skim. But those who go to the pdfview webpage will notice anyway.
Patrick, thanks for the comment. You are right, PDFView has been discontinued and I have added a comment to the article.
Thanks – just started with latex yesterday (advised by my brother) and found all the hints I needed to get started here.
I think I’ve followed the directions exactly, but when I do command-R, TextMate shows the result in its own viewer instead of Skim. Am I doing something wrong? My intuition tells me that it has something to do with the cutting edge version of TextMate:
[CHANGED] Latex bundle: The Typeset & View command has received a major overhaul. Behavior is primarily controlled via the new preferences dialog (rather than environment variables) although TM_LATEX_MASTER can still be used. Options can also be specified via the %!TEX syntax (see Help command for more). (Brad Miller)
Hi Kevin. You are right. The LaTeX bundle has been improved and needs some additional configuration that can conveniently made using a graphical preferences panel. I have added a brief tutorial at the top of this article.
[...] fortælle om den lille guide jeg fulgte for at få latex til at spille sammen med Textmate også. Læs omkring den her Posted: 07 Nov, 2007 | Categories: OS X , latex By: Lauer. [...]
I am using Mac OS X 10.5.1
teTeX failed to build due to an undeclared dependancy on openmotif. So after the failed install, I did the following to get it to install
sudo port clean –work teTeX; sudo port install openmotif teTeX
In the event that anyone is reading this blog, can I get some help with this LaTeX/Textmate error?
Error: Could not open /bin/sh: line 1: kpsewhich: command not found to check for packages
This is most likely a problem with TM_LATEX_MASTER
I have followed the installation instructions above, but still get that error message. Thanks for any help. mike
Mike – it looks like the LaTeX bundle cannot find your LaTeX related binaries on the search path. Add the following line to the file .bash_profile in your home directory and you should be set:
export PATH=/usr/texbin:$PATHAnother update: teTeX has been discontinued by its author. People on OS X should use MacTeX http://www.tug.org/mactex/ for extensive UTF8 support, look at XeTeX.
I am having trouble getting the clicking between Skim and Textmate to work as you describe (i.e. shift-cmd click in Skim to go to line in Textmate). Is there any settings I should be aware of to make this work?
Thanks.
Dan – No, it should work out of the box if you have a) included pdfsync using usepackage{pdfsync} in the preamble of your LaTeX document, and b) selected the TextMate preset in Skim’s Syn Preferences.
I have been using TextMate for LaTeX for a while, but one thing that frustrates me is that I could not find a way to comment a bunch of lines short of entering % manually at the beginning of each line. Any pointers would be very much appreciated. Thanks.
Tamer – There’s an easy solution for this: you can use TextMate’s column selection mode. Select all lines you want to comment with the mouse or the keyboard. Press the “alt” key to toggle from line to column selection. Your cursor will turn into a line spanning all lines of the selection. Now press % for adding the comment character.
For more information on column selection refer to Section “4.7.2 Column Selections” of the built-in TextMate help.
Thank you very much Christian. I would have never guessed to use the column mode for this.
Hi,
I’ve been using TeXShop for some time now. I like it but can’t say I love it. Do you know it and how does it compare to TextMate in your opinion? (given that it’s always a bit of trouble to learn a new editor well…) Are there any other editors (I use only LaTeX) that you would recommend?
I would be looking in particular for a nice functionality on moving between different parts of the text, so an editor which can set bookmarks, hopefully lists the sections and/or defined labels etc etc.
Many thanks in advance
Jan
Jan – I have never used Texshop, but TextMate supports your wish list quite well. The only real alternative I see is Emacs, which I have used extensively for many years. Emacs has excellent LaTeX support though the AUCTeX and RefTex packages. Emacs caters to a very specific breed of users, but if you like the Emacs way of doing things, it is a very good and simple to use environment for typesetting in LaTeX.
Jan,
IMO, The power of TeXShop lies in its simplicity. If you’re beginner to LaTeX I would recommend learning to use it through TeXShop first and move to TextMate later, after you’re comfortable with the markup. I’m still learning TM and LaTeX and find myself distracted at times with TM’s vast functionality. In effect, I am less productive with TM because it’s diminishing my LaTeXing speed. TM is great but it takes some time to get comfortable with it.
A note: pdfsync seems to break the p-width in tabular
Tamer,
Another way to comment a bunch of lines in TM is to select the lines to be commented and hit “Cmd-/”. That command works in most file modes and uses the appropriate comment character.
I’m having trouble with UTF-8 characters. For example, if I put a phi in my source
here's a phi: ϕ, I get an error:I have the following in my header:
Suggestions?
Gaius, your headers look good, I don’t see anything wrong. But there are better places to ask these kind of questions, e.g, the comp.text.tex newsgroup.
A very useful blog! Nice
I might also add that the excellent MacTex distribution is both well-developed and well-supported. As I write, the 2009 version is about to be released. Well, the maintainers keep promising…
In the meantime, the 2008 version of MacTex is working well for me. It’s a decent alternative to the fink or gwTeX installs. I believe both of these are based on the teTeX distribution, which Thomas stopped supporting a year or two ago.
Thanks for the post!
Hello,
is it possible to change the PDF Viewer to Adobe Reader /Acrobat? These are the only ones, which play sounds and movies (by using the movie15 package for example).
Thanks in advance
No, I think it’s in the current version of the LaTeX not possible to setup the PDF viewer to Acrobat. But this doesn’t make any sense in my view anyway, as Acrobat is very slow compared to the other viewers.
This is very strange, because TeXShop is able to use Acrobat…
But Acrobat is the only player, which supports playback of sound-files. (unfortunately skim won´t). Thats why I need it.
Noone any Idea?