Combining LaTeX and Illustrator

Adobe Illustrator is a powerful vector graphics program with EPS as native graphics format and is therefore ideally suited to create figures for LaTeX. This article describes how to include LaTeX output (e.g. mathematical formulas) into figures or posters created by Illustrator. In addition I present a way to use the combination Illustrator+LaTeX for creating slide presentations.

The work has been tested with Windows XP, MikTeX 2.8 and Illustrator CS.

Installing LaTeX fonts on the system

The LaTeX fonts have to be installed as system wide fonts, otherwise Illustrator (as other programs) cannot deal with LaTeX output. The Windows compatible LaTeX font files have the extension *.pfm. Localize these files on your LaTeX installation, e.g.

C:\Programs\MiKTeX 2.8\fonts\type1\public\amsfonts\cm

and copy it to the Windows font directory, e.g.

C:\WINDOWS\Fonts

Instead of just copying you can also download and install the free program Adobe Type Manager Light (ATM). In ATM specify the font source directories, select the fonts and click Add.

Now the LaTeX fonts appear in the Windows font list and can be used by any Windows program.

Exporting LaTeX to Illustrator

As Illustrator is able to import individual pages form PDF files, you can compile any LaTeX code to PDF (by DviPS or PDFLaTeX) and import it in Illustrator. This way you can include LaTeX formulas in your figures or posters in true vector font quality.

Known bugs

For some few characters in math mode (e.g. slash ‘/’, point ‘.’, comma ‘,’) there is a confusion between Illustrator and LaTeX about the character codes. The LaTeX expression $1/2$ appears in Illustrator with a small triangle instead of the slash. In this case you have to edit the text expression in Illustrator and select the correct symbol from the Glyph list (Window -> Type -> Glyphs).

Simplification by Illustrator scripts

Illustrator is programmable by JavaScript. To install a script just copy it to

C:\Programs\Adobe\Illustrator CS\Presets\Scripts
German version: C:\Programme\Adobe\Illustrator CS\Vorgaben\Skripte

After the next start of Illustrator the script appears in the menu File -> Scripts. If you edit an existing script you don’t need to restart Illustrator. Documentations of Illustrator JavaScript can be found here.

Illustrator script: LaTeX

The script LaTeX.js prompts the user to enter a single line of LaTeX code, e.g.

\[ f(x)=\frac{1}{\sqrt{1+x^1}} \]

After clicking OK the code is automatically compiled, converted to PDF and copied into the currently opened Illustrator document in the middle of the current view.

The script requires pdflatex.exe to be installed. You have to make sure that the location of pdflatex.exe is included in the system path. Alternatively you can edit the first line of the script and specify pdflatex.exe with full path.

Illustrator script: LayersToPDF

For me it was always a pain to include LaTeX math into PowerPoint or similar programs. On the other hand, using plain LaTeX to create slide presentations it was a pain as well to correctly position graphics and figures. What you need is a WYSIWYG environment which is capable of handling LaTeX expressions.

The Illustrator script LayersToPDF.js presented here is an attempt in this direction. It converts the layers of a single Illustrator file into pages of a PDF file, i.e. slides of a presentation. The bottom layer becomes the first slide, the top layer the last.

You can exclude certain layers or you can combine several layers to a single slide by the following layer naming conventions:

• layer names starting with a minus sign do not create a slide.
• to include other layers just add their names with a plus sign.

Example: The Illustrator document contains 7 layers with the following names:

slide5+bkg
-trash
slide4+slide3+bkg
slide3+slide2+bkg
slide2+bkg
slide1+bkg
-bkg

The script creates a 5 page PDF with the following pages:

page 1: bkg + slide1
page 2: bkg + slide2
page 3: bkg + slide2 + slide3
page 4: bkg + slide3 + slide4
page 5: bkg + slide5

The first alphanumerical part of each layer name (e.g. “bkg”, “slide1”, “slide2″…) is used in the script to identify the layer. The additional names (e.g. “+slide3+bkg”) refer to other layers and can be given in any order. In this example the background for all slides is defined on the bottom layer called “-bkg”. As it starts with the minus sign it doesn’t create an own slide. It is just included into other slides. The layer “-trash” is not used at all. Page 2 of the PDF file displays layer “slide2” and the background. On page 3 layer “slide3” is added. On page 4 layer “slide4” is added and layer “slide2” is removed. If you want to keep “slide2” you have to repeat it in the layer name, i.e. “slide4+slide3+slide2+bkg”.

If you create a presentation you should set the page format of your document to a 4:3 ratio, e.g. width 200mm and height 150mm.

Some technical issues

Illustrator is not able to create a multi page PDF by itself. Therefore the script first creates a number of single page PDFs which are afterwards combined to the final multi-page PDF by an external tool. I use the command line tool pdfpg.exe from verypdf.com. The program can be downloaded here. It is actually shareware but the included command line version pdfpg.exe seems to be free. You should add the location of pdfpg.exe to your system path or specify the full path in the first script line.

The script successively prepares all individual slides and exports them to PDF files. If the Illustrator file is named mydoc.ai the PDF files mydoc_1.pdf, mydoc_2.pdf etc. are created. The final multi-page PDF is called mydoc.pdf.

In order to obtain small and compact files the PDF option preserveEditability is turned off, which means that only the basic PDF data is saved and no additional Illustrator specific information. This works only if the layers not used on a particular slide are deleted and not just hidden. Therefore the script at first saves the original Illustrator file and reloads it after each PDF export.

To save time the script asks at first, which pages are to be converted. This way we don’t have to wait for a whole rebuild if just a few pages have been changed. Please mind that the other pages should already exist from a previous script call because at the end of each script all single page PDFs are merged again into the final multi-page PDF.

Known bugs

The script fails if too many pages are converted in a single run (observed with Illustrator CS). Then the script aborts with an error message which makes no sense to me. It does not depend on the layer content and is probably caused by some memory overflow in Illustrator. However, you can live with it by calling the script again and continuing with the page where the script stopped before.