jgm/pandoc — pull request #483 by rekka (2012-04-16 12:35:52+00:00)
Title: Add --include-macros command line option

__Motivation.__ I have been using pandoc for a while now. I use it mainly to take various notes. It is a wonderful tool, but I found it seriously lacking this feature. I get to type a lot of formulas. Therefore I have a set of predefined macros that I reuse in all my writing. A typical example is `\e` for `\varepsilon`.

However, there did not seem to be a clean way how to import `\{re}newcommand` macros from an external LaTeX file. It is of course possible to specify multiple input files as in

```
pandoc macros.tex file.md
```

that will be merged and processed at once. This would work fine, if it were not for the pandoc metadata in the preamble. These get garbled since now they appear in a block of text after `macros.tex`.

Up to now, I resolved to preprocessing the input file using a batch to inject the macros after the preamble, but this requires to actually parse the preamble, or put a tag after the preamble into the input. I did not find it satisfactory, since pandoc excels in a clean customization of the output in every other way. This led me to implement this extension.

__Description.__ The new option `--include-macros` enables the user to include supported LaTeX macros from arbitrary external LaTeX files. These macros are then applied when processing LaTeX formulas, depending on the input and output formats.

It is implemented using the pandoc LaTeX parser in `Text.Readers.LaTeX`, only the `stateMacros` is returned instead of the parsed document.

The usage follows the pattern of the other options, for instance `--include-in-header`, etc.:

```
pandoc ... --include-macros=FILE1 --include-macros=FILE2 ...
```

The loaded files can be inserted verbatim into the output template using the variable
array `$include-macros$`. To this extend I am also submitting a related pull request to jgm/pandoc-templates.

I have also added a test that uses a set of `include-macros*` files, and added it to `Tests.Old`. Running `cabal test` shows that all the tests PASS (Ubuntu 11.10).

I appreciate any comments or suggestions. It would be nice to have this feature in the official pandoc distribution.

Best,
Norbert