git.iko.soy/typeable/pandoc
on bf42fa1 help sign in
1261 lines 49 kB history raw
1% Pandoc User's Guide
2% John MacFarlane
3% December 7, 2009
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 [markdown], [reStructuredText], [HTML], [LaTeX], [ConTeXt],
9[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-9 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.)
43Contributors: Recai Oktaş (build system, debian package, wrapper
44scripts), Peter Wang (Texinfo writer), Andrea Rossato (OpenDocument writer).
46[GPL]: http://www.gnu.org/copyleft/gpl.html "GNU General Public License"
48Using Pandoc
49============
51If you run `pandoc` without arguments, it will accept input from
52stdin. If you run it with file names as arguments, it will take input
53from those files. By default, `pandoc` writes its output to stdout.[^1]
54If you want to write to a file, use the `-o` option:
56 pandoc -o hello.html hello.txt
58[^1]: The exception is for `odt`. Since this is a binary output format,
59 an output file must be specified explicitly.
61Note that you can specify multiple input files on the command line.
62`pandoc` will concatenate them all (with blank lines between them)
63before parsing:
65 pandoc -s ch1.txt ch2.txt refs.txt > book.html
67(The `-s` option here tells `pandoc` to produce a standalone HTML file,
68with a proper header, rather than a fragment. For more details on this
69and many other command-line options, see below.)
71The format of the input and output can be specified explicitly using
72command-line options. The input format can be specified using the
73`-r/--read` or `-f/--from` options, the output format using the
74`-w/--write` or `-t/--to` options. Thus, to convert `hello.txt` from
75markdown to LaTeX, you could type:
77 pandoc -f markdown -t latex hello.txt
79To convert `hello.html` from html to markdown:
81 pandoc -f html -t markdown hello.html
83Supported output formats include `markdown`, `latex`, `context`
84(ConTeXt), `html`, `rtf` (rich text format), `rst`
85(reStructuredText), `docbook` (DocBook XML), `opendocument`
86(OpenDocument XML), `odt` (OpenOffice text document), `texinfo`, (GNU
87Texinfo), `mediawiki` (MediaWiki markup), `man` (groff man), and `s5`
88(which produces an HTML file that acts like powerpoint).
90Supported input formats include `markdown`, `html`, `latex`, and `rst`.
91Note that the `rst` reader only parses a subset of reStructuredText
92syntax. For example, it doesn't handle tables, option lists, or
93footnotes. But for simple documents it should be adequate. The `latex`
94and `html` readers are also limited in what they can do. Because the
95`html` reader is picky about the HTML it parses, it is recommended that
96you pipe HTML through [HTML Tidy] before sending it to `pandoc`, or use
97the `html2markdown` script described below.
99If you don't specify a reader or writer explicitly, `pandoc` will
100try to determine the input and output format from the extensions of
101the input and output filenames. Thus, for example,
103 pandoc -o hello.tex hello.txt
105will convert `hello.txt` from markdown to LaTeX. If no output file
106is specified (so that output goes to stdout), or if the output file's
107extension is unknown, the output format will default to HTML.
108If no input file is specified (so that input comes from stdin), or
109if the input files' extensions are unknown, the input format will
110be assumed to be markdown unless explicitly specified.
112Character encodings
113-------------------
115All input is assumed to be in the UTF-8 encoding, and all output
116is in UTF-8. If your local character encoding is not UTF-8 and you use
117accented or foreign characters, you should pipe the input and output
118through [`iconv`]. For example,
120 iconv -t utf-8 source.txt | pandoc | iconv -f utf-8 > output.html
122will convert `source.txt` from the local encoding to UTF-8, then
123convert it to HTML, then convert back to the local encoding,
124putting the output in `output.html`.
126The shell scripts (described below) automatically convert the input
127from the local encoding to UTF-8 before running them through `pandoc`,
128then convert the output back to the local encoding.
130Shell scripts
131=============
133Three shell scripts, `markdown2pdf`, `html2markdown`, and `hsmarkdown`,
134are included in the standard Pandoc installation. (They are not included
135in the Windows binary package, as they require a POSIX shell, but they
136may be used in Windows under Cygwin.)
1381. `markdown2pdf` produces a PDF file from markdown-formatted
139 text, using `pandoc` and `pdflatex`. The default
140 behavior of `markdown2pdf` is to create a file with the same
141 base name as the first argument and the extension `pdf`; thus,
142 for example,
144 markdown2pdf sample.txt endnotes.txt
146 will produce `sample.pdf`. (If `sample.pdf` exists already,
147 it will be backed up before being overwritten.) An output file
148 name can be specified explicitly using the `-o` option:
150 markdown2pdf -o book.pdf chap1 chap2
152 If no input file is specified, input will be taken from stdin.
153 All of `pandoc`'s options will work with `markdown2pdf` as well.
155 `markdown2pdf` assumes that `pdflatex` is in the path. It also
156 assumes that the following LaTeX packages are available:
157 `unicode`, `fancyhdr` (if you have verbatim text in footnotes),
158 `graphicx` (if you use images), `array` (if you use tables),
159 and `ulem` (if you use strikeout text). If they are not already
160 included in your LaTeX distribution, you can get them from
161 [CTAN]. A full [TeX Live] or [MacTeX] distribution will have all of
162 these packages.
1642. `html2markdown` grabs a web page from a file or URL and converts
165 it to markdown-formatted text, using `tidy` and `pandoc`.
167 All of `pandoc`'s options will work with `html2markdown` as well.
168 In addition, the following special options may be used.
169 The special options must be separated from the `html2markdown`
170 command and any regular Pandoc options by the delimiter `--`:
172 html2markdown -o out.txt -- -e latin1 -g curl google.com
174 The `-e` or `--encoding` option specifies the character encoding
175 of the HTML input. If this option is not specified, and input
176 is not from stdin, `html2markdown` will attempt to determine the
177 page's character encoding from the "Content-type" meta tag.
178 If this is not present, UTF-8 is assumed.
180 The `-g` or `--grabber` option specifies the command to be used to
181 fetch the contents of a URL:
183 html2markdown -g 'curl --user foo:bar' www.mysite.com
185 If this option is not specified, `html2markdown` searches for an
186 available program (`wget`, `curl`, or a text-mode browser) to fetch
187 the contents of a URL.
189 `html2markdown` requires [HTML Tidy], which must be in the path.
190 It uses [`iconv`] for character encoding conversions; if `iconv`
191 is absent, it will still work, but it will treat everything as UTF-8.
1933. `hsmarkdown` is designed to be used as a drop-in replacement for
194 `Markdown.pl`. It forces `pandoc` to convert from markdown to
195 HTML, and to use the `--strict` flag for maximal compliance with
196 official markdown syntax. (All of Pandoc's syntax extensions and
197 variants, described below, are disabled.) No other command-line
198 options are allowed. (In fact, options will be interpreted as
199 filenames.)
201 As an alternative to using the `hsmarkdown` shell script, the
202 user may create a symbolic link to `pandoc` called `hsmarkdown`.
203 When invoked under the name `hsmarkdown`, `pandoc` will behave
204 as if the `--strict` flag had been selected, and no command-line
205 options will be recognized. However, this approach does not work
206 under Cygwin, due to problems with its simulation of symbolic
207 links.
209[Cygwin]: http://www.cygwin.com/
210[HTML Tidy]: http://tidy.sourceforge.net/
211[`iconv`]: http://www.gnu.org/software/libiconv/
212[CTAN]: http://www.ctan.org "Comprehensive TeX Archive Network"
213[TeX Live]: http://www.tug.org/texlive/
214[MacTeX]: http://www.tug.org/mactex/
216Command-line options
217====================
219Various command-line options can be used to customize the output.
220For further documentation, see the `pandoc(1)` man page.
222`-f`, `--from`, `-r`, or `--read` *format*
223: specifies the input format (the format Pandoc will be converting
224 *from*). *format* can be `native`, `markdown`, `rst`, `html`, or
225 `latex`. (`+lhs` can be appended to indicate that the input should
226 be treated as literate Haskell source. See
227 [Literate Haskell support](#literate-haskell-support), below.)
229`-t`, `--to`, `-w`, or `--write` *format*
230: specifies the output format -- the format Pandoc will
231 be converting *to*. *format* can be `native`, `html`, `s5`,
232 `docbook`, `opendocument`, `latex`, `context`, `markdown`, `man`,
233 `rst`, and `rtf`. (`+lhs` can be appended to indicate that the
234 output should be treated as literate Haskell source. See
235 [Literate Haskell support](#literate-haskell-support), below.)
237`-s` or `--standalone`
238: indicates that a standalone document is to be produced (with
239 appropriate headers and footers), rather than a fragment.
241`-o` or `--output` *filename*
242: sends output to *filename*. If this option is not specified,
243 or if its argument is `-`, output will be sent to stdout.
244 (Exception: if the output format is `odt`, output to stdout
245 is disabled.)
247`-p` or `--preserve-tabs`
248: causes tabs in the source text to be preserved, rather than converted
249 to spaces (the default).
251`--tab-stop` *tabstop*
252: sets the number of spaces per tab to *tabstop* (defaults to 4).
254`--strict`
255: specifies that strict markdown syntax is to be used, without
256 pandoc's usual extensions and variants (described below). When the
257 input format is HTML, this means that constructs that have no
258 equivalents in standard markdown (e.g. definition lists or strikeout
259 text) will be parsed as raw HTML.
261`--reference-links`
262: causes reference-style links to be used in markdown
263 and reStructuredText output. By default inline links are used.
265`-R` or `--parse-raw`
266: causes the HTML and LaTeX readers to parse HTML codes and LaTeX
267 environments that it can't translate as raw HTML or LaTeX. Raw HTML can
268 be printed in markdown, reStructuredText, HTML, and S5 output; raw LaTeX
269 can be printed in markdown, reStructuredText, LaTeX, and ConTeXt output.
270 The default is for the readers to omit untranslatable HTML codes and
271 LaTeX environments. (The LaTeX reader does pass through untranslatable
272 LaTeX *commands*, even if `-R` is not specified.)
274`-C` or `--custom-header` *filename*
275: can be used to specify a custom document header. To see the headers
276 used by default, use the `-D` option: for example, `pandoc -D html`
277 prints the default HTML header. Implies `--standalone`.
279`--toc` or `--table-of-contents`
280: includes an automatically generated table of contents (or, in the
281 case of `latex`, `context`, and `rst`, an instruction to create
282 one) in the output document. This option has no effect with `man`,
283 `docbook`, or `s5` output formats.
285`--template=`*file*
286: uses *file* as a custom template for the generated document. Implies
287 `-s`. See [Templates](#templates) below for a description
288 of template syntax. If this option is not used, a default
289 template appropriate for the output format will be used. See also
290 `-D/--print-default-template`.
292`-V` *key=val*, `--variable=`*key:val*
293: sets the template variable *key* to the value *val* when rendering the
294 document in standalone mode. This is only useful when the
295 `--template` option is used to specify a custom template, since
296 pandoc automatically sets the variables used in the default
297 templates.
299`-c` or `--css` *filename*
300: allows the user to specify a custom stylesheet that will be linked to
301 in HTML and S5 output. This option can be used repeatedly to include
302 multiple stylesheets. They will be included in the order specified.
303 Implies `--standalone`.
305`-H` or `--include-in-header` *filename*
306: includes the contents of *filename* (verbatim) at the end of the
307 document header. This can be used, for example, to include special
308 CSS or javascript in HTML documents. This option can be used
309 repeatedly to include multiple files in the header. They will be
310 included in the order specified. Implies `--standalone`.
312`-B` or `--include-before-body` *filename*
313: includes the contents of *filename* (verbatim) at the beginning of
314 the document body (e.g. after the `<body>` tag in HTML, or the
315 `\begin{document}` command in LaTeX). This can be used to include
316 navigation bars or banners in HTML documents. This option can be
317 used repeatedly to include multiple files. They will be included in
318 the order specified.
320`-A` or `--include-after-body` *filename*
321: includes the contents of *filename* (verbatim) at the end of
322 the document body (before the `</body>` tag in HTML, or the
323 `\end{document}` command in LaTeX). This option can be be used
324 repeatedly to include multiple files. They will be included in the
325 order specified.
327`-D` or `--print-default-template` *format*
328: prints the default template for an output *format*. (See `-t`
329 for a list of possible *format*s.)
331`-T` or `--title-prefix` *string*
332: includes *string* as a prefix at the beginning of the title that
333 appears in the HTML header (but not in the title as it appears at
334 the beginning of the HTML body). (See below on
335 [Title Blocks](#title-blocks).) Implies `--standalone`.
337`-S` or `--smart`
338: causes `pandoc` to produce typographically correct output, along the
339 lines of John Gruber's [Smartypants]. Straight quotes are converted
340 to curly quotes, `---` to dashes, and `...` to ellipses. Nonbreaking
341 spaces are inserted after certain abbreviations, such as "Mr."
342 (Note: This option is only significant when the input format is
343 `markdown`. It is selected automatically when the output format is
344 `latex` or `context`.)
346`-m`*[url]* or `--latexmathml`*[=url]*
347: causes `pandoc` to use the [LaTeXMathML] script to display
348 TeX math in HTML or S5. If a local copy of `LaTeXMathML.js` is
349 available on the webserver where the page will be viewed, provide a
350 *url* and a link will be inserted in the generated HTML or S5. If
351 no *url* is provided, the contents of the script will be inserted
352 directly; this provides portability at the price of efficiency. If
353 you plan to use math on several pages, it is much better to link to
354 a copy of `LaTeXMathML.js`, which can be cached. (See `--jsmath`,
355 `--gladtex`, and `--mimetex` for alternative ways of dealing with
356 math in HTML.)
358`--jsmath`*=[url]*
359: causes `pandoc` to use the [jsMath] script to display
360 TeX math in HTML or S5. The *url* should point to the jsMath load
361 script (e.g. `jsMath/easy/load.js`). If it is provided, a link to it
362 will be included in the header of standalone HTML documents.
363 (See `--latexmathml`, `--mimetex`, and `--gladtex` for alternative
364 ways of dealing with math in HTML.)
366`--gladtex`*[=url]*
367: causes TeX formulas to be enclosed in `<eq>` tags in HTML or S5 output.
368 This output can then be processed by [gladTeX] to produce links to
369 images with the typeset formulas. (See `--latexmathml`, `--jsmath`, and
370 `--mimetex` for alternative ways of dealing with math in HTML.)
372`--mimetex`*[=url]*
373: causes TeX formulas to be replaced by `<img>` tags linking to the
374 [mimeTeX] CGI script, which will produce images with the typeset
375 formulas. (See `--latexmathml`, `--jsmath`, and `--gladtex` for alternative
376 ways of dealing with math in HTML.)
378`-i` or `--incremental`
379: causes all lists in S5 output to be displayed incrementally by
380 default (one item at a time). The normal default is for lists to be
381 displayed all at once.
383`-N` or `--number-sections`
384: causes sections to be numbered in LaTeX, ConTeXt, or HTML output.
385 By default, sections are not numbered.
387`--no-wrap`
388: disables text-wrapping in output. By default, text is wrapped
389 appropriately for the output format.
391`--sanitize-html`
392: sanitizes HTML (in markdown or HTML input) using a whitelist.
393 Unsafe tags are replaced by HTML comments; unsafe attributes
394 are omitted. URIs in links and images are also checked against a
395 whitelist of URI schemes.
397`--email-obfuscation`*=none|javascript|references*
398: specifies a method for obfuscating `mailto:` links in HTML documents.
399 *none* leaves `mailto:` links as they are. *javascript* obfuscates
400 them using javascript. *references* obfuscates them by printing their
401 letters as decimal or hexadecimal character references. If `--strict`
402 is specified, *references* is used regardless of the presence
403 of this option.
405`--id-prefix`*=string*
406: specifies a prefix to be added to all automatically generated identifiers
407 in HTML output. This is useful for preventing duplicate identifiers
408 when generating fragments to be included in other pages.
410`--indented-code-classes`*=classes*
411: specifies classes to use for indented code blocks--for example,
412 `perl,numberLines` or `haskell`. Multiple classes may be separated
413 by spaces or commas.
415`--dump-args`
416: is intended to make it easier to create wrapper scripts that use
417 Pandoc. It causes Pandoc to dump information about the arguments
418 with which it was called to stdout, then exit. The first line
419 printed is the name of the output file specified using the `-o`
420 or `--output` option, or `-` if output would go to stdout. The
421 remaining lines, if any, list command-line arguments. These will
422 include the names of input files and any special options passed
423 after ` -- ` on the command line. So, for example,
425: pandoc --dump-args -o foo.html -s foo.txt \
426 appendix.txt -- -e latin1
428: will cause the following to be printed to stdout:
430: foo.html foo.txt appendix.txt -e latin1
432`--ignore-args`
433: causes Pandoc to ignore all command-line arguments.
434 Regular Pandoc options are not ignored. Thus, for example,
436: pandoc --ignore-args -o foo.html -s foo.txt -- -e latin1
438: is equivalent to
440: pandoc -o foo.html -s
442`-v` or `--version`
443: prints the version number to STDERR.
445`-h` or `--help`
446: prints a usage message to STDERR.
448[Smartypants]: http://daringfireball.net/projects/smartypants/
449[LaTeXMathML]: http://math.etsu.edu/LaTeXMathML/
450[jsMath]: http://www.math.union.edu/~dpvc/jsmath/
451[gladTeX]: http://www.math.uio.no/~martingu/gladtex/index.html
452[mimeTeX]: http://www.forkosh.com/mimetex.html
454Templates
455=========
457When the `-s/--standalone` option is used, pandoc uses a template to
458add header and footer material that is needed for a self-standing
459document. To see the default template that is used, just type
461 pandoc --print-default-template=FORMAT
463where `FORMAT` is the name of the output format. A custom template
464can be specified using the `--template` option.
466Templates may contain *variables*. Variable names are sequences of
467alphanumerics, `-`, and `_`, starting with a letter. A variable name
468surrounded by `$` signs will be replaced by its value. For example,
469the string `$title$` in
471 <title>$title$</title>
473will be replaced by the document title.
475To write a literal `$` in a template, use `$$`.
477Some variables are set automatically by pandoc. These vary somewhat
478depending on the output format, but include:
480`legacy-header`
481: contents specified by `-C/--custom-header`
482`header-includes`
483: contents specified by `-H/--include-in-header`
484`toc`
485: non-null value if `--toc/--table-of-contents` was specified
486`body`
487: body of document
488`title`
489: title of document, as specified in title block
490`author`
491: author of document, as specified in title block
492`date`
493: date of document, as specified in title block
495Variables may be set at the command line using the `-V/--variable`
496option. This allows users to include custom variables in their
497templates.
499Templates may contain conditionals. The syntax is as follows:
501 $if(variable)$
502 X
503 $else$
504 Y
505 $endif$
507This will include `X` in the template if `variable` has a non-null
508value; otherwise it will include `Y`. `X` and `Y` are placeholders for
509any valid template text, and may include interpolated variables or other
510conditionals. The `$else$` section may be omitted.
512When variables can have multiple values (for example, `author` in
513a multi-author document), you can use the `$for$` keyword:
515 $for(author)$
516 <meta name="author" content="$author$" />
517 $endfor$
519You can optionally specify a separator to be used between
520consecutive items:
522 $for(author)$$author$$sep$, $endfor$
524Pandoc's markdown vs. standard markdown
525=======================================
527In parsing markdown, Pandoc departs from and extends [standard markdown]
528in a few respects. (To run Pandoc on the official markdown test suite,
529type `make test-markdown`.) Except where noted, these differences can
530be suppressed by specifying the `--strict` command-line option or by
531using the `hsmarkdown` wrapper.
533[standard markdown]: http://daringfireball.net/projects/markdown/syntax
534 "Markdown syntax description"
536Backslash escapes
537-----------------
539Except inside a code block or inline code, any punctuation or space
540character preceded by a backslash will be treated literally, even if it
541would normally indicate formatting. Thus, for example, if one writes
543 *\*hello\**
545one will get
547 <em>*hello*</em>
549instead of
551 <strong>hello</strong>
553This rule is easier to remember than standard markdown's rule,
554which allows only the following characters to be backslash-escaped:
556 \`*_{}[]()>#+-.!
558A backslash-escaped space is parsed as a nonbreaking space. It will
559appear in TeX output as '`~`' and in HTML and XML as '`\&#160;`' or
560'`\&nbsp;`'.
562A backslash-escaped newline (i.e. a backslash occurring at the end of
563a line) is parsed as a hard line break. It will appear in TeX output as
564'`\\`' and in HTML as '`<br />`'. This is a nice alternative to
565markdown's "invisible" way of indicating hard line breaks using
566two trailing spaces on a line.
568Subscripts and superscripts
569---------------------------
571Superscripts may be written by surrounding the superscripted text by `^`
572characters; subscripts may be written by surrounding the subscripted
573text by `~` characters. Thus, for example,
575 H~2~O is a liquid. 2^10^ is 1024.
577If the superscripted or subscripted text contains spaces, these spaces
578must be escaped with backslashes. (This is to prevent accidental
579superscripting and subscripting through the ordinary use of `~` and `^`.)
580Thus, if you want the letter P with 'a cat' in subscripts, use
581`P~a\ cat~`, not `P~a cat~`.
583Strikeout
584---------
586To strikeout a section of text with a horizontal line, begin and end it
587with `~~`. Thus, for example,
589 This ~~is deleted text.~~
591Nested Lists
592------------
594Pandoc behaves differently from standard markdown on some "edge
595cases" involving lists. Consider this source:
597 1. First
598 2. Second:
599 - Fee
600 - Fie
601 - Foe
603 3. Third
605Pandoc transforms this into a "compact list" (with no `<p>` tags around
606"First", "Second", or "Third"), while markdown puts `<p>` tags around
607"Second" and "Third" (but not "First"), because of the blank space
608around "Third". Pandoc follows a simple rule: if the text is followed by
609a blank line, it is treated as a paragraph. Since "Second" is followed
610by a list, and not a blank line, it isn't treated as a paragraph. The
611fact that the list is followed by a blank line is irrelevant. (Note:
612Pandoc works this way even when the `--strict` option is specified. This
613behavior is consistent with the official markdown syntax description,
614even though it is different from that of `Markdown.pl`.)
616Ordered Lists
617-------------
619Unlike standard markdown, Pandoc allows ordered list items to be marked
620with uppercase and lowercase letters and roman numerals, in addition to
621arabic numerals. (This behavior can be turned off using the `--strict`
622option.) List markers may be enclosed in parentheses or followed by a
623single right-parentheses or period. They must be separated from the
624text that follows by at least one space, and, if the list marker is a
625capital letter with a period, by at least two spaces.[^2]
627[^2]: The point of this rule is to ensure that normal paragraphs
628 starting with people's initials, like
630 B. Russell was an English philosopher.
632 do not get treated as list items.
634 This rule will not prevent
636 (C) 2007 Joe Smith
638 from being interpreted as a list item. In this case, a backslash
639 escape can be used:
641 (C\) 2007 Joe Smith
643Pandoc also pays attention to the type of list marker used, and to the
644starting number, and both of these are preserved where possible in the
645output format. Thus, the following yields a list with numbers followed
646by a single parenthesis, starting with 9, and a sublist with lowercase
647roman numerals:
649 9) Ninth
650 10) Tenth
651 11) Eleventh
652 i. subone
653 ii. subtwo
654 iii. subthree
656Note that Pandoc pays attention only to the *starting* marker in a list.
657So, the following yields a list numbered sequentially starting from 2:
659 (2) Two
660 (5) Three
661 1. Four
662 * Five
664If default list markers are desired, use '`#.`':
666 #. one
667 #. two
668 #. three
670Definition lists
671----------------
673Pandoc supports definition lists, using a syntax inspired by
674[PHP Markdown Extra] and [reStructuredText]:[^3]
676 Term 1
678 : Definition 1
680 Term 2 with *inline markup*
682 : Definition 2
684 { some code, part of Definition 2 }
686 Third paragraph of definition 2.
688Each term must fit on one line, which may optionally be followed by
689a blank line, and must be followed by one or more definitions.
690A definition begins with a colon or tilde, which may be indented one
691or two spaces. A term may have multiple definitions, and each definition
692may consist of one or more block elements (paragraph, code block, list,
693etc.), each indented four spaces or one tab stop.
695If you leave space after the definition (as in the example above),
696the blocks of the definitions will be considered paragraphs. In some
697output formats, this will mean greater spacing between term/definition
698pairs. For a compact definition list, do not leave space between the
699definition and the next term:
701 Term 1
702 ~ Definition 1
703 Term 2
704 ~ Definition 2a
705 ~ Definition 2b
707[^3]: I have also been influenced by the suggestions of [David Wheeler](http://www.justatheory.com/computers/markup/modest-markdown-proposal.html).
709[PHP Markdown Extra]: http://www.michelf.com/projects/php-markdown/extra/
711Reference links
712---------------
714Pandoc allows implicit reference links with just a single set of
715brackets. So, the following links are equivalent:
717 1. Here's my [link]
718 2. Here's my [link][]
720 [link]: linky.com
722(Note: Pandoc works this way even if `--strict` is specified, because
723`Markdown.pl` 1.0.2b7 allows single-bracket links.)
725Footnotes
726---------
728Pandoc's markdown allows footnotes, using the following syntax:
730 Here is a footnote reference,[^1] and another.[^longnote]
732 [^1]: Here is the footnote.
734 [^longnote]: Here's one with multiple blocks.
736 Subsequent paragraphs are indented to show that they
737 belong to the previous footnote.
739 { some.code }
741 The whole paragraph can be indented, or just the first
742 line. In this way, multi-paragraph footnotes work like
743 multi-paragraph list items.
745 This paragraph won't be part of the note, because it isn't indented.
747The identifiers in footnote references may not contain spaces, tabs,
748or newlines. These identifiers are used only to correlate the
749footnote reference with the note itself; in the output, footnotes
750will be numbered sequentially.
752The footnotes themselves need not be placed at the end of the
753document. They may appear anywhere except inside other block elements
754(lists, block quotes, tables, etc.).
756Inline footnotes are also allowed (though, unlike regular notes,
757they cannot contain multiple paragraphs). The syntax is as follows:
759 Here is an inline note.^[Inlines notes are easier to write, since
760 you don't have to pick an identifier and move down to type the
761 note.]
763Inline and regular footnotes may be mixed freely.
765Tables
766------
768Two kinds of tables may be used. Both kinds presuppose the use of
769a fixed-width font, such as Courier.
771Simple tables look like this:
773 Right Left Center Default
774 ------- ------ ---------- -------
775 12 12 12 12
776 123 123 123 123
777 1 1 1 1
779 Table: Demonstration of simple table syntax.
781The headers and table rows must each fit on one line. Column
782alignments are determined by the position of the header text relative
783to the dashed line below it:[^4]
785 - If the dashed line is flush with the header text on the right side
786 but extends beyond it on the left, the column is right-aligned.
787 - If the dashed line is flush with the header text on the left side
788 but extends beyond it on the right, the column is left-aligned.
789 - If the dashed line extends beyond the header text on both sides,
790 the column is centered.
791 - If the dashed line is flush with the header text on both sides,
792 the default alignment is used (in most cases, this will be left).
794[^4]: This scheme is due to Michel Fortin, who proposed it on the
795 [Markdown discussion list](http://six.pairlist.net/pipermail/markdown-discuss/2005-March/001097.html).
797The table must end with a blank line, or a line of dashes followed by
798a blank line. A caption may optionally be provided (as illustrated in
799the example above). A caption is a paragraph beginning with the string
800`Table:`, which will be stripped off.
802The column headers may be omitted, provided a dashed line is used
803to end the table. For example:
805 ------- ------ ---------- -------
806 12 12 12 12
807 123 123 123 123
808 1 1 1 1
809 ------- ------ ---------- -------
811When headers are omitted, column alignments are determined on the basis
812of the first line of the table body. So, in the tables above, the columns
813would be right, left, center, and right aligned, respectively.
815Multiline tables allow headers and table rows to span multiple lines
816of text. Here is an example:
818 -------------------------------------------------------------
819 Centered Default Right Left
820 Header Aligned Aligned Aligned
821 ----------- ------- --------------- -------------------------
822 First row 12.0 Example of a row that
823 spans multiple lines.
825 Second row 5.0 Here's another one. Note
826 the blank line between
827 rows.
828 -------------------------------------------------------------
830 Table: Here's the caption. It, too, may span
831 multiple lines.
833These work like simple tables, but with the following differences:
835 - They must begin with a row of dashes, before the header text
836 (unless the headers are omitted).
837 - They must end with a row of dashes, then a blank line.
838 - The rows must be separated by blank lines.
840In multiline tables, the table parser pays attention to the widths of
841the columns, and the writers try to reproduce these relative widths in
842the output. So, if you find that one of the columns is too narrow in the
843output, try widening it in the markdown source.
845Headers may be omitted in multiline tables as well as simple tables:
847 ----------- ------- --------------- -------------------------
848 First row 12.0 Example of a row that
849 spans multiple lines.
851 Second row 5.0 Here's another one. Note
852 the blank line between
853 rows.
854 -------------------------------------------------------------
856 Table: Here's a multiline table without headers.
858It is possible for a multiline table to have just one row, but the row
859should be followed by a blank line (and then the row of dashes that ends
860the table), or the table may be interpreted as a simple table.
862Delimited Code blocks
863---------------------
865In addition to standard indented code blocks, Pandoc supports
866*delimited* code blocks. These begin with a row of three or more
867tildes (`~`) and end with a row of tildes that must be at least
868as long as the starting row. Everything between the tilde-lines
869is treated as code. No indentation is necessary:
871 ~~~~~~~
872 {code here}
873 ~~~~~~~
875Like regular code blocks, delimited code blocks must be separated
876from surrounding text by blank lines.
878If the code itself contains a row of tildes, just use a longer
879row of tildes at the start and end:
881 ~~~~~~~~~~~~~~~~
882 ~~~~~~~~~~
883 code including tildes
884 ~~~~~~~~~~
885 ~~~~~~~~~~~~~~~~
887Optionally, you may specify the language of the code block using
888this syntax:
890 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.haskell .numberLines}
891 qsort [] = []
892 qsort (x:xs) = qsort (filter (< x) xs) ++ [x] ++
893 qsort (filter (>= x) xs)
894 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
896Some output formats can use this information to do syntax highlighting.
897Currently, the only output format that uses this information is HTML.
899If pandoc has been compiled with syntax highlighting support, then the
900code block above will appear highlighted, with numbered lines. (To see
901which languages are supported, do `pandoc --version`.)
903If pandoc has not been compiled with syntax highlighting support, the
904code block above will appear as follows:
906 <pre class="haskell">
907 <code>
908 ...
909 </code>
910 </pre>
912Title blocks
913------------
915If the file begins with a title block
917 % title
918 % author(s) (separated by commas)
919 % date
921it will be parsed as bibliographic information, not regular text. (It
922will be used, for example, in the title of standalone LaTeX or HTML
923output.) The block may contain just a title, a title and an author,
924or all three lines. Each must begin with a % and fit on one line.
925The title may contain standard inline formatting. If you want to
926include an author but no title, or a title and a date but no author,
927you need a blank line:
929 % My title
930 %
931 % June 15, 2006
933Titles will be written only when the `--standalone` (`-s`) option is
934chosen. In HTML output, titles will appear twice: once in the
935document head -- this is the title that will appear at the top of the
936window in a browser -- and once at the beginning of the document body.
937The title in the document head can have an optional prefix attached
938(`--title-prefix` or `-T` option). The title in the body appears as
939an H1 element with class "title", so it can be suppressed or
940reformatted with CSS. If a title prefix is specified with `-T` and no
941title block appears in the document, the title prefix will be used by
942itself as the HTML title.
944The man page writer extracts a title, man page section number, and
945other header and footer information from the title line. The title
946is assumed to be the first word on the title line, which may optionally
947end with a (single-digit) section number in parentheses. (There should
948be no space between the title and the parentheses.) Anything after
949this is assumed to be additional footer and header text. A single pipe
950character (`|`) should be used to separate the footer text from the header
951text. Thus,
953 % PANDOC(1)
955will yield a man page with the title `PANDOC` and section 1.
957 % PANDOC(1) Pandoc User Manuals
959will also have "Pandoc User Manuals" in the footer.
961 % PANDOC(1) Pandoc User Manuals | Version 4.0
963will also have "Version 4.0" in the header.
965Markdown in HTML blocks
966-----------------------
968While standard markdown leaves HTML blocks exactly as they are, Pandoc
969treats text between HTML tags as markdown. Thus, for example, Pandoc
970will turn
972 <table>
973 <tr>
974 <td>*one*</td>
975 <td>[a link](http://google.com)</td>
976 </tr>
977 </table>
979into
981 <table>
982 <tr>
983 <td><em>one</em></td>
984 <td><a href="http://google.com">a link</a></td>
985 </tr>
986 </table>
988whereas `Markdown.pl` will preserve it as is.
990There is one exception to this rule: text between `<script>` and
991`</script>` tags is not interpreted as markdown.
993This departure from standard markdown should make it easier to mix
994markdown with HTML block elements. For example, one can surround
995a block of markdown text with `<div>` tags without preventing it
996from being interpreted as markdown.
998Header identifiers in HTML
999--------------------------
1001Each header element in pandoc's HTML output is given a unique
1002identifier. This identifier is based on the text of the header. To
1003derive the identifier from the header text,
1005 - Remove all formatting, links, etc.
1006 - Remove all punctuation, except underscores, hyphens, periods,
1007 and tildes.
1008 - Replace all spaces and newlines with hyphens.
1009 - Convert all alphabetic characters to lowercase.
1010 - Remove everything up to the first letter (identifiers may
1011 not begin with a number or punctuation mark).
1012 - If nothing is left after this, use the identifier `section`.
1014Thus, for example,
1016 Header Identifier
1017 ------------------------------------- ---------------------------
1018 Header identifiers in HTML `header-identifiers-in-html`
1019 *Dogs*?--in *my* house? `dogs--in-my-house`
1020 [HTML], [S5], or [RTF]? `html-s5-or-rtf`
1021 3. Applications `applications`
1022 33 `section`
1024These rules should, in most cases, allow one to determine the identifier
1025from the header text. The exception is when several headers have the
1026same text; in this case, the first will get an identifier as described
1027above; the second will get the same identifier with `-1` appended; the
1028third with `-2`; and so on.
1030These identifiers are used to provide link targets in the table of
1031contents generated by the `--toc|--table-of-contents` option. They
1032also make it easy to provide links from one section of a document to
1033another. A link to this section, for example, might look like this:
1035 See the section on [header identifiers](#header-identifiers-in-html).
1037Note, however, that this method of providing links to sections works
1038only in HTML.
1040Blank lines before headers and blockquotes
1041------------------------------------------
1043Standard markdown syntax does not require a blank line before a header
1044or blockquote. Pandoc does require this (except, of course, at the
1045beginning of the document). The reason for the requirement is that
1046it is all too easy for a `>` or `#` to end up at the beginning of a
1047line by accident (perhaps through line wrapping). Consider, for
1048example:
1050 I like several of their flavors of ice cream: #22, for example, and
1051 #5.
1053Math
1054----
1056Anything between two $ characters will be treated as TeX math. The
1057opening $ must have a character immediately to its right, while the
1058closing $ must have a character immediately to its left. Thus,
1059`$20,000 and $30,000` won't parse as math. If for some reason
1060you need to enclose text in literal $ characters, backslash-escape
1061them and they won't be treated as math delimiters.
1063TeX math will be printed in all output formats. In Markdown,
1064reStructuredText, LaTeX, and ConTeXt output, it will appear verbatim
1065between $ characters.
1067In reStructuredText output, it will be rendered using an interpreted
1068text role `:math:`, as described
1069[here](http://www.american.edu/econ/itex2mml/mathhack.rst).
1071In Texinfo output, it will be rendered inside a `@math` command.
1073In groff man output, it will be rendered verbatim without $'s.
1075In MediaWiki output, it will be rendered inside `<math>` tags.
1077In RTF, Docbook, and OpenDocument output, it will be rendered, as far as
1078possible, using unicode characters, and will otherwise appear verbatim.
1079Unknown commands and symbols, and commands that cannot be dealt with
1080this way (like `\frac`), will be rendered verbatim. So the results may
1081be a mix of raw TeX code and properly rendered unicode math.
1083In HTML and S5 output, the way math is rendered will depend on the
1084command-line options selected:
10861. The default is to render TeX math as far as possible using unicode
1087 characters, as with RTF, Docbook, and OpenDocument output. Formulas
1088 are put inside a `span` with `class="math"`, so that they may be
1089 styled differently from the surrounding text if needed.
10912. If the `--latexmathml` option is used, TeX math will be displayed
1092 between $ or $$ characters and put in `<span>` tags with class `LaTeX`.
1093 The [LaTeXMathML] script will be used to render it as formulas.
1094 (This trick does not work in all browsers, but it works in Firefox.
1095 In browsers that do not support LaTeXMathML, TeX math will appear
1096 verbatim between $ characters.)
10983. If the `--jsmath` option is used, TeX math will be put inside
1099 `<span>` tags (for inline math) or `<div>` tags (for display math)
1100 with class `math`. The [jsMath] script will be used to render
1101 it.
11034. If the `--mimetex` option is used, the [mimeTeX] CGI script will
1104 be called to generate images for each TeX formula. This should
1105 work in all browsers. The `--mimetex` option takes an optional URL
1106 as argument. If no URL is specified, it will be assumed that the
1107 mimeTeX CGI script is at `/cgi-bin/mimetex.cgi`.
11095. If the `--gladtex` option is used, TeX formulas will be enclosed
1110 in `<eq>` tags in the HTML output. The resulting `htex` file may then
1111 be processed by [gladTeX], which will produce image files for each
1112 formula and an `html` file with links to these images. So, the
1113 procedure is:
1115 pandoc -s --gladtex myfile.txt -o myfile.htex
1116 gladtex -d myfile-images myfile.htex # produces myfile.html
1117 # and images in myfile-images
1119Inline TeX
1120----------
1122Inline TeX commands will be preserved and passed unchanged to the
1123LaTeX and ConTeXt writers. Thus, for example, you can use LaTeX to
1124include BibTeX citations:
1126 This result was proved in \cite{jones.1967}.
1128Note that in LaTeX environments, like
1130 \begin{tabular}{|l|l|}\hline
1131 Age & Frequency \\ \hline
1132 18--25 & 15 \\
1133 26--35 & 33 \\
1134 36--45 & 22 \\ \hline
1135 \end{tabular}
1137the material between the begin and end tags will be interpreted as raw
1138LaTeX, not as markdown.
1140Inline LaTeX is ignored in output formats other than Markdown, LaTeX,
1141and ConTeXt.
1143Custom headers
1144==============
1146When run with the "standalone" option (`-s`), `pandoc` creates a
1147standalone file, complete with an appropriate header. To see the
1148default headers used for html and latex, use the following commands:
1150 pandoc -D html
1152 pandoc -D latex
1154If you want to use a different header, just create a file containing
1155it and specify it on the command line as follows:
1157 pandoc --custom-header=MyHeaderFile
1159Producing S5 with Pandoc
1160========================
1162Producing an [S5] web-based slide show with Pandoc is easy. A title
1163page is constructed automatically from the document's title block (see
1164above). Each section (with a level-one header) produces a single slide.
1165(Note that if the section is too big, the slide will not fit on the page;
1166S5 is not smart enough to produce multiple pages.)
1168Here's the markdown source for a simple slide show, `eating.txt`:
1170 % Eating Habits
1171 % John Doe
1172 % March 22, 2005
1174 # In the morning
1176 - Eat eggs
1177 - Drink coffee
1179 # In the evening
1181 - Eat spaghetti
1182 - Drink wine
1184To produce the slide show, simply type
1186 pandoc -w s5 -s eating.txt > eating.html
1188and open up `eating.html` in a browser.
1190Note that by default, the S5 writer produces lists that display
1191"all at once." If you want your lists to display incrementally
1192(one item at a time), use the `-i` option. If you want a
1193particular list to depart from the default (that is, to display
1194incrementally without the `-i` option and all at once with the
1195`-i` option), put it in a block quote:
1197 > - Eat spaghetti
1198 > - Drink wine
1200In this way incremental and nonincremental lists can be mixed in
1201a single document.
1203Note: the S5 file produced by pandoc with the `-s/--standalone` option
1204embeds the javascript and CSS required to show the slides. Thus it
1205does not depend on any additional files: you can send the HTML file to
1206others, and they will be able to view the slide show just by opening
1207it. However, if you intend to produce several S5 slide shows, and you
1208are displaying them on your own website, it is better to keep the S5
1209javascript and CSS files separate from the slide shows themselves, so
1210that they may be cached. The best approach in this case is to use pandoc
1211without the `-s` option to produce the body of the S5 document, which
1212can then be inserted into an HTML template that links to the javascript
1213and CSS files required by S5. (See the instructions on the S5 website.)
1214Alternatively, you may use `-s` together with the `-C/--custom-header`
1215option.
1217Literate Haskell support
1218========================
1220If you append `+lhs` to an appropriate input or output format (`markdown`,
1221`rst`, or `latex` for input or output; `html` for output only), pandoc
1222will treat the document as literate Haskell source. This means that
1224 - In markdown input, "bird track" sections will be parsed as Haskell
1225 code rather than block quotations. Text between `\begin{code}`
1226 and `\end{code}` will also be treated as Haskell code.
1228 - In markdown output, code blocks with class `haskell` will be
1229 rendered using bird tracks, and block quotations will be
1230 indented one space, so they will not be treated as Haskell code.
1231 In addition, headers will be rendered setext-style (with underlines)
1232 rather than atx-style (with '#' characters). (This is because ghc
1233 treats '#' characters in column 1 as introducing line numbers.)
1235 - In restructured text input, "bird track" sections will be parsed
1236 as Haskell code.
1238 - In restructured text output, code blocks with class `haskell` will
1239 be rendered using bird tracks.
1241 - In LaTeX input, text in `code` environments will be parsed as
1242 Haskell code.
1244 - In LaTeX output, code blocks with class `haskell` will be rendered
1245 inside `code` environments.
1247 - In HTML output, code blocks with class `haskell` will be rendered
1248 with class `literatehaskell` and bird tracks.
1250Examples:
1252 pandoc -f markdown+lhs -t html
1254reads literate Haskell source formatted with markdown conventions and writes
1255ordinary HTML (without bird tracks).
1257 pandoc -f markdown+lhs -t html+lhs
1259writes HTML with the Haskell code in bird tracks, so it can be copied
1260and pasted as literate Haskell source.