-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathREADME
205 lines (155 loc) · 6.66 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
% Literate Programming with pandoc and lhs2tex
% Tillmann Rendel (Updated by Matthew Pickering)
% November 2015
pandoc-lit supports literate programming by combining two
excellent tools: [pandoc] for text processing, and [lhs2TeX]
for source code formatting. pandoc-lit's input files are written
in markdown+lhs, and its output is LaTeX code ready to be
processed by lhs2tex.
[pandoc]: http://johnmacfarlane.net/pandoc/
[lhs2TeX]: http://people.cs.uu.nl/andres/lhs2tex/
I use pandoc-lit to write research papers and prepare
presentation slides, and I plan to use it for my Ph.D. thesis. It
has been used by a colleague to prepare a presentation, so it
runs one computers other than mine, too. So while I think it is
quite usable already, it is by no means stable, and currently,
using it essentially requires some amount of hacking on it.
Installation
============
Install the package from hackage. It provides an executable called `pandoc-lit`.
cabal install pandoc-lit
Documentation
=============
pandoc-lit works by traversing the [pandoc] AST and reformatting certain elements
so that they are suitable to be processed by [lhs2TeX].
## Transformations
All special lhs2TeX characters are escaped automatically (for example `|`).
### Inline Code
Inline code fragments are directly translated to lhs2TeX inline code fragments.
```
This is some text with the variable `x` in the middle
-->
This is some text with the variable |x| in the middle
```
### Code Blocks
Code blocks are translated to either the `code` or `spec` environment. If
`literate` is amongst the code block's classes then it will be translated to a
`code` environment, otherwise the `spec` environment.
```
\`\`\`
foo = x
\`\`\`
-->
\begin{spec}
foo = x
\end{spec}
```
```{literate}
\`\`\`
foo = x
\`\`\`
-->
\begin{code}
foo = x
\end{code}
```
### Raw LaTeX
Raw LaTeX commands are escaped and passed through.
## Options
There are also a large number of options which can be used to configure the final
document.
None available, but try `pandoc-lit --help` for an overview of
command-line options, or watch this [lightning talk at the
Haskell Implementors Workshop].
[lightning talk at the Haskell Implementors Workshop]: http://www.vimeo.com/15481736
Example
=======
The paper and presentation slides about [invertible syntax
descriptions] were produced with pandoc-lit. This short guide
explains how to recompile the pdfs from sources.
[invertible syntax descriptions]: http://www.informatik.uni-marburg.de/~rendel/unparse/
First, install pandoc-lit:
wget http://www.informatik.uni-marburg.de/~rendel/pandoc-lit/pandoc-lit-0.1.tar.gz
tar -xzf pandoc-lit-0.1.tar.gz
cd pandoc-lit-0.1
cabal install
cd ..
rm -r pandoc-lit-0.1
The following commands should download the files necessary to
compile the paper and the presentation slides:
md pandoc-lit-test
cd pandoc-lit-test
wget http://www.informatik.uni-marburg.de/~rendel/unparse/sources.zip
unzip sources.zip
wget http://www.informatik.uni-marburg.de/~rendel/unparse/scrartcl.template
wget http://www.sigplan.org/sigplanconf.cls
wget -P Talk http://www.informatik.uni-marburg.de/~rendel/unparse/beamer.template
The paper
---------
The paper consists of the primary file `Unparse.lhs` which uses
lhs2tex `%include` directives to include a bunch of secondary
files (`Iso.lhs`, `TH.lhs` and `Evaluation.lhs`). All of these
files use pandoc `markdown+lhs` mixed with lhs2tex directives. We
need to run pandoc-lit on each of the files to convert the
pandoc `markdown+lhs` into `latex+lhs`, but leaving the lhs2tex
directives in place, and encoding everything according to
lhs2tex's input format (e.g., escaping `|` into `||`). The transformed
files will be written into a separate `build` directory.
We start with the secondary files. We use the `--comments` flag to
preserve TeX-style `%...` comments, including lhs2tex directives.
md build
pandoc-lit --comments Iso.lhs > build/Iso.lhs
pandoc-lit --comments TH.lhs > build/TH.lhs
pandoc-lit --comments Evaluation.lhs > build/Evaluation.lhs
For the primary file, we need to add a couple of options. We use
`--template` to select `scrartcl.template` which contains the
document preamble. The `--abstract` flag converts a section with
header `"Abstract"` into an `abstract` environment. And finally
`--variable=sigplanconf:1` sets a variable for pandoc's template
engine. This variable is tested in `scrartcl.template`.
pandoc-lit --template scrartcl.template --abstract --variable=sigplanconf:1 --comments Unparse.lhs > build/Unparse.lhs
Now, the four `*.lhs2tex` files in `build` are ready to be
processed by lhs2tex. A single call will suffice, since lhs2tex
will process the `%include` directives.
cd build
lhs2tex Unparse.lhs > ../paper.tex
cd ..
Lhs2tex should have produced a single file `paper.tex` which
contains the full paper. We can `latex` or `pdflatex` this file
as usual.
The presentation slides
-----------------------
The presentation slides use the LaTeX-package `beamer`. Like the
paper, the presentation slides consist of a primary file
(`Talk/Main.lhs`) which uses lhs2tex `%include` directives to
include some secondary files (`Talk/AST.lhs`,
`Talk/OnlyParsing.lhs`, `Talk/OnlyPrinting.lhs` and
`Talk/Syntax.lhs`). But for the paper, instead of processing the
secondary files separately to be included by lhs2tex, pandoc-lit
will process the `%include` directives, producing a single input
file for `lhs2tex`.
cd Talk
pandoc-lit --title-page --template beamer.template --eval .. --comments --beamer --process-includes Main.lhs > slides.lhs
The `--title-page` option replaces the first section called
`Title Page` by a title frame (using `\maketitle`). The
`--template` option selects `beamer.template` for the preamble.
The `--eval ..` option activates processing of `\eval{...}`
directives with source directory `..`. Using `..` as source
directory is necessary to process module names such as `Iso` or
`Talk.Syntax` correctly. The `--comments` option preserves
TeX-style `%...` comments. The `--beamer` option activates
beamer-specific processing. For instance, subsections in the
input are replaced by `frame` environments in the output.
Finally, `--process-includes` activates the processing of
`%include` directives.
Pandoc-lit should have produced a single file `slides.lhs` which
contains all of the presentation slides. This file can be
processed by lhs2tex.
lhs2tex slides.lhs > slides.tex
The preamble in `beamer.template` is targeted at XeTeX, so we
need to further process `slides.tex` by `xelatex`.
Feedback
========
Feedback, patches, rants, questions, insights etc. are welcome.
Send to [Tillmann Rendel].
[Tillmann Rendel]: mailto:[email protected]