# Evaluating LaTeX code with Alfred and Wolfram Alpha

The LaTeX documents I create have a lot of numerical illustrations. If you write hundreds (maybe thousands) of numerical expressions in LaTeX over the course of a year, you *will* fat-finger a few digits along the way, and I *really* hate typos.

For example, my PDF output might have an expression like this:

```
<img src="/img/math-pe.png" alt=""/>
```

*Quick*. In your head. . . does that really equal 1.9602? Yeah, I don't want to do that either.

My old fashioned editing approach would be to hand check each one with a calculator like Soulver, typing in the expression after it's typeset to PDF and verifying the result. This is because the LaTeX code itself isn't in a format that can be pasted into a typical calculator:

```
\frac{0.9989 + \frac{0.9975}{1.04}}{0.9989} = 1.9602
```

## A better way

I only recently found out that Wolfram Alpha can evaluate most LaTeX expressions in their raw form. Just paste a LaTeX expression into Wolfram Alpha's text input field, and see what it does.

For an even faster approachâ€”avoiding the need to even leave your favorite LaTeX editorâ€”use the stock "Ask Wolfram" workflow in Alfred:

```
<img src="/img/img.png" alt=""/>
```

- Invoke Alfred
- Start typing
`wolf...`

to bring up the Wolfram workflow - Paste LaTeX code and
`return`

The workflow takes you straight to the Wolfram site, which evaluates the expression in a second or two.

```
<img src="/img/img.png" alt=""/>
```

That's probably enough digits, Wolfram. But anyway, yeah, there's the 1.9602 I was hoping to see.

This is by far the fastest and most accurate way I've found to audit LaTeX numerical expressions on the fly. In fact, I've started using Wolfram Alpha to evaluate expressions in the first place. This lets me type LaTeX expressions as I "think" them and know that I can evaluate them in-line as I go.

Alfred, after all, is always just a `Cmd-Space`

away.

**Update:** For ideas on automating this process further with Python, see Dr. Drang's follow-up post.

**Update 2:** Here's an even faster way to evaulate LaTeX with Alfred and Wolfram.