# Real helpful, Pandoc…

Pandoc is an open source markdown conversion tool. It can convert between many formats, such as LaTeX, HTML, Markdown, and many others. The project I’ve been working on recently has a book written in Literate Haskell/LaTeX, and uses Pandoc to convert this to PDF. For the most part, Pandoc does this swimmingly.

Unfortunately, as is often the case with open source, things can be a bit rough around the edges. I intend to help proofread the book and provide feedback. To this end, I got the source for the book and, after installing LaTeX, I tried to build the book:

```
$ make
pandoc: Error running filter [source_dir]/.hs
fd:4: hPutBuf: resource vanished (Broken pipe)
Makefile:60: recipe for target 'pdf' failed
make: *** [pdf] Error 83
```

…really helpful output occurred. Luckily, it seems that I’m not the only person that this has ever happened to, a quick google search turns up this issue opened against *Write You A Haskell*. After reading the thread, I tried:

```
$ cabal exec sh
$ ghc --make .hs
```

…and sure enough, there was a problem with the source file that was preventing it from compiling! I fixed the bug, and re-ran make and everything was fine.

So, preserved here for posterity is a potential solution to this issue; if Pandoc gives you this error, make sure there is nothing wrong with your source file.

# Doing My Math Homework…

Well, it was bound to happen some day… Recently, a new quarter began, and with it new classes. One of said classes is a boolean algebra class, which means lots of fancy math runes to be drawn on pieces of dead trees. One problem though; homework in this class needs to be submitted as a .pdf online. Crap.

I’ve written about this sort of thing before, however, I also remember that being a gigantic hassle. Not to mention the fact that boolean algebra involves drawing logic gates, which is outside the scope of that. I decided it was high time I get onboard the LaTex train.

## One Problem…

What problem? Learning LaTeX sounds like a *huge hassle*. I have enough problems without spending God knows how long learning a new markup language just to submit what would take 20 minutes to write on a piece of paper. In short: I don’t got *time* for that! Luckily for us, we have tools for this sort of thing.

Last month I wrote about giving Emacs a shot. So far, things have been going well. In fact, one tool that Emacs is known for, org-mode, is actually suited particularly well for this problem. I’ll spare you the basics, and just link to the excellent David O'Toole Org tutorial. If you are unfamiliar with org-mode, I suggest you go give it a read before continuing here.

…back? Good. Among the many things that org-mode is good for, it can be used to produce different kinds of output. Among them are html and our good friend LaTeX.

## Document Structure

Let me assign some homework to myself, and we’ll work through it!

```
Show that AB + B'C + AC = AB + B'C without
directly applying the Consensus Theorem
```

As you can imagine, AB + B’C + AC = AB + B’C because some fancy Consensus Theorem says so. Our task is to *do stuff* until the left-hand-side turns into the right-hand-side. And to do it *in LaTeX*!

First, we need to set up our document structure. Create a new file called homework.org, and create a heading:

`* Show using boolean algebra:`

This will create a new heading. Now, we need to do some boilerplate first. Add the following to the top of your file:

`#+OPTIONS: toc:nil`

This will prevent org-mode from creating a table of contents for your homework. I think a table of contents is silly for something with only a few pages, but it sure looks neat! Next, our equations will be automatically numbered, but we want them numbered by section. Add the following below the options line:

`\numberwithin{equation}{section}`

Now, let’s do some LaTeX. org-mode allows us to do inline LaTeX, and it will use it in the final document. Let’s add an equation block:

```
* Show using boolean algebra:
\begin{equation}
AB + \overline{B}C + AC = AB + \overline{B}C
\end{equation}
```

If you save, then press: `C-c C-e`

, then `l o`

, your default .pdf reader should launch with a fancy new page that looks something like this:

Let’s do some more math! You can write comments inside of your heading, and they will be part of that section:

```
Apply identity law and complement law:
\begin{equation}
AB + \overline{B}C + AC(B + \overline{B})
\end{equation}
Apply distributive law:
\begin{equation}
AB + \overline{B}C + ACB + AC\overline{B}
\end{equation}
```

Re-export your new document and you should see something like this:

You may have noticed that we are basically done. Let’s write our answer down along with a fancy box so the professor knows it’s the answer:

```
\begin{equation}
\boxed{AB + \overline{B}C}
\end{equation}
```

And we’re done! If you export your document you should see:

## I thought you didn’t want to learn LaTex…

I know, there’s a whole lot of LaTeX in there. But it could be worse, let’s take a look at the source file that org-mode creates:

```
% Created 2015-01-26 Mon 18:26
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fixltx2e}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{float}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{marvosym}
\usepackage{wasysym}
\usepackage{amssymb}
\usepackage{hyperref}
\tolerance=1000
\author{Chris Tetreault}
\date{\today}
\title{homework}
\hypersetup{
pdfkeywords={},
pdfsubject={},
pdfcreator={Emacs 24.3.1 (Org mode 8.2.10)}}
\begin{document}
\maketitle
\numberwithin{equation}{section}
\section{Show using boolean algebra:}
\label{sec-1}
\begin{equation}
AB + \overline{B}C + AC = AB + \overline{B}C
\end{equation}
Apply identity law and complement law:
\begin{equation}
AB + \overline{B}C + AC(B + \overline{B})
\end{equation}
Apply distributive law:
\begin{equation}
AB + \overline{B}C + ACB + AC\overline{B}
\end{equation}
\begin{equation}
AB(1 + C) + \overline{B}C(1 + A)
\end{equation}
LHS now equals RHS, yay!
\begin{equation}
\boxed{AB + \overline{B}C}
\end{equation}
% Emacs 24.3.1 (Org mode 8.2.10)
\end{document}
```

Yeah… Doesn’t seem so bad now. Thanks to org-mode, we can use just enough LaTeX to do what we need to do, and not have to worry about all that boilerplate!