#### Previous topic

Free math and stats programs

#### Next topic

Ordinary Differential Equations with Maple

# Introduction to LaTeX¶

## Introduction¶

TeX is a type setting program developed by Donald Knuth. Many books that you have read used the TeX software to set the characters on the page correctly. LaTeX is a set of “standard” macros for TeX that make using it much more friendly and straightforward. Most people that know LaTeX wouldn’t characterize it as “friendly” or “straightforward” though. Most will tell you it has a “steep learning curve.” This is basically a nice way of saying that the syntax is a big hairy beast to tame and that you should expect to get wild results (huge images, equations that just walk right off the page) until you have used it for a while. What follows on this page is a painstakingly in depth description of setting up either your Windows computer or your Linux computer for using free LaTeX tools available on the internet.

Throughout this page, I reference a number of different file types, so if you’re not familiar with them here’s a list:

• TeX or .tex - The LaTeX file you are turning into a document
• PDF or .pdf - Adobe’s Portable Document Format file type. This is what most people want to make with LaTeX.
• PS or .ps - PostScript file. This is a file more commonly seen on UNIX systems, on which it is used for printing. LaTeX can create these files from TeX files as well.
• DVI or .dvi - DeVice Independent file. This is sort of the open source community’s version of PDF files.
• JPG or .jpg/.jpeg - A common graphics file I’m sure most of you are familiar with.
• PNG or .png - Portable Network Graphics file. A file format more commonly seen on Linux systems. Its a lot like an open source JPG.
• EPS or .eps - Encapsulated PostScript file. This is sort of a hybrid image/text file format. Maple exports all of its graphs to EPS when you export a Maple worksheet as a LaTeX source file.

## Setting up LaTeX in Windows¶

First of all, if you don’t already have Adobe Acrobat reader, download and install it now. You only need the free reader to view PDF files.

c:\texmf

and

c:\localtexmf

You are given the option of creating the second one (localtexmf), and I highly recommend that you do, especially if you plan on creating PDF files from Maple.

Okay, so now you have Acrobat Reader, MikTeX, GhostScript, and GSView installed. There is a nice, tidy way of accessing all of these programs called an Integrated Development Environment (IDE), and the best completely free one for Winidows I have found for TeX is TeXnicCenter. When you install TeXnicCenter it should tell you that it has detected MikTeX on your system and ask if you want to set TeXnicCenter up for use with it. It is absolutely critical that you say yes to this question. After the install, when you run TeXnicCenter the first time it will take you through a configuration wizard. The only really important thing to do here is to point it to your PostScript viewing program, GSView. If you chose all of the default options when installing GSView you’ll want to point it to:

C:\Program Files\Ghostgum\gsview\gsview32.exe

## LaTeX in Linux¶

Unless your Linux distribution is somewhat in the stone age, it most likely has a LaTeX package available. The program you want to look for is called teTeX. Redhat, I know, has an rpm that will set everything up for you that comes on the CDs. I don’t use an IDE of any kind for LaTeX in Linux, opting instead for VIM or gEdit and command line tools. Just install the teTeX package and grab the example below. The commands you want to be aware of are:

latex [.tex file] - Create a .dvi file from the .tex file

pdflatex [.tex file] - Create a .pdf file from the .tex file

dvipdf [.dvi file] - Create a .pdf file from the .dvi file

(see the note on graphics for why you might want to use dvipdf)

For the example below, you would put the .tex file and the .jpg file in the same directory, then just

pdflatex texexample

(the extension isn’t required for latex or pdflatex). Also see the note below about graphics in LaTeX.

## An Example TeX file and instructions¶

Now you’re ready to make PDF files! If you’re unfamiliar with LaTeX, check out this example source file that introduces a lot of basic stuff like equations, sections, graphics, and references (here's the JPG graphic as well. If you want to build the example both files need to be in the same directory). Building a PDF from this file in RedHat Linux gives this PDF file. To build a TeX source file in TeXnicCenter open a .tex file and locate the ‘build current file’ button. To the left of this button is the dropdown menu ‘output profile’ where you can select to create DVI, PS, or PDF files. Choose PDF for the example since DVI and PS need EPS files for graphics, and we’re using JPG. See the note below for more on graphics in LaTeX.

## Setting up LaTeX for making PDF files from Maple¶

Getting a LaTeX file from Maple is easy. Just open your Maple file, and choose ‘file -> Export As -> LaTeX’. If you have plots, then they will be exported as EPS files. Then you can use the method described below to create a DVI, then a PDF. Before you do this, however, you need to get the Maple style files loaded into either MikTeX (Windows) or teTeX (Linux).

To do this in MikTeX, go to the localtexmf directory that you created during the MikTex install (the default being C:\localtexmf) and create any of the following directories you don’t have so that you have a directory structure that looks like this:

C:\localtexmf\tex\latex\maple

On my computer I had to create the ‘latex’ and ‘maple’ directories. Now copy the Maple style files from their installed location to the directory that you just made. That is, copy all of the files that are in here:

C:\Program Files\Maple 7\ETC

(default directory, it should contain .sty files)

to here:

C:\localtexmf\tex\latex\maple

Having done that, the last thing is to update MikTeX. Just hit the start button, go to the MikTeX program group, and select MikTeX options. In that window click the ‘Refresh Now’ button under the ‘File Names Database’ section of the first tab. That’s everything! Go export a Maple file to LaTeX and read the note below about graphics to create a PDF.

Linux is a bit different. It took me quite a bit of digging to figure out just what needed to go where and what to do afterwards. Basically the idea is the same as in Windows. You need to get Maple’s .sty files into the local texmf directory and refresh the names database of teTeX. On my Redhat 8.0 box this meant doing the following:

(Create the local package directory for the Maple .sty files where teTeX can find them)

mkdir -p /usr/local/share/texmf/tex/latex/maple

(Copy the Maple .sty files into that directory)

cp /usr/local/maple_su/etc/* /usr/local/share/texmf/tex/latex/maple/

(update the names database)

mktexlsr

Then LaTeX could find the Maple style files and build DVI files without any problems. The directories on your distribution could be quite a bit different, so don’t just blindly enter in commands. Instead, read this email I found that lead me to the solution as it is much more in depth.

## A note on working with graphics in LaTeX¶

The type of graphics you should use will depend on what kind of file you want to produce, either DVI, PS, or PDF. This is because the various document building programs are set to recognize certain graphics types. If you try to use your JPG images to create DVI or PS documents, for instance, you will get a “no boundingbox” error. There are couple of different ways you can approach this problem though the easiest is to use only JPG or PNG images for creating PDF documents and EPS for everything else. I prefer working with PNG files, but JPG files are probably more accessible to Windows users. Unless you use Maple, which exports all of its graphs as EPS when saving to LaTeX, you probably will not encounter many EPS files. If you need a good all-around image viewer and converter I suggest IrfanView. To round out your LaTeX graphics utilities, the GSView program can open EPS files and create JPG or PNG files from them via the ‘File -> Convert’ command.

If you’re using EPS graphics or Maple to make PDF files, don’t despair! There is a much easier way to get to a good PDF than converting all of the EPS files to other formats and then editing the source file. The trick is to first create a DVI using the TeX file and all of the EPS files. Once you have a DVI file, you can use the dvipdf command in Linux to get a PDF file. If you are on Windows, locate the newly created DVI file and right click on it (it may take a Shift+right click), then choose ‘Open with...’. This will take you to a window where you can select a program to open that file with. Click the ‘Other’ button and locate the program ‘dvipdfm’ which will be located at

C:\texmf\miktex\bin\dvipdfm.exe

if you used all of the default install options. You only have to do that once, and then when you need to create a PDF from a Maple file, you can create a DVI from the LaTeX file, then just right click it and select ‘open with’ -> ‘DVI-to-PDF Converter.’ Easy as $\pi$.