git.iko.soy/typeable/pandoc
on 7d20ffe help sign in
1300 lines 50 kB history raw
1% Pandoc User's Guide
2% John MacFarlane
3% March 20, 2010
5Pandoc is a [Haskell] library for converting from one markup format to
6another, and a command-line tool that uses this library. It can read
7[markdown] and (subsets of) [reStructuredText], [HTML], and [LaTeX]; and
8it can write plain text, [markdown], [reStructuredText], [HTML], [LaTeX],
9[ConTeXt], [RTF], [DocBook XML], [OpenDocument XML], [ODT], [GNU Texinfo],
10[MediaWiki markup], [groff man] pages, and [S5] HTML slide shows.
11Pandoc's enhanced version of markdown includes syntax for footnotes,
12tables, flexible ordered lists, definition lists, delimited code blocks,
13superscript, subscript, strikeout, title blocks, automatic tables of
14contents, embedded LaTeX math, and markdown inside HTML block elements.
15(These enhancements can be disabled if a drop-in replacement for
16`Markdown.pl` is desired.)
18In contrast to most existing tools for converting markdown to HTML, which
19use regex substitutions, Pandoc has a modular design: it consists of a
20set of readers, which parse text in a given format and produce a native
21representation of the document, and a set of writers, which convert
22this native representation into a target format. Thus, adding an input
23or output format requires only adding a reader or writer.
25[markdown]: http://daringfireball.net/projects/markdown/
26[reStructuredText]: http://docutils.sourceforge.net/docs/ref/rst/introduction.html
27[S5]: http://meyerweb.com/eric/tools/s5/
28[HTML]: http://www.w3.org/TR/html40/
29[LaTeX]: http://www.latex-project.org/
30[ConTeXt]: http://www.pragma-ade.nl/
31[RTF]: http://en.wikipedia.org/wiki/Rich_Text_Format
32[DocBook XML]: http://www.docbook.org/
33[OpenDocument XML]: http://opendocument.xml.org/
34[ODT]: http://en.wikipedia.org/wiki/OpenDocument
35[MediaWiki markup]: http://www.mediawiki.org/wiki/Help:Formatting
36[groff man]: http://developer.apple.com/DOCUMENTATION/Darwin/Reference/ManPages/man7/groff_man.7.html
37[Haskell]: http://www.haskell.org/
38[GNU Texinfo]: http://www.gnu.org/software/texinfo/
40© 2006-2010 John MacFarlane (jgm at berkeley dot edu). Released under the
41[GPL], version 2 or greater. This software carries no warranty of
42any kind. (See COPYRIGHT for full copyright and warranty notices.)
43Other contributors include Recai Oktaş, Paulo Tanimoto, Peter Wang,
44Andrea Rossato, Eric Kow, infinity0x, Luke Plant, shreevatsa.public,
45rodja.trappe, Bradley Kuhn, thsutton, Justin Bogner.
47[GPL]: http://www.gnu.org/copyleft/gpl.html "GNU General Public License"
49Using Pandoc
50============
52If you run `pandoc` without arguments, it will accept input from
53stdin. If you run it with file names as arguments, it will take input
54from those files. By default, `pandoc` writes its output to stdout.[^1]
55If you want to write to a file, use the `-o` option:
57 pandoc -o hello.html hello.txt
59[^1]: The exception is for `odt`. Since this is a binary output format,
60 an output file must be specified explicitly.
62Note that you can specify multiple input files on the command line.
63`pandoc` will concatenate them all (with blank lines between them)
64before parsing:
66 pandoc -s ch1.txt ch2.txt refs.txt > book.html
68(The `-s` option here tells `pandoc` to produce a standalone HTML file,
69with a proper header, rather than a fragment. For more details on this
70and many other command-line options, see below.)
72Instead of a filename, you can specify an absolute URI. In this
73case pandoc will attempt to download the content via HTTP:
75 pandoc -f html -t markdown http://www.fsf.org
77The format of the input and output can be specified explicitly using
78command-line options. The input format can be specified using the
79`-r/--read` or `-f/--from` options, the output format using the
80`-w/--write` or `-t/--to` options. Thus, to convert `hello.txt` from
81markdown to LaTeX, you could type:
83 pandoc -f markdown -t latex hello.txt
85To convert `hello.html` from html to markdown:
87 pandoc -f html -t markdown hello.html
89Supported output formats include `markdown`, `latex`, `context`
90(ConTeXt), `html`, `rtf` (rich text format), `rst`
91(reStructuredText), `docbook` (DocBook XML), `opendocument`
92(OpenDocument XML), `odt` (OpenOffice text document), `texinfo`, (GNU
93Texinfo), `mediawiki` (MediaWiki markup), `man` (groff man), and `s5`
94(which produces an HTML file that acts like powerpoint).
96Supported input formats include `markdown`, `html`, `latex`, and `rst`.
97Note that the `rst` reader only parses a subset of reStructuredText
98syntax. For example, it doesn't handle tables, option lists, or
99footnotes. But for simple documents it should be adequate. The `latex`
100and `html` readers are also limited in what they can do.
102If you don't specify a reader or writer explicitly, `pandoc` will
103try to determine the input and output format from the extensions of
104the input and output filenames. Thus, for example,
106 pandoc -o hello.tex hello.txt
108will convert `hello.txt` from markdown to LaTeX. If no output file
109is specified (so that output goes to stdout), or if the output file's
110extension is unknown, the output format will default to HTML.
111If no input file is specified (so that input comes from stdin), or
112if the input files' extensions are unknown, the input format will
113be assumed to be markdown unless explicitly specified.
115Character encodings
116-------------------
118All input is assumed to be in the UTF-8 encoding, and all output
119is in UTF-8. If your local character encoding is not UTF-8 and you use
120accented or foreign characters, you should pipe the input and output
121through [`iconv`]. For example,
123 iconv -t utf-8 source.txt | pandoc | iconv -f utf-8 > output.html
125will convert `source.txt` from the local encoding to UTF-8, then
126convert it to HTML, then convert back to the local encoding,
127putting the output in `output.html`.
129Wrappers
130========
132`markdown2pdf`
133--------------
135The standard Pandoc installation includes `markdown2pdf`, a wrapper
136around `pandoc` and `pdflatex` that produces PDFs directly from markdown
137sources. The default behavior of `markdown2pdf` is to create a file with
138the same base name as the first argument and the extension `pdf`; thus,
139for example,
141 markdown2pdf sample.txt endnotes.txt
143will produce `sample.pdf`. (If `sample.pdf` exists already,
144it will be backed up before being overwritten.) An output file
145name can be specified explicitly using the `-o` option:
147 markdown2pdf -o book.pdf chap1 chap2
149If no input file is specified, input will be taken from stdin.
150All of `pandoc`'s options will work with `markdown2pdf` as well.
152`markdown2pdf` assumes that `pdflatex` is in the path. It also
153assumes that the following LaTeX packages are available:
154`unicode`, `fancyhdr` (if you have verbatim text in footnotes),
155`graphicx` (if you use images), `array` (if you use tables),
156and `ulem` (if you use strikeout text). If they are not already
157included in your LaTeX distribution, you can get them from
158[CTAN]. A full [TeX Live] or [MacTeX] distribution will have all of
159these packages.
161`hsmarkdown`
162------------
164A user who wants a drop-in replacement for `Markdown.pl` may create
165a symbolic link to the `pandoc` executable called `hsmarkdown`. When
166invoked under the name `hsmarkdown`, `pandoc` will behave as if the
167`--strict` flag had been selected, and no command-line options will be
168recognized. However, this approach does not work under Cygwin, due to
169problems with its simulation of symbolic links.
171[Cygwin]: http://www.cygwin.com/
172[`iconv`]: http://www.gnu.org/software/libiconv/
173[CTAN]: http://www.ctan.org "Comprehensive TeX Archive Network"
174[TeX Live]: http://www.tug.org/texlive/
175[MacTeX]: http://www.tug.org/mactex/
177Command-line options
178====================
180Various command-line options can be used to customize the output.
181For further documentation, see the `pandoc(1)` man page.
183`-f`, `--from`, `-r`, or `--read` *format*
184: specifies the input format (the format Pandoc will be converting
185 *from*). *format* can be `native`, `markdown`, `rst`, `html`, or
186 `latex`. (`+lhs` can be appended to indicate that the input should
187 be treated as literate Haskell source. See
188 [Literate Haskell support](#literate-haskell-support), below.)
190`-t`, `--to`, `-w`, or `--write` *format*
191: specifies the output format -- the format Pandoc will
192 be converting *to*. *format* can be `native`, `html`, `s5`,
193 `docbook`, `opendocument`, `latex`, `context`, `markdown`, `man`,
194 `plain`, `rst`, and `rtf`. (`+lhs` can be appended to indicate that
195 the output should be treated as literate Haskell source. See
196 [Literate Haskell support](#literate-haskell-support), below.)
198`-s` or `--standalone`
199: indicates that a standalone document is to be produced (with
200 appropriate headers and footers), rather than a fragment.
202`-o` or `--output` *filename*
203: sends output to *filename*. If this option is not specified,
204 or if its argument is `-`, output will be sent to stdout.
205 (Exception: if the output format is `odt`, output to stdout
206 is disabled.)
208`-p` or `--preserve-tabs`
209: causes tabs in the source text to be preserved, rather than converted
210 to spaces (the default).
212`--tab-stop` *tabstop*
213: sets the number of spaces per tab to *tabstop* (defaults to 4).
215`--strict`
216: specifies that strict markdown syntax is to be used, without
217 pandoc's usual extensions and variants (described below). When the
218 input format is HTML, this means that constructs that have no
219 equivalents in standard markdown (e.g. definition lists or strikeout
220 text) will be parsed as raw HTML.
222`--reference-links`
223: causes reference-style links to be used in markdown
224 and reStructuredText output. By default inline links are used.
226`-R` or `--parse-raw`
227: causes the HTML and LaTeX readers to parse HTML codes and LaTeX
228 environments that it can't translate as raw HTML or LaTeX. Raw HTML can
229 be printed in markdown, reStructuredText, HTML, and S5 output; raw LaTeX
230 can be printed in markdown, reStructuredText, LaTeX, and ConTeXt output.
231 The default is for the readers to omit untranslatable HTML codes and
232 LaTeX environments. (The LaTeX reader does pass through untranslatable
233 LaTeX *commands*, even if `-R` is not specified.)
235`-C` or `--custom-header` *filename*
236: can be used to specify a custom document header. Implies `--standalone`.
237 *Note: this option is deprecated. Use of `--template` is preferred.*
239`--toc` or `--table-of-contents`
240: includes an automatically generated table of contents (or, in the
241 case of `latex`, `context`, and `rst`, an instruction to create
242 one) in the output document. This option has no effect with `man`,
243 `docbook`, or `s5` output formats.
245`--base-header-level` *level*
246: specifies the base level for headers (defaults to 1).
248`--template=`*file*
249: uses *file* as a custom template for the generated document. Implies
250 `-s`. See [Templates](#templates) below for a description
251 of template syntax. If this option is not used, a default
252 template appropriate for the output format will be used. See also
253 `-D/--print-default-template`.
255`-V` *key=val*, `--variable=`*key:val*
256: sets the template variable *key* to the value *val* when rendering the
257 document in standalone mode. This is only useful when the
258 `--template` option is used to specify a custom template, since
259 pandoc automatically sets the variables used in the default
260 templates.
262`-c` or `--css` *filename*
263: allows the user to specify a custom stylesheet that will be linked to
264 in HTML and S5 output. This option can be used repeatedly to include
265 multiple stylesheets. They will be included in the order specified.
266 Implies `--standalone`.
268`-H` or `--include-in-header` *filename*
269: includes the contents of *filename* (verbatim) at the end of the
270 document header. This can be used, for example, to include special
271 CSS or javascript in HTML documents. This option can be used
272 repeatedly to include multiple files in the header. They will be
273 included in the order specified. Implies `--standalone`.
275`-B` or `--include-before-body` *filename*
276: includes the contents of *filename* (verbatim) at the beginning of
277 the document body (e.g. after the `<body>` tag in HTML, or the
278 `\begin{document}` command in LaTeX). This can be used to include
279 navigation bars or banners in HTML documents. This option can be
280 used repeatedly to include multiple files. They will be included in
281 the order specified. Implies `--standalone`.
283`-A` or `--include-after-body` *filename*
284: includes the contents of *filename* (verbatim) at the end of
285 the document body (before the `</body>` tag in HTML, or the
286 `\end{document}` command in LaTeX). This option can be be used
287 repeatedly to include multiple files. They will be included in the
288 order specified. Implies `--standalone`.
290`--reference-odt` *filename*
291: uses the specified file as a style reference in producing an ODT.
292 For best results, the reference ODT should be a modified version
293 of an ODT produced using pandoc. The contents of the reference ODT
294 are ignored, but its stylesheets are used in the new ODT. If no
295 reference ODT is specified on the command line, pandoc will look
296 for a file `reference.odt` in the user data directory (see
297 `--data-dir`, below). If it is not found there, sensible defaults
298 will be used.
300`-D` or `--print-default-template` *format*
301: prints the default template for an output *format*. (See `-t`
302 for a list of possible *format*s.)
304`-T` or `--title-prefix` *string*
305: includes *string* as a prefix at the beginning of the title that
306 appears in the HTML header (but not in the title as it appears at
307 the beginning of the HTML body). (See below on
308 [Title Blocks](#title-blocks).) Implies `--standalone`.
310`-S` or `--smart`
311: causes `pandoc` to produce typographically correct output, along the
312 lines of John Gruber's [Smartypants]. Straight quotes are converted
313 to curly quotes, `---` to dashes, and `...` to ellipses. Nonbreaking
314 spaces are inserted after certain abbreviations, such as "Mr."
315 (Note: This option is only significant when the input format is
316 `markdown`. It is selected automatically when the output format is
317 `latex` or `context`.)
319`-m`*[url]* or `--latexmathml`*[=url]*
320: causes `pandoc` to use the [LaTeXMathML] script to display
321 TeX math in HTML or S5. If a local copy of `LaTeXMathML.js` is
322 available on the webserver where the page will be viewed, provide a
323 *url* and a link will be inserted in the generated HTML or S5. If
324 no *url* is provided, the contents of the script will be inserted
325 directly; this provides portability at the price of efficiency. If
326 you plan to use math on several pages, it is much better to link to
327 a copy of `LaTeXMathML.js`, which can be cached. (See `--jsmath`,
328 `--gladtex`, and `--mimetex` for alternative ways of dealing with
329 math in HTML.)
331`--mathml`
332: causes `pandoc` to convert all TeX math to MathML.
333 In standalone mode, a small javascript will be inserted that allows
334 the MathML to be viewed on some browsers.
336`--jsmath`*=[url]*
337: causes `pandoc` to use the [jsMath] script to display
338 TeX math in HTML or S5. The *url* should point to the jsMath load
339 script (e.g. `jsMath/easy/load.js`). If it is provided, a link to it
340 will be included in the header of standalone HTML documents.
341 (See `--latexmathml`, `--mimetex`, and `--gladtex` for alternative
342 ways of dealing with math in HTML.)
344`--gladtex`*[=url]*
345: causes TeX formulas to be enclosed in `<eq>` tags in HTML or S5 output.
346 This output can then be processed by [gladTeX] to produce links to
347 images with the typeset formulas. (See `--latexmathml`, `--jsmath`, and
348 `--mimetex` for alternative ways of dealing with math in HTML.)
350`--mimetex`*[=url]*
351: causes TeX formulas to be replaced by `<img>` tags linking to the
352 [mimeTeX] CGI script, which will produce images with the typeset
353 formulas. (See `--latexmathml`, `--jsmath`, and `--gladtex` for alternative
354 ways of dealing with math in HTML.)
356`-i` or `--incremental`
357: causes all lists in S5 output to be displayed incrementally by
358 default (one item at a time). The normal default is for lists to be
359 displayed all at once.
361`--xetex`
362: creates LaTeX outut suitable for processing by XeTeX.
364`-N` or `--number-sections`
365: causes sections to be numbered in LaTeX, ConTeXt, or HTML output.
366 By default, sections are not numbered.
368`--no-wrap`
369: disables text-wrapping in output. By default, text is wrapped
370 appropriately for the output format.
372`--sanitize-html`
373: sanitizes HTML (in markdown or HTML input) using a whitelist.
374 Unsafe tags are replaced by HTML comments; unsafe attributes
375 are omitted. URIs in links and images are also checked against a
376 whitelist of URI schemes.
378`--email-obfuscation`*=none|javascript|references*
379: specifies a method for obfuscating `mailto:` links in HTML documents.
380 *none* leaves `mailto:` links as they are. *javascript* obfuscates
381 them using javascript. *references* obfuscates them by printing their
382 letters as decimal or hexadecimal character references. If `--strict`
383 is specified, *references* is used regardless of the presence
384 of this option.
386`--id-prefix`*=string*
387: specifies a prefix to be added to all automatically generated identifiers
388 in HTML output. This is useful for preventing duplicate identifiers
389 when generating fragments to be included in other pages.
391`--indented-code-classes`*=classes*
392: specifies classes to use for indented code blocks--for example,
393 `perl,numberLines` or `haskell`. Multiple classes may be separated
394 by spaces or commas.
396`--data-dir`*=directory*
397: specifies the user data directory to search for pandoc data files.
398 If this option is not specified, the default user data directory
399 will be used:
401 $HOME/.pandoc
403 in unix and
405 C:\Documents And Settings\USERNAME\Application Data\pandoc
407 in Windows. A reference ODT, `templates` directory, `s5` directory
408 placed in this directory will override pandoc's normal defaults.
410`--dump-args`
411: is intended to make it easier to create wrapper scripts that use
412 Pandoc. It causes Pandoc to dump information about the arguments
413 with which it was called to stdout, then exit. The first line
414 printed is the name of the output file specified using the `-o`
415 or `--output` option, or `-` if output would go to stdout. The
416 remaining lines, if any, list command-line arguments. These will
417 include the names of input files and any special options passed
418 after ` -- ` on the command line. So, for example,
420 pandoc --dump-args -o foo.html -s foo.txt \
421 appendix.txt -- -e latin1
423 will cause the following to be printed to stdout:
425 foo.html foo.txt appendix.txt -e latin1
427`--ignore-args`
428: causes Pandoc to ignore all command-line arguments.
429 Regular Pandoc options are not ignored. Thus, for example,
431 pandoc --ignore-args -o foo.html -s foo.txt -- -e latin1
433 is equivalent to
435 pandoc -o foo.html -s
437`-v` or `--version`
438: prints the version number to STDERR.
440`-h` or `--help`
441: prints a usage message to STDERR.
443[Smartypants]: http://daringfireball.net/projects/smartypants/
444[LaTeXMathML]: http://math.etsu.edu/LaTeXMathML/
445[jsMath]: http://www.math.union.edu/~dpvc/jsmath/
446[gladTeX]: http://www.math.uio.no/~martingu/gladtex/index.html
447[mimeTeX]: http://www.forkosh.com/mimetex.html
449Templates
450=========
452When the `-s/--standalone` option is used, pandoc uses a template to
453add header and footer material that is needed for a self-standing
454document. To see the default template that is used, just type
456 pandoc -D FORMAT
458where `FORMAT` is the name of the output format. A custom template
459can be specified using the `--template` option. You can also override
460the system default templates for a given output format `FORMAT`
461by putting a file `templates/FORMAT.template` in the user data
462directory (see `--data-dir`, above).
464Templates may contain *variables*. Variable names are sequences of
465alphanumerics, `-`, and `_`, starting with a letter. A variable name
466surrounded by `$` signs will be replaced by its value. For example,
467the string `$title$` in
469 <title>$title$</title>
471will be replaced by the document title.
473To write a literal `$` in a template, use `$$`.
475Some variables are set automatically by pandoc. These vary somewhat
476depending on the output format, but include:
478`legacy-header`
479: contents specified by `-C/--custom-header`
480`header-includes`
481: contents specified by `-H/--include-in-header` (may have multiple
482 values)
483`toc`
484: non-null value if `--toc/--table-of-contents` was specified
485`include-before`
486: contents specified by `-B/--include-before-body` (may have
487 multiple values)
488`include-after`
489: contents specified by `-A/--include-after-body` (may have
490 multiple values)
491`body`
492: body of document
493`title`
494: title of document, as specified in title block
495`author`
496: author of document, as specified in title block (may have
497 multiple values)
498`date`
499: date of document, as specified in title block
501Variables may be set at the command line using the `-V/--variable`
502option. This allows users to include custom variables in their
503templates.
505Templates may contain conditionals. The syntax is as follows:
507 $if(variable)$
508 X
509 $else$
510 Y
511 $endif$
513This will include `X` in the template if `variable` has a non-null
514value; otherwise it will include `Y`. `X` and `Y` are placeholders for
515any valid template text, and may include interpolated variables or other
516conditionals. The `$else$` section may be omitted.
518When variables can have multiple values (for example, `author` in
519a multi-author document), you can use the `$for$` keyword:
521 $for(author)$
522 <meta name="author" content="$author$" />
523 $endfor$
525You can optionally specify a separator to be used between
526consecutive items:
528 $for(author)$$author$$sep$, $endfor$
530Pandoc's markdown vs. standard markdown
531=======================================
533In parsing markdown, Pandoc departs from and extends [standard markdown]
534in a few respects. Except where noted, these differences can
535be suppressed by specifying the `--strict` command-line option.
537[standard markdown]: http://daringfireball.net/projects/markdown/syntax
538 "Markdown syntax description"
540Backslash escapes
541-----------------
543Except inside a code block or inline code, any punctuation or space
544character preceded by a backslash will be treated literally, even if it
545would normally indicate formatting. Thus, for example, if one writes
547 *\*hello\**
549one will get
551 <em>*hello*</em>
553instead of
555 <strong>hello</strong>
557This rule is easier to remember than standard markdown's rule,
558which allows only the following characters to be backslash-escaped:
560 \`*_{}[]()>#+-.!
562A backslash-escaped space is parsed as a nonbreaking space. It will
563appear in TeX output as '`~`' and in HTML and XML as '`\&#160;`' or
564'`\&nbsp;`'.
566A backslash-escaped newline (i.e. a backslash occurring at the end of
567a line) is parsed as a hard line break. It will appear in TeX output as
568'`\\`' and in HTML as '`<br />`'. This is a nice alternative to
569markdown's "invisible" way of indicating hard line breaks using
570two trailing spaces on a line.
572Subscripts and superscripts
573---------------------------
575Superscripts may be written by surrounding the superscripted text by `^`
576characters; subscripts may be written by surrounding the subscripted
577text by `~` characters. Thus, for example,
579 H~2~O is a liquid. 2^10^ is 1024.
581If the superscripted or subscripted text contains spaces, these spaces
582must be escaped with backslashes. (This is to prevent accidental
583superscripting and subscripting through the ordinary use of `~` and `^`.)
584Thus, if you want the letter P with 'a cat' in subscripts, use
585`P~a\ cat~`, not `P~a cat~`.
587Strikeout
588---------
590To strikeout a section of text with a horizontal line, begin and end it
591with `~~`. Thus, for example,
593 This ~~is deleted text.~~
595Nested Lists
596------------
598Pandoc behaves differently from standard markdown on some "edge
599cases" involving lists. Consider this source:
601 1. First
602 2. Second:
603 - Fee
604 - Fie
605 - Foe
607 3. Third
609Pandoc transforms this into a "compact list" (with no `<p>` tags around
610"First", "Second", or "Third"), while markdown puts `<p>` tags around
611"Second" and "Third" (but not "First"), because of the blank space
612around "Third". Pandoc follows a simple rule: if the text is followed by
613a blank line, it is treated as a paragraph. Since "Second" is followed
614by a list, and not a blank line, it isn't treated as a paragraph. The
615fact that the list is followed by a blank line is irrelevant. (Note:
616Pandoc works this way even when the `--strict` option is specified. This
617behavior is consistent with the official markdown syntax description,
618even though it is different from that of `Markdown.pl`.)
620Ordered Lists
621-------------
623Unlike standard markdown, Pandoc allows ordered list items to be marked
624with uppercase and lowercase letters and roman numerals, in addition to
625arabic numerals. (This behavior can be turned off using the `--strict`
626option.) List markers may be enclosed in parentheses or followed by a
627single right-parentheses or period. They must be separated from the
628text that follows by at least one space, and, if the list marker is a
629capital letter with a period, by at least two spaces.[^2]
631[^2]: The point of this rule is to ensure that normal paragraphs
632 starting with people's initials, like
634 B. Russell was an English philosopher.
636 do not get treated as list items.
638 This rule will not prevent
640 (C) 2007 Joe Smith
642 from being interpreted as a list item. In this case, a backslash
643 escape can be used:
645 (C\) 2007 Joe Smith
647Pandoc also pays attention to the type of list marker used, and to the
648starting number, and both of these are preserved where possible in the
649output format. Thus, the following yields a list with numbers followed
650by a single parenthesis, starting with 9, and a sublist with lowercase
651roman numerals:
653 9) Ninth
654 10) Tenth
655 11) Eleventh
656 i. subone
657 ii. subtwo
658 iii. subthree
660Note that Pandoc pays attention only to the *starting* marker in a list.
661So, the following yields a list numbered sequentially starting from 2:
663 (2) Two
664 (5) Three
665 1. Four
666 * Five
668If default list markers are desired, use '`#.`':
670 #. one
671 #. two
672 #. three
674Definition lists
675----------------
677Pandoc supports definition lists, using a syntax inspired by
678[PHP Markdown Extra] and [reStructuredText]:[^3]
680 Term 1
682 : Definition 1
684 Term 2 with *inline markup*
686 : Definition 2
688 { some code, part of Definition 2 }
690 Third paragraph of definition 2.
692Each term must fit on one line, which may optionally be followed by
693a blank line, and must be followed by one or more definitions.
694A definition begins with a colon or tilde, which may be indented one
695or two spaces. A term may have multiple definitions, and each definition
696may consist of one or more block elements (paragraph, code block, list,
697etc.), each indented four spaces or one tab stop.
699If you leave space after the definition (as in the example above),
700the blocks of the definitions will be considered paragraphs. In some
701output formats, this will mean greater spacing between term/definition
702pairs. For a compact definition list, do not leave space between the
703definition and the next term:
705 Term 1
706 ~ Definition 1
707 Term 2
708 ~ Definition 2a
709 ~ Definition 2b
711[^3]: I have also been influenced by the suggestions of [David Wheeler](http://www.justatheory.com/computers/markup/modest-markdown-proposal.html).
713[PHP Markdown Extra]: http://www.michelf.com/projects/php-markdown/extra/
715Reference links
716---------------
718Pandoc allows implicit reference links with just a single set of
719brackets. So, the following links are equivalent:
721 1. Here's my [link]
722 2. Here's my [link][]
724 [link]: linky.com
726(Note: Pandoc works this way even if `--strict` is specified, because
727`Markdown.pl` 1.0.2b7 allows single-bracket links.)
729Footnotes
730---------
732Pandoc's markdown allows footnotes, using the following syntax:
734 Here is a footnote reference,[^1] and another.[^longnote]
736 [^1]: Here is the footnote.
738 [^longnote]: Here's one with multiple blocks.
740 Subsequent paragraphs are indented to show that they
741 belong to the previous footnote.
743 { some.code }
745 The whole paragraph can be indented, or just the first
746 line. In this way, multi-paragraph footnotes work like
747 multi-paragraph list items.
749 This paragraph won't be part of the note, because it isn't indented.
751The identifiers in footnote references may not contain spaces, tabs,
752or newlines. These identifiers are used only to correlate the
753footnote reference with the note itself; in the output, footnotes
754will be numbered sequentially.
756The footnotes themselves need not be placed at the end of the
757document. They may appear anywhere except inside other block elements
758(lists, block quotes, tables, etc.).
760Inline footnotes are also allowed (though, unlike regular notes,
761they cannot contain multiple paragraphs). The syntax is as follows:
763 Here is an inline note.^[Inlines notes are easier to write, since
764 you don't have to pick an identifier and move down to type the
765 note.]
767Inline and regular footnotes may be mixed freely.
769Tables
770------
772Two kinds of tables may be used. Both kinds presuppose the use of
773a fixed-width font, such as Courier.
775Simple tables look like this:
777 Right Left Center Default
778 ------- ------ ---------- -------
779 12 12 12 12
780 123 123 123 123
781 1 1 1 1
783 Table: Demonstration of simple table syntax.
785The headers and table rows must each fit on one line. Column
786alignments are determined by the position of the header text relative
787to the dashed line below it:[^4]
789 - If the dashed line is flush with the header text on the right side
790 but extends beyond it on the left, the column is right-aligned.
791 - If the dashed line is flush with the header text on the left side
792 but extends beyond it on the right, the column is left-aligned.
793 - If the dashed line extends beyond the header text on both sides,
794 the column is centered.
795 - If the dashed line is flush with the header text on both sides,
796 the default alignment is used (in most cases, this will be left).
798[^4]: This scheme is due to Michel Fortin, who proposed it on the
799 [Markdown discussion list](http://six.pairlist.net/pipermail/markdown-discuss/2005-March/001097.html).
801The table must end with a blank line, or a line of dashes followed by
802a blank line. A caption may optionally be provided (as illustrated in
803the example above). A caption is a paragraph beginning with the string
804`Table:`, which will be stripped off.
806The column headers may be omitted, provided a dashed line is used
807to end the table. For example:
809 ------- ------ ---------- -------
810 12 12 12 12
811 123 123 123 123
812 1 1 1 1
813 ------- ------ ---------- -------
815When headers are omitted, column alignments are determined on the basis
816of the first line of the table body. So, in the tables above, the columns
817would be right, left, center, and right aligned, respectively.
819Multiline tables allow headers and table rows to span multiple lines
820of text. Here is an example:
822 -------------------------------------------------------------
823 Centered Default Right Left
824 Header Aligned Aligned Aligned
825 ----------- ------- --------------- -------------------------
826 First row 12.0 Example of a row that
827 spans multiple lines.
829 Second row 5.0 Here's another one. Note
830 the blank line between
831 rows.
832 -------------------------------------------------------------
834 Table: Here's the caption. It, too, may span
835 multiple lines.
837These work like simple tables, but with the following differences:
839 - They must begin with a row of dashes, before the header text
840 (unless the headers are omitted).
841 - They must end with a row of dashes, then a blank line.
842 - The rows must be separated by blank lines.
844In multiline tables, the table parser pays attention to the widths of
845the columns, and the writers try to reproduce these relative widths in
846the output. So, if you find that one of the columns is too narrow in the
847output, try widening it in the markdown source.
849Headers may be omitted in multiline tables as well as simple tables:
851 ----------- ------- --------------- -------------------------
852 First row 12.0 Example of a row that
853 spans multiple lines.
855 Second row 5.0 Here's another one. Note
856 the blank line between
857 rows.
858 -------------------------------------------------------------
860 Table: Here's a multiline table without headers.
862It is possible for a multiline table to have just one row, but the row
863should be followed by a blank line (and then the row of dashes that ends
864the table), or the table may be interpreted as a simple table.
866Delimited Code blocks
867---------------------
869In addition to standard indented code blocks, Pandoc supports
870*delimited* code blocks. These begin with a row of three or more
871tildes (`~`) and end with a row of tildes that must be at least
872as long as the starting row. Everything between the tilde-lines
873is treated as code. No indentation is necessary:
875 ~~~~~~~
876 {code here}
877 ~~~~~~~
879Like regular code blocks, delimited code blocks must be separated
880from surrounding text by blank lines.
882If the code itself contains a row of tildes, just use a longer
883row of tildes at the start and end:
885 ~~~~~~~~~~~~~~~~
886 ~~~~~~~~~~
887 code including tildes
888 ~~~~~~~~~~
889 ~~~~~~~~~~~~~~~~
891Optionally, you may specify the language of the code block using
892this syntax:
894 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.haskell .numberLines}
895 qsort [] = []
896 qsort (x:xs) = qsort (filter (< x) xs) ++ [x] ++
897 qsort (filter (>= x) xs)
898 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
900Some output formats can use this information to do syntax highlighting.
901Currently, the only output format that uses this information is HTML.
903If pandoc has been compiled with syntax highlighting support, then the
904code block above will appear highlighted, with numbered lines. (To see
905which languages are supported, do `pandoc --version`.)
907If pandoc has not been compiled with syntax highlighting support, the
908code block above will appear as follows:
910 <pre class="haskell">
911 <code>
912 ...
913 </code>
914 </pre>
916Images with captions
917--------------------
919An image occurring by itself in a paragraph will be rendered as
920a figure with a caption.[^5] (In LaTeX, a figure environment will be
921used; in HTML, the image will be placed in a `div` with class
922`figure`, together with a caption in a `p` with class `caption`.)
923The image's alt text will be used as the caption.
925 ![This is the caption](/url/of/image.png)
927[^5]: This feature is not yet implemented for RTF, OpenDocument, or
928 ODT. In those formats, you'll just get an image in a paragraph by
929 itself, with no caption.
931If you just want a regular inline image, just make sure it is not
932the only thing in the paragraph. One way to do this is to insert a
933nonbreaking space after the image:
935 ![This image won't be a figure](/url/of/image.png)\
937Title blocks
938------------
940If the file begins with a title block
942 % title
943 % author(s) (separated by semicolons)
944 % date
946it will be parsed as bibliographic information, not regular text. (It
947will be used, for example, in the title of standalone LaTeX or HTML
948output.) The block may contain just a title, a title and an author,
949or all three elements. If you want to include an author but no
950title, or a title and a date but no author, you need a blank line:
952 %
953 % Author
955 % My title
956 %
957 % June 15, 2006
959The title may occupy multiple lines, but continuation lines must
960begin with leading space, thus:
962 % My title
963 on multiple lines
965If a document has multiple authors, the authors may be put on
966separate lines with leading space, or separated by semicolons, or
967both. So, all of the following are equivalent:
969 % Author One
970 Author Two
972 % Author One; Author Two
974 % Author One;
975 Author Two
977The date must fit on one line.
979All three metadata fields may contain standard inline formatting
980(italics, links, footnotes, etc.).
982Title blocks will always be parsed, but they will affect the output only
983when the `--standalone` (`-s`) option is chosen. In HTML output, titles
984will appear twice: once in the document head -- this is the title that
985will appear at the top of the window in a browser -- and once at the
986beginning of the document body. The title in the document head can have
987an optional prefix attached (`--title-prefix` or `-T` option). The title
988in the body appears as an H1 element with class "title", so it can be
989suppressed or reformatted with CSS. If a title prefix is specified with
990`-T` and no title block appears in the document, the title prefix will
991be used by itself as the HTML title.
993The man page writer extracts a title, man page section number, and
994other header and footer information from the title line. The title
995is assumed to be the first word on the title line, which may optionally
996end with a (single-digit) section number in parentheses. (There should
997be no space between the title and the parentheses.) Anything after
998this is assumed to be additional footer and header text. A single pipe
999character (`|`) should be used to separate the footer text from the header
1000text. Thus,
1002 % PANDOC(1)
1004will yield a man page with the title `PANDOC` and section 1.
1006 % PANDOC(1) Pandoc User Manuals
1008will also have "Pandoc User Manuals" in the footer.
1010 % PANDOC(1) Pandoc User Manuals | Version 4.0
1012will also have "Version 4.0" in the header.
1014Markdown in HTML blocks
1015-----------------------
1017While standard markdown leaves HTML blocks exactly as they are, Pandoc
1018treats text between HTML tags as markdown. Thus, for example, Pandoc
1019will turn
1021 <table>
1022 <tr>
1023 <td>*one*</td>
1024 <td>[a link](http://google.com)</td>
1025 </tr>
1026 </table>
1028into
1030 <table>
1031 <tr>
1032 <td><em>one</em></td>
1033 <td><a href="http://google.com">a link</a></td>
1034 </tr>
1035 </table>
1037whereas `Markdown.pl` will preserve it as is.
1039There is one exception to this rule: text between `<script>` and
1040`</script>` tags is not interpreted as markdown.
1042This departure from standard markdown should make it easier to mix
1043markdown with HTML block elements. For example, one can surround
1044a block of markdown text with `<div>` tags without preventing it
1045from being interpreted as markdown.
1047Header identifiers in HTML
1048--------------------------
1050Each header element in pandoc's HTML output is given a unique
1051identifier. This identifier is based on the text of the header. To
1052derive the identifier from the header text,
1054 - Remove all formatting, links, etc.
1055 - Remove all punctuation, except underscores, hyphens, and periods.
1056 - Replace all spaces and newlines with hyphens.
1057 - Convert all alphabetic characters to lowercase.
1058 - Remove everything up to the first letter (identifiers may
1059 not begin with a number or punctuation mark).
1060 - If nothing is left after this, use the identifier `section`.
1062Thus, for example,
1064 Header Identifier
1065 ------------------------------------- ---------------------------
1066 Header identifiers in HTML `header-identifiers-in-html`
1067 *Dogs*?--in *my* house? `dogs--in-my-house`
1068 [HTML], [S5], or [RTF]? `html-s5-or-rtf`
1069 3. Applications `applications`
1070 33 `section`
1072These rules should, in most cases, allow one to determine the identifier
1073from the header text. The exception is when several headers have the
1074same text; in this case, the first will get an identifier as described
1075above; the second will get the same identifier with `-1` appended; the
1076third with `-2`; and so on.
1078These identifiers are used to provide link targets in the table of
1079contents generated by the `--toc|--table-of-contents` option. They
1080also make it easy to provide links from one section of a document to
1081another. A link to this section, for example, might look like this:
1083 See the section on [header identifiers](#header-identifiers-in-html).
1085Note, however, that this method of providing links to sections works
1086only in HTML.
1088Blank lines before headers and blockquotes
1089------------------------------------------
1091Standard markdown syntax does not require a blank line before a header
1092or blockquote. Pandoc does require this (except, of course, at the
1093beginning of the document). The reason for the requirement is that
1094it is all too easy for a `>` or `#` to end up at the beginning of a
1095line by accident (perhaps through line wrapping). Consider, for
1096example:
1098 I like several of their flavors of ice cream: #22, for example, and
1099 #5.
1101Math
1102----
1104Anything between two $ characters will be treated as TeX math. The
1105opening $ must have a character immediately to its right, while the
1106closing $ must have a character immediately to its left. Thus,
1107`$20,000 and $30,000` won't parse as math. If for some reason
1108you need to enclose text in literal $ characters, backslash-escape
1109them and they won't be treated as math delimiters.
1111TeX math will be printed in all output formats. In Markdown,
1112reStructuredText, LaTeX, and ConTeXt output, it will appear verbatim
1113between $ characters.
1115In reStructuredText output, it will be rendered using an interpreted
1116text role `:math:`, as described
1117[here](http://www.american.edu/econ/itex2mml/mathhack.rst).
1119In Texinfo output, it will be rendered inside a `@math` command.
1121In groff man output, it will be rendered verbatim without $'s.
1123In MediaWiki output, it will be rendered inside `<math>` tags.
1125In RTF, Docbook, and OpenDocument output, it will be rendered, as far as
1126possible, using unicode characters, and will otherwise appear verbatim.
1127Unknown commands and symbols, and commands that cannot be dealt with
1128this way (like `\frac`), will be rendered verbatim. So the results may
1129be a mix of raw TeX code and properly rendered unicode math.
1131In HTML and S5 output, the way math is rendered will depend on the
1132command-line options selected:
11341. The default is to render TeX math as far as possible using unicode
1135 characters, as with RTF, Docbook, and OpenDocument output. Formulas
1136 are put inside a `span` with `class="math"`, so that they may be
1137 styled differently from the surrounding text if needed.
11392. If the `--latexmathml` option is used, TeX math will be displayed
1140 between $ or $$ characters and put in `<span>` tags with class `LaTeX`.
1141 The [LaTeXMathML] script will be used to render it as formulas.
1142 (This trick does not work in all browsers, but it works in Firefox.
1143 In browsers that do not support LaTeXMathML, TeX math will appear
1144 verbatim between $ characters.)
11463. If the `--jsmath` option is used, TeX math will be put inside
1147 `<span>` tags (for inline math) or `<div>` tags (for display math)
1148 with class `math`. The [jsMath] script will be used to render
1149 it.
11514. If the `--mimetex` option is used, the [mimeTeX] CGI script will
1152 be called to generate images for each TeX formula. This should
1153 work in all browsers. The `--mimetex` option takes an optional URL
1154 as argument. If no URL is specified, it will be assumed that the
1155 mimeTeX CGI script is at `/cgi-bin/mimetex.cgi`.
11575. If the `--gladtex` option is used, TeX formulas will be enclosed
1158 in `<eq>` tags in the HTML output. The resulting `htex` file may then
1159 be processed by [gladTeX], which will produce image files for each
1160 formula and an `html` file with links to these images. So, the
1161 procedure is:
1163 pandoc -s --gladtex myfile.txt -o myfile.htex
1164 gladtex -d myfile-images myfile.htex
1165 # produces myfile.html and images in myfile-images
1167Inline TeX
1168----------
1170Inline TeX commands will be preserved and passed unchanged to the
1171LaTeX and ConTeXt writers. Thus, for example, you can use LaTeX to
1172include BibTeX citations:
1174 This result was proved in \cite{jones.1967}.
1176Note that in LaTeX environments, like
1178 \begin{tabular}{|l|l|}\hline
1179 Age & Frequency \\ \hline
1180 18--25 & 15 \\
1181 26--35 & 33 \\
1182 36--45 & 22 \\ \hline
1183 \end{tabular}
1185the material between the begin and end tags will be interpreted as raw
1186LaTeX, not as markdown.
1188Inline LaTeX is ignored in output formats other than Markdown, LaTeX,
1189and ConTeXt.
1191Producing S5 with Pandoc
1192========================
1194Producing an [S5] web-based slide show with Pandoc is easy. A title
1195page is constructed automatically from the document's title block (see
1196above). Each section (with a level-one header) produces a single slide.
1197(Note that if the section is too big, the slide will not fit on the page;
1198S5 is not smart enough to produce multiple pages.)
1200Here's the markdown source for a simple slide show, `eating.txt`:
1202 % Eating Habits
1203 % John Doe
1204 % March 22, 2005
1206 # In the morning
1208 - Eat eggs
1209 - Drink coffee
1211 # In the evening
1213 - Eat spaghetti
1214 - Drink wine
1216To produce the slide show, simply type
1218 pandoc -w s5 -s eating.txt > eating.html
1220and open up `eating.html` in a browser.
1222Note that by default, the S5 writer produces lists that display
1223"all at once." If you want your lists to display incrementally
1224(one item at a time), use the `-i` option. If you want a
1225particular list to depart from the default (that is, to display
1226incrementally without the `-i` option and all at once with the
1227`-i` option), put it in a block quote:
1229 > - Eat spaghetti
1230 > - Drink wine
1232In this way incremental and nonincremental lists can be mixed in
1233a single document.
1235Note: the S5 file produced by pandoc with the `-s/--standalone` option
1236embeds the javascript and CSS required to show the slides. Thus it
1237does not depend on any additional files: you can send the HTML file to
1238others, and they will be able to view the slide show just by opening
1239it. However, if you intend to produce several S5 slide shows, and you
1240are displaying them on your own website, it is better to keep the S5
1241javascript and CSS files separate from the slide shows themselves, so
1242that they may be cached. The best approach in this case is to use pandoc
1243without the `-s` option to produce the body of the S5 document, which
1244can then be inserted into an HTML template that links to the javascript
1245and CSS files required by S5. (See the instructions on the S5 website.)
1246Alternatively, you may use `-s` together with the `--template`
1247option to specify a custom template.
1249You can change the style of the slides by putting customized CSS files
1250in `$DATADIR/s5/default`, where `$DATADIR` is the user data directory
1251(see `--data-dir`, above). The originals may be found in pandoc's system
1252data directory (generally `$CABALDIR/pandoc-VERSION/s5/default`). Pandoc
1253will look there for any files it does not find in the user data
1254directory.
1256Literate Haskell support
1257========================
1259If you append `+lhs` to an appropriate input or output format (`markdown`,
1260`rst`, or `latex` for input or output; `html` for output only), pandoc
1261will treat the document as literate Haskell source. This means that
1263 - In markdown input, "bird track" sections will be parsed as Haskell
1264 code rather than block quotations. Text between `\begin{code}`
1265 and `\end{code}` will also be treated as Haskell code.
1267 - In markdown output, code blocks with class `haskell` will be
1268 rendered using bird tracks, and block quotations will be
1269 indented one space, so they will not be treated as Haskell code.
1270 In addition, headers will be rendered setext-style (with underlines)
1271 rather than atx-style (with '#' characters). (This is because ghc
1272 treats '#' characters in column 1 as introducing line numbers.)
1274 - In restructured text input, "bird track" sections will be parsed
1275 as Haskell code.
1277 - In restructured text output, code blocks with class `haskell` will
1278 be rendered using bird tracks.
1280 - In LaTeX input, text in `code` environments will be parsed as
1281 Haskell code.
1283 - In LaTeX output, code blocks with class `haskell` will be rendered
1284 inside `code` environments.
1286 - In HTML output, code blocks with class `haskell` will be rendered
1287 with class `literatehaskell` and bird tracks.
1289Examples:
1291 pandoc -f markdown+lhs -t html
1293reads literate Haskell source formatted with markdown conventions and writes
1294ordinary HTML (without bird tracks).
1296 pandoc -f markdown+lhs -t html+lhs
1298writes HTML with the Haskell code in bird tracks, so it can be copied
1299and pasted as literate Haskell source.