# Latexit Linux

## Why Use TEX for Equations?

1. LaTeX-Tutorial provides step-by-step lessons to learn how to use LaTeX in no time. It allows you to start creating beautiful documents for your reports, books and papers through easy and simple tutorials.
2. LaTeXit for Linux. March 18, 2010 // 9. I wrote a page on how to create a script which does, in Linux, something very similar to what LaTeXit does for Mac.
3. LaTeXiT Should LaTeXiT be categorized, it would be an equation editor. This is not the plain truth, since LaTeXiT is 'simply' a graphical interface above a LaTeX engine. However, its large set of features is a reason to see it as an editor; this is the goal in fact.

Latexyt A clone of the popular Mac OS program latexit for GTK/linux.

$$s = sqrt{frac{ sum (x_{i} - bar{x})^2}{n - 1}}$$
$$text{SE}_{(bar x _ 1 - bar x _ 2)} = sqrt{ frac{s_1^2}{n_1} + frac{s_2^2}{n_2} }$$

Figure 1: Example Equations

Using TeX (pronounced tek) markup to typeset equations has three hugeadvantages over the many GUI apps out there:

1. It is exceedingly easy to learn and use (especially with the help of this tutorial ☺ ).
2. You can easily put equations on Web pages with the amazing MathJax renderingengine (demonstrated on this page).
3. It's free and open-source.

'But,' I hear you ask, 'isn't the cryptic markup of TeX old-school? Isn'tit easier to just use a GUI application for typesetting equations? Youwould think so, wouldn't you? The night I got a take-home exam in my firstgraduate-level statistics seminar, I found myself in immediate need forsomething to quickly produce good looking equations. So naturally I triedout a few of the GUI apps like MathType, MathMagic and Mac OS X's Grapher. After about five hours experimenting with themI still couldn't figure out how to make any of them do seemingly simplethings. And I found them all extremely clunky when trying to modifyequations. They would constantly do things I didn't intend.

Now, having been a computer geek since 1984 I had always been aware of DonaldKnuth's TeXtypesetting system for scientific papers, soI thought maybe I should finally give TeX atry. Within 20 minutes of opening a little Mac app called LaTeXiT (and with help from a this nice TeX math cheat sheet) Iwas turning to random pages in my stats book and easily typesetting anyequation on the page! (See Figure 1.) It really is that easy.I ended up typesetting my entire exam with LaTeX (pronounced LAY-tek, anextension of TeX), just as an exercise to finally learn how to use it (andit was not so easy). But you don't have to learn how to typesetyour entire papers with LaTeX just to use it for equations.

In this article I'll start with a short interactive tutorial so that youcan experience just how easy it really is to typeset equations with TeXmarkup. Then I'll show you how you can put these equations into wordprocessing and presentation applications, and even onto Web pages.

## Interactive TEX Math Tutorial

This short interactive tutorial will introduce markup codes and conceptsone step at a time, and allow you try them out as you go. Enter thesyntax in the text box at the bottom of the tutorial area and you'll see ittypeset in the middle box whenever you click the 'TYPESET IT' button. Justclick the 'Next' button to move to the next step, or click the small boxesto go to any specific step.

Let's begin with a very small equation, a simple linear model. In thetext box at the bottom (the 'input' box), type 'y = a + bx' (without thequotes), then click the 'TYPESET IT' button. You should see the followingshow up in the middle box (the 'output' box):

$$y = a + bx$$

TeX uses very simple markup codes for special charactersand functions. The codes begin with a backslash followed by aword that describes the character or function.
For example, try typesettingthis: 'y = alpha + beta x + epsilon'. (Note the space betweenbeta and x. You need that because there's no code named 'betax'. It'simportant to know that the spaces you type will not be included inthe typeset equation, because TeX controls all the spacing withinequations.) This is what you should see:

$$y = alpha + beta x + epsilon$$

Here are a few more codes for you to try. Note that somecodes begin with an UPPERCASE letter. Try those with that first letter inlowercase and see what you get.

 (mu) – mu (gamma) – gamma (Delta) – Delta (lbrace) – lbrace (pm) – pm (div) – div (times) – times (approx) – approx (in) – in (geq) – geq (prime) – prime (Rightarrow) – Rightarrow

You can find a complete list in Short Math Guide for LaTeX. You'll need to take the time to lookthrough that after this tutorial.

TeX uses braces, { and }, to enclose sequences ofcharacters that should to be taken together and treated as a whole phrase.So, for example, if you wanted to make the fraction (frac 1 2) you couldjust type 'frac 1 2' (try that now). But if you need to put more than justa single character in the numerator or denominator, you need to enclose themin braces.
So try this: 'z = frac {x - mu} sigma' and you should get this:

$$z = frac {x - mu} sigma$$

Diacritic marks are produced with a code for the markfollowed by a space (remember, spaces are ignored), then the letter that themark should appear over. Some marks can span across severalletters, in which case the letters must be enclosed in braces. Trythese:

 (breve x) – breve x (dot x) – dot x (hat x) – hat x (widehat{xxx}) – widehat{xxx} (check x) – check x (ddot x) – ddot x (bar x) – bar x (overline{xxx}) – overline{xxx} (vec x) – vec x (dddot x) – dddot x (tilde x) – tilde x (widetilde{xxx}) – widetilde{xxx}

Superscripts and subscripts arespecified with the ^ and _ symbols, respectively, followed by thesingle character that should be superscripted or subscripted.
Try this: 'sum (x_i - bar x)^2', and you should get this:

$$sum (x_i - bar x)^2$$

It's important to understand that the superscript or subscript is onlyapplied to the first single character after the ^ or _ symbol. (Aswe'll see, that's the case for many codes in TeX.) If you need to superscriptor subscript a number with more than one digit, or a negative number, or even awhole mathematical phrase, you must enclose it in braces.

So try typing 'p_12' and see what happens. In order for the 1 and2 to be treated as a single unit, just enclose them in braces, likethis: 'p_{12}'. You should see (p_{12})
Then try: 'e ^ {-(b_0 + b_1 X_1 + epsilon_i)}'. You should see (e ^ {-(b_0 + b_1 X_1 + epsilon_i)}).

Now what if you need a variable to have both a superscript and asubscript? It's actually quite easy. If you follow a variable withboth a superscript and a subscript, TeX assumes you meant for bothof them to be applied to that variable. For example, try typing 'x _ mu ^ 2'.You should see (x _ mu ^ 2). It doesn't matter what order you put them in,'x ^ 2 _ mu' will work the same. But if, say, the subscript also needsa subscript, you'll need to use braces, as such: 'x _ {mu_1} ^ 2', which shouldgive you (x _ {mu_1} ^ 2). Try it and experiment with it a bit.

TeX treats superscripts and subscripts in a special way when they areapplied to the sumation (Sigma) or integral (int) symbols. In thesespecial cases they are treated as the limits for those symbols, sothe superscript is placed on top and the subscript is placedunderneath the symbol. (Sometimes, depending on the context, TeXwill put them beside the symbol rather than on the top and bottom.So don't think you made a mistake.) Try this: 'sum ^ n _ {i=1}':

$$sum ^ n _ {i=1}$$

You can place any arbitrary superscript-sized symbol above or below anyother symbol by using the overset and underset codes. These codes, likefrac, take two sets of braces. The first contains the symbols to placeabove or below the symbols within the second braces. So, for example, typeset'overset n X ' or 'underset {n-1} X' and you should get one of thefollowing, respectively:

$$overset n X quad underset {n-1} X$$

If you need to force some extra space, you can use one of the following (the thin ones don't show up so well on Web pages):

 (x , y) , (thin space) (x : y) : (medium space) (x ; y) ; (thick space) (x quad y) quad (x qquad y) qquad

You may have noticed that TeX automatically italicizes all letters,assuming that they are variables. For named operators suchas log() or sin(), TeX has many predefined codes (log and sin in thiscase) which are simply displayed as normal, non-italicized text. For namedoperators that TeX has no code for, such as 'cov' or 'rank', use theoperatorname{} code. For example, try this: 'r =frac{ operatorname{cov}_{xy} } { s_x s_y }'.

$$r = frac{ operatorname{cov}_{xy} } { s_x s_y }$$

Sometimes you need to put other words or letters in your equations thatshouldn't be italicized because you don't want them to look like variables.In such instances you can use the text{} code. For example, try this:'R = pm sqrt{ ( frac{text{Wald} - (2 times df)}{-text{LL}(text{Original})} ) }'.

$$R = pm sqrt{ ( frac{text{Wald} - (2 times df)}{-text{LL}(text{Original})} ) }$$

But, notice something wrong about that? How do we stretch those parentheses?

When you need left and right delimiters (such as parentheses, brackets,and braces) to stretch vertically with their contents, use theleft and right codes before the openingand closing delimiters. For example, in the last equation, put left justbefore the ( and right just before the ), like this:
'R = pm sqrt{ left( frac{text{Wald}-(2 times df)}{-text{LL}(text{Original})} right) }'

$$R = pm sqrt{ left( frac{text{Wald}-(2 times df)}{-text{LL}(text{Original})} right) }$$

If you need parentheses ( ) or square brackets [ ] you can type them directly from your keyboard. Other delimiters must be specified with a code.

 (lbrace ; rbrace) lbrace rbrace (langle ; rangle) langle rangle (lmoustache ; rmoustache) lmoustache rmoustache (lvert ; rvert) lvert rvert (lceil ; rceil) lceil rceil (lgroup ; rgroup) lgroup rgroup (lVert ; rVert) lVert rVert (lfloor ; rfloor) lfloor rfloor

All of those are extensible delimiters, meaning they canall be preceeded by the left and right codes to make them stretch verticallywith their content. Give some of them a try.

When TeX renders fractions inside of other fractions it typically makesthe inner fraction slightly smaller, which is a good thing. But if you needto have many fractions within fractions, you might not want them tokeep getting smaller. To keep TeX from reducing the size, use thecontinuing fraction code, cfrac, instead of frac. Forexample, try typesetting this to see what it looks like: 'frac{1}{sqrt{2}+ frac{1}{sqrt{2} + frac{1}{sqrt{2}+dotsb} } }'. Then change each ofthose frac codes to cfrac to see the difference.

Finally, let's look at how you would show multiple-lines in an equation.This would be useful, for example, when you're writing instructionalmaterials for a class and you want to show how to calculate a particularvalue. Here's an example. In the next step I'll show you how to do it.

begin{align}hat sigma _ {bar x} &= s / sqrt{n} &= 3.853 / sqrt{250} &= 3.853 / 15.811 &= 0.244end{align}

TeX uses ampersands & to set alignment points. So, to set thealignment points before the equals signs you put an ampersands in front ofthem. Typing new lines has no effect on TeX, it will ignore them just asit ignores spaces. Instead, TeX recognizes two backslashes to indicate a newline.So to typeset the previous example, use this:

That's it. We've covered the basics. To learn what else you can do withequations using TeX, peruse Michael Downes's excellent Short Math Guide for LaTeX. In the remainingsteps I'll present you with some sample equations. Try to typeset them asbest you can, then click the 'See Answer' link under the equation to see thecode that produced it. Have Downes's article open in a separate window as areference for the codes. Just take them one small chunk at a time and goahead and hit the 'TYPESET IT' after each chunk. If it displays thecodes instead of the equation, then you have something wrong (probablymissed a closing brace).

$$bar x pm t frac{s}{sqrt{n}}$$

$$bar x pm t_{.005} (hat sigma_bar x )$$

$$bar x = frac{sum x_i}{n}$$

$$mu_{M_d}^2 = frac{sigma_1^2}{n_1} + frac{sigma_2^2}{n_2}$$

$$n! approx sqrt{2 pi n} left( frac{n}{e} right) ^n$$

$$sigma_{p_1 - p_2} = sqrt{ frac{pi_1 (1 - pi_1)}{n_1} + frac{pi_2 (1 - pi_2)}{n_2} }$$

$$operatorname{Pr} [Y = j] ; = ; _n C_j p^j (1-p)^{n-j} quad (0 leq j leq n)$$

$$operatorname{Pr}[r] = frac{N!}{r!(N - r)!} pi^r (1 - pi)^{N-r}$$

Confusion with braces will be the source of much of your mistakes andfrustration. Problems will occur if you forget to close abrace that you've opened, or if you put the closing brace in the wrongplace. If you get a strange error, or things don't look right, checkyour brace pairs. Try typesetting the following equation and see if you can get it to look right:

$$sigma_L = sqrt{ frac{sum a_i^2}{n} sigma_2 2 }$$

And now, for a final challenge, try this whopper!

$$r = frac{ sum XY - frac{sum X sum Y}{N} }{ sqrt{ left( sum X^2 - frac{(sum X)^2}{N} right) left( sum Y^2 - frac {(sum Y)^2}{N} right) 2 } }$$

## Placing Equations on Web Pages

With MathJax youcan put equations on your Web pages that look beautiful in any decentbrowser. I can't heap enough praise on the developers who produced MathJax.It is truly a thing of beauty.

To use MathJax on a Web page, simply add this single line to the <head> sectionof the page:

That's it. That's all you have to do. Once that's in place, adding anequation anywhere in your page is as simple as typing the TeX markup insidethe standard TeX delimiters: $$...$$. So, for example, to place the equation for standarddeviation onto the page, put the following on its own line in your HTMlfile, as if it were a separate paragraph:

That line in your HTML will end up being rendered by MathJax as this:

$$s = sqrt{frac{ sum (x_{i} - bar{x})^2}{n - 1}}$$

Using the standard $$delimiters always puts theequation in its own paragraph. If you need an equation inlinewithin the text of a paragraph you can use the standard TeX inlinedelimiters: ( ... ). For example, you might be talking about a linearmodel and want to show the equation in the text, like this: ( y = alpha +beta x + epsilon ). You do that by simply typing it like this: ( y = alpha + beta x + epsilon ). To insert multi-line equations you can't use the$$ delimiters. Instead, you begin the lines with 'begin{align}' and end them with 'end{align}'.

That code, in the middle of your HTML, will be picked up by MathJax andit will render it as follows:

begin{aligned}hat sigma _ {bar x} &= s / sqrt{n} &= 3.853 / sqrt{250} &= 3.853 / 15.811 &= 0.244end{aligned}

That's all there it to it. How simple is that? It's absolutely amazing.MathJax just totally rocks!

Here's another cool thing that's just icing on the cake. Notice howequations are a little difficult to read in the low-resolution of a webpage, especially the superscripts and subscripts? Well, MathJax can allowthe viewer to zoom the equation so it can be seen more clearly.Just move the mouse cursor over any equation and let it hover there for acouple of seconds and it will show it to you magnified! Go ahead. Try it.Hover over any equation on this page. They look beautiful. It's brilliant.(You can also set it to zoom by double-clicking instead of hovering.) To setyour page so that it zooms on hover, add the following code to the <head>section of your Web page before the <script> tag that calls theMathJax script:

## Placing Equations into Any Application

Equations can be placed into any application by turning them intographics files that can be pasted or imported. The ideal image format forequations is PDF, which can be placed within anyapplication that can handle the PDF format. If your application can't handlePDF, then PNG is the next best alternative, but you'll need to PNG file tobe a fairly high resolution, like 300 dots-per-inch, otherwise it won'tprint well and might not even be legible on-screen.

### Mac OS X

Mac OS X users can download the awesomeLaTeXiT app, which allows you to typeset your equationsin a window very similar to the tutorial above and then copy and paste themas PDFs or PNGs into your applications.

The first thing you need to do is download and install MacTeX. After you getthat installed, reboot your Mac to make sure everything is in place. Next,download and install LaTeXiT.

The LaTeXiT window is similar to the tutorial above, with a big outputwindow at the top and a text input box at the bottom (see Figure 2).Strangely, LaTeXiT defaults to typesetting your equations in 36 pt type. Idon't know why you would want them to be so huge, but there it is. The firstthing you should do is change that to 12 pt. Leave the color black, andleave the mode on 'Align' (I'll explain that later).

Figure 3: LaTeXiT Zoom Control

Now type something simple into the input box like 'y = a + bx' (withoutthe quotes), then click the 'LaTeX it!' button. Your equation should appearin the top half of the window. Notice, however, that it's awfully small(assuming you changed the font size to 12 pt). To see it better LaTeXiTprovides a magnification feature. Just drag the zoom controller up a littlebit to zoom in on it (see Figure 3). From this point on you can just useLaTeXiT the same way you used the tutorial above. Remember, you don't haveto type out the code for the entire equation at once. You can type smallchunks of it at a time and click the 'LaTeX it!' button as many timesas you need to make sure it's looking correct.

Now comes the cool part. When you're equation looks the way you want itto, right-click on it (or hold the CTRL key while you click, if youdon't have a multi-button mouse—which you should) and you'll get tothe menu shown in Figure 5. Notice the default is already set to PDF. Thisis ideal. The PDF format can be placed into just about any application onthe Mac, and it can be resized to any size you need and will alwayslook perfect, whether on screen or printed. You should always try to use PDFinstead of PNG, JPEG, or GIF if at all possible.

You don't, however, have to go through the copy menu. For most applicationsall you have to do is drag your equation from the LaTeXiT window rightonto the page of your Pages, Word, or PowerPoint file! How awesome is that?You can also use the copy and paste keyboard commands. At any time you canjust hold down the Command and Option keys and hit the C key to copy theequation in PDF format to the clipboard. Once you have it in the clip boardyou can paste it into Pages, Word, PowerPoint, InDesign, Illustrator, orjust about any other app (sadly, however, not OpenOffice or NeoOffice).

## Latexit Linux Operating System

Unfortunately, for Windows users the situation isn't nearly so sweet.There's nothing anywhere close to as nice as LaTeXiT, and nothing that I'vefound that will produce the equations in PDF format.

Honestly, if you use Windows and you want to produce really goodlooking equations for your papers or presentations (that is, you want PDF),I would suggest just using the CodeCogs onlineEquationEditor. It will allow you to typeset equations using TeX markup, andthen to download the equations in PDF format. It even has GUI menus for allthe TeX codes, which is something LaTeXiT could use.

The best you can do for a Windows-native application is the LaTeX EquationEditor. It's clunky, and it only produces PNG files, but it will atleast produce high-resolution PNG files, so that they'll lookhalfway decent in print.

First you need to download and install MiKTeX, the LaTeX distribution for Windows. Duringinstallation, leave the default setting of 'Anyone who uses this computer.'When it asks you where to install, put 'C:MiKTeX'. And when it asks for'Prefered paper,' if you're in the US change 'A4' to 'Letter.' MiKTeX mightinstall without a hitch, or it might not install at all, completely crappingout with a lovely error like this: 'Windows API error 2: The system cannotfind the file specified.' It's hit or miss depending on your installation ofWindows. I've had both experiences on Windows machines that were bothrunning Windows XP SP3. Go figure.

After (and if ) you get MiKTeX installed, download and install LaTeX EquationEditor. The first time you run LaTeX Equation Editor you'll need to click on the'Settings' tab and tell it where to find the MikTeX 'texify.exe' and'dvipng.exe' programs. If you installed it into C:MikTeX, then you'll findboth of them in 'C:MikTeXmiktexbin'. If you installed it into C:ProgramFilesMikTeX the they'll be in 'C:Program FilesMikTeXmiktexbin'.

Strangly, this program has no menus and no 'Quit' button. To quit out ofit, you're only option is to click the close-window button [X] in thetop right of the window. As I said, it's clunky.

## Latexit Alternative For Linux

### Linux

Sadly, there's no decent TeX equation editor (that I'm aware of) forLinux. There once was a very good one called Ekee that could even produce the equations in PDFformat. But it has not been maintained for many years and apparently doesnot run on most newer versions of Linux. But, as I mentioned just above, youcan use the CodeCogs onlineEquationEditor.

I hope this helped get you started with typesetting your own equations.To continue, you really need to read Downes's Short Math Guide for LaTeX. (You can skipsections 1 and 2 unless you want to learn about putting equations into LaTeXdocuments.) That will show you how to do more complicated things. If you'reinterested in learning how to typeset entire articles with LaTeX, you can goto Tobias Oetiker's Not So Short Introduction to LaTeX2e. And onemore cool resource: if you know the symbol you need, and you can't find theTeX code for it, go to the Detexify site, draw the symbol and it will lookup the code for you!

## References

Chatelier, Pierre. LaTeXiT: A TeX Equation Editor for Mac. http://pierre.chachatelier.fr/programmation/latexit_en.php.

Bateman, Will. Online LaTeX Equation Editor. CodeCogs Engineering.(A very cool online TeX equation rendering engine that can produce many fileformats including PNG, PDF, and even SVG.) http://www.codecogs.com/latex/about.php.

Downes, Michael. 2002. Short Math Guide forLaTeX. Providence, RI: American Mathematical Society. ftp://ftp.ams.org/pub/tex/doc/amsmath/short-math-guide.pdf.

MathJax. MathJax: Beautiful Math in All Browsers. http://www.mathjax.org/.

Oetiker, Tobias. 2011. The Not So ShortIntroduction to LaTeX2e: Or LaTeX2e in 174 Minutes.http://www.ctan.org/tex-archive/info/lshort/english/.

Pakin, Scott. 2009. The Comprehensive LaTeX Symbol List.The Comprehensive TeX Archive Network.http://mirrors.ctan.org/info/symbols/comprehensive/symbols-letter.pdf.

TeX Users Group. MacTeX: The Reference Edition of TeX for Mac. http://www.tug.org/mactex/.

Thrysoee, Jess. Laeqed - LaTeX Equation Editor. A Java-based appthat runs on all operating systems, but only produces PNG format. http://www.thrysoee.dk/laeqed/.

### LaTeXiT

Should LaTeXiT be categorized, it would be an equation editor. This is not the plain truth, since LaTeXiT is 'simply' a graphical interface above a LaTeX engine. However, its large set of features is a reason to see it as an editor; this is the goal in fact.

### How to use it

You are maybe familiar with the LaTeX language. Then you are given a great power to compose equations, from the simplest to the most complex ones, with a perfect result. But to be honest, you don't really want to go though all of the following steps just to illustrate a document :

• create a tex file with its preamble ;
• compile this file ;
• crop the result ;
• insert that part in your document ;
• delete or backup the files you have just used ;
• restart from the beginning if you want to modify a little thing in the equation.

Balking is forgiven. This is to get rid of that burden that LaTeXiT was created.
With LaTeXiT, you only focus on your equation. The result is automatically cropped and you can drag and drop it in any application, in the desired format (certainly PDF).

Moreover, for the compatible formats, you can reopen the equation to modify it : the LaTeX code is kept inside.
Many other features are provided, you can see most of them in the dedicated section.

### (Il)limitations

Even if LaTeXiT simplifies the whole process of 'latexizing' you do not lose control over the advanced uses of the LaTeX engine. You can still select the LaTeX engine, include packages, change the preamble, use scripts… The graphical interface makes it possible to hide that to the beginner, but a fine grained customization is never far away.

The interface is designed for equations, not for multi-pages documents. For such a usage, other applications may be more relevant.