Once in a while I write a letter, and for some time I’ve been doing so with LaTeX, and more recently using the scrlttr2 class from the KOMA-Script project.

In this article, we’ll look at a few complicated ways to make this process simpler.

One of the tricks will be to use pandoc. This will allow us to use lightweight markup languages, and write to a custom scrlttr2 pandoc template.

The other two tricks we’ll use, are from the KOMA-Script manual, regarding letter class options, and an address file.

Pandoc template

For reference, there is the pandoc manual.

Let’s make a pandoc template file called scrlttr2.latex, with nothing but the text $body$ in it.

To see how this works, try the following.

You can see what the default pandoc template looks like via pandoc -D latex.

Considering what my original scrlttr2 .tex file contained, I put together the following template. You can put this in your current working directory, but better might be to move it to ~/.pandoc/templates/.

This allows us to compose with for example markdown,

Now, let’s create a Makefile for easier use,

# Makefile
	pandoc --template=scrlttr2 -o test.pdf

	pandoc --template=scrlttr2 -o test.tex

Now in the shell, simply executing make should make the pdf.

If you’re using emacs, you might use the following binding to call make. Calling with a prefix, C-u C-c c, you can modify the command. If you need to change completely, default-directory, etc, use M-x compile.

Let’s now move on to the tricks from the scrlttr2 section of the KOMA manual.

Letter Class Options

While these files can go in current working directory, some may be more appropriately saved to ~/Library/texmf/tex/latex/. (I discovered this location while reading Creating letters with KOMA-Script scrlttr2 and Org-mode.)

Consider the following improvement over our template file, by removing this block,

and replacing with the following,

For this to work, we create the following file,

If you felt that was an improvement, you may feel the following is as well.


With an address file, we can use aliases to refer to complete addresses.

We next consider this improvement, in our markdown file. We will replace the following yaml metadata

with the simpler

To make this work, we modify our pandoc template and add an adr file.

In our pandoc template, we replace the following,

with instead, now

And we add an adr file with one entry,

That’s it!

(A benefit of this terse address specification, you can use #+ADR: BIRD in org-mode files. Then you have benefits of org-mode such as commenting sections out has a nicer syntax than in markdown. If I recall correctly, pandoc does not currently work with multiline #+ADDRESS: specifications.)

In closing

In closing, I mention a few improvements I might consider going forward, as well as a few links I’d like to look for ideas out of.

One improvement I’d like to make, is improving the template conditionals in the pandoc template. For example, template should allow for either of address or adr variable to be set.

Also considering if some refactoring or lifting of variables from the tex or lco files, up to the pandoc variables, would be convenient for some cases.

A few links I’d like to read more at, as a potential source of ideas.