Archive | Org

# My Kingdom For a File Browser

As you may know, lately I’ve been trying to get used to using emacs. This has been going well, but there are some things I find myself missing from my old editors. One of them is the files list on the left side:

Sure, I can use dired, Speedbar, or any number of other solutions. But none of these work exactly like my old file browser. In despair, I got used to the C-x C-f Do [tab] c [tab] [tab] d [tab] p [tab] [tab] ... workflow that autocompletion brings us. However, it never quite settled with me.

Lately, I’ve found myself using org-mode in a way that has been quieting the proverbial fire. I’ve been able to use org-mode as a project browser, let me show you how!

## Some Background

As you may know, org-mode is kind of a catch-all tool for organizing, note taking, and keeping todo lists. You can create hierarchical trees of headings. Hierarchical trees… Sound like anything we know?

I’ve been trying to use org-mode primarily as a TODO list to keep track of all the stuff I have going on. For projects that I’m working on, I’ve been creating TODO lists for the various source files I’m writing. A few links later, and we have the beginning of a project browser.

## * TODO programming project

One of the nice things about tracking your own project is that you can decide what the tree looks like. An embedded project might group C and assembly source files separately, where a Haskell project might group source files by module nesting level.

Let’s talk C. We can create a project.org file in the root of our project directory (where the Makefile is). Next, let’s create some headers:

* C
* ASM
* Unit Tests
* Misc

Here, I’ve created 4 groups. C source goes in the C group, Assembly source goes in ASM, Unit test source files go in Unit Tests, and miscellaneous stuff like Makefiles, .gitignores, and READMEs go in Misc.

Next, let’s add some source files:

* C
** [[./main.c]]
* ASM
* Unit Tests
* Misc

Here, I’ve added a link to main.c to the C group. At this point, this file doesn’t exist. If you click on main.c with org-mode enabled, the file will be opened in emacs, creating it if doesn’t exist! Sure, it’s manual, but I find it is not hard to keep up. If you commit your project.org to your version control system, all members of the project can keep it updated and in sync.

However, what the manual updating buys you is the freedom to organize it how you like! We can add tasks to the tree:

* C
** [[./main.c]]
*** TODO implement main
* ASM
* Unit Tests
* Misc

*C
** [[./main.c]]
*** TODO implement main
* ASM
* Unit Tests
* Misc

* C
** [[./main.c]]
*** TODO implement main
- I tried to implement main, but printf is
such a hard function to use! I'll
revisit this after I've had four beers...
* ASM
* Unit Tests
* Misc

* C
** [[./main.c]]
*** TODO implement main
- I tried to implement main, but printf is
such a hard function to use! I'll
revisit this after I've had four beers...
**** TODO drink four beers
* ASM
* Unit Tests
* Misc

Let’s see your silly little file browser window do that!

# 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:

$$AB + \overline{B}C + AC = AB + \overline{B}C$$

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:

$$AB + \overline{B}C + AC(B + \overline{B})$$

Apply distributive law:

$$AB + \overline{B}C + ACB + AC\overline{B}$$

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:

  $$\boxed{AB + \overline{B}C}$$

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}

$$AB + \overline{B}C + AC = AB + \overline{B}C$$

Apply identity law and complement law:

$$AB + \overline{B}C + AC(B + \overline{B})$$

Apply distributive law:

$$AB + \overline{B}C + ACB + AC\overline{B}$$

$$AB(1 + C) + \overline{B}C(1 + A)$$

LHS now equals RHS, yay!

$$\boxed{AB + \overline{B}C}$$
% 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!