LaTeXiT



January 29, 2018 at 9:36 PM by Dr. Drang

Latexit

  • Global Nav Open Menu Global Nav Close Menu; Apple; Shopping Bag +.
  • Online LaTeX equation editor, generate your mathematical expressions using LaTeX with a simple way.
LaTeXiT

When I learn something new in Matplotlib, I usually write a short post about it to reinforce what I’ve learned and to give me a place to look it up when I need to do it again. In my section properties post from last week, I had a 2×2 set of plots that helped explain which arctangent result I wanted to choose under different circumstances.

Here’s the plot:

And here’s the code that made most of it:

I'm a huge fan of Last Exit to Nowhere. By huge fan, I mean that I am delighted to wear a semi-secret message on my chest that identifies me as part of the geek conspiracy to take over the world.

What was new to me was the use of the pyplot.subplots function to generate both the overall figure and the grid of subplots in one fell swoop. It’s possible that this technique was new to me because the documentation for Matplotlib’s Pyplot API doesn’t contain an entry for subplots.1 I don’t remember where I first learned about it—Stack Overflow would be a good guess—but I’ve since learned that pyplot.subplots is basically a combination of pyplot.figure and Figure.subplots.

Lines 6–10 define the four functions to be plotted. The x values are the same for each and the y values are named according to the quadrant they’re going to appear in. The y values are defined so the moments and product of inertia match the annotations shown in the graph. The actual numbers used in these definitions are less important than their signs and their relative magnitudes, as the plots are intended to be generic.

Line 12 then defines the figure and the array of “axes,” where you have to remember that Matplotlib unfortunately uses that word in a way that doesn’t fit the rest of the world’s usage. In Matplotlib, “axes” is usually treated as a singular noun and refers to the area of an individual plot. After Line 12, the axarr variable is a 2×2 array of Matplotlib axes.

Lines 13–19 then define the subplot in the upper left quadrant (what you learned as Quadrant II in analytic geometry class). Line 19 turns off the usual plot frame, and Lines 17–18 ensure there are no tick marks or labels. Lines 14—15 draw the (x) and (y) axes (here I’m using the normal definition of the word). You’ll notice that I’ve drawn the (x) axis at (y = 2) instead of (y = 0). I didn’t like the way the graphs looked with the (x) axis lower, so I moved it up. Again, this doesn’t change the meaning behind the graph because it’s generic.

The rest of the lines down through 43 are just repetitions for the the other quadrants. Finally, Line 45 saves the figure to a PDF file that looks like this:

Now it’s time to annotate the figure. In theory, I could do this in Matplotlib, but that’s a lot of programming for something that’s more visual than algorithmic. If I were making dozens of these figures, I’d probably invest the time in annotating them in Matplotlib, but for a one-off it’s much faster to do it in OmniGraffle.

I can open the PDF directly in OmniGraffle and start editing. First, I select the white background rectangle that’s usually included in files like this and delete it. It doesn’t add anything, and it’s too easy to select by mistake. Then I select all the axes (again, the usual definition) and add the arrowheads.

The Edit‣Select‣Similar Objects command is very helpful in selecting repeated elements like this.

Latexit

After placing red circles at the maxima, it was time to label the axes (yes, usual definition; we’re out of Matplotlib now) and add the annotations. I made the annotations in LaTeXiT, a very nice little program for generating equations to be pasted into graphics programs. I’ve been using it for ages.

LaTeXiT cleverly ties into your existing LaTeX installation, so you can take advantage of all the packages you’re used to having available. I usually have LaTeXiT use the Arev package because I like its sans-serif look in figures.

After adding all the annotations, I export the figure from OmniGraffle as a PNG, run it through OptiPNG to save a little bandwidth, and upload it to the server. If this were a figure for a report instead of the blog, I’d export it as a PDF.

  1. I’ve complained about Matplotlib’s documentation before, so I’ll spare you the rant this time. Download excimer-dm driver. ↩

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.

Latexite

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