Using markdown/restructuredtext to produce a letter

For simple documents, I like to use markdown/restructuredtext and convert it to LaTeX using `pandoc` (and LaTeX includes). For documents such as articles, leaflets, etc., it's quite easy. However, I would like to try and typeset letters (using, e.g. the French `lettre` class).

How would you adapt the markdown/restructuredtext syntax to do that (specifically, to pass the variables and open the `lettre` environment)?

-

Markdown is quite limited when it comes to logical markup. It lacks the necessary structural elements like “sender”, “receiver” etc. I think it's not possible to create letters solely in markdown.

A solution would be to use a pre-processor like gpp to create a logical markup which translates into different structural elements of the final format. There's a blog describing this in detail: How I stopped worring and started using Markdown like TeX. The following example is taken from the blog and gives you an idea of how to use it within the document. It defines logical markup for a file name.

``````<#define filename|`#1`>
<#ifdef HTML>
<#define filename|<code class="filename">#1</code>>
<#endif>
<#ifdef TEX>
<#define filename|\\filename{#1}>
<#endif>
The source is included in <#filename src/hello.c>
``````

The downside is that you have to create the markup translation for each output format. That's the price to pay for the flexibility.

-
That is an option indeed, thank you for your answer. – ℝaphink Nov 4 '12 at 21:09

Pandoc lets you specify both templates and variables. For instance, see the example here: http://pmagwene.github.io/blog/2013/02/07/pandoc-latex-letters/

Paraphrasing that link: you just create the latex template file with your desired letter class, etc, and then add pandoc macros (such as `\$title\$` or `\$body\$`) to include the variables (defined in the compile command) and content defined in the markdown file. Then compile with a command such as:

``````pandoc letter-to-joe.md -o letter-to-joe.pdf --template minletter --variable=addressee:"Joe McShmoe \\ 9876 Mulberry Ln. \\ Salinas, CA 97654"
``````

Note that since pandoc 1.12 you can also define variables using yaml headers.

-