git.iko.soy/typeable/pandoc
on 71e508f help sign in
981 lines 37 kB history raw
1% Pandoc User's Guide
2% John MacFarlane
3% August 15, 2007
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], [groff man] pages, and [S5] HTML slide shows.
10Pandoc's version of markdown contains some enhancements, like footnotes
11and embedded LaTeX.
13In contrast to existing tools for converting markdown to HTML, which
14use regex substitutions, Pandoc has a modular design: it consists of a
15set of readers, which parse text in a given format and produce a native
16representation of the document, and a set of writers, which convert
17this native representation into a target format. Thus, adding an input
18or output format requires only adding a reader or writer.
20[markdown]: http://daringfireball.net/projects/markdown/
21[reStructuredText]: http://docutils.sourceforge.net/docs/ref/rst/introduction.html
22[S5]: http://meyerweb.com/eric/tools/s5/
23[HTML]: http://www.w3.org/TR/html40/
24[LaTeX]: http://www.latex-project.org/
25[ConTeXt]: http://www.pragma-ade.nl/
26[RTF]: http://en.wikipedia.org/wiki/Rich_Text_Format
27[DocBook XML]: http://www.docbook.org/
28[groff man]: http://developer.apple.com/DOCUMENTATION/Darwin/Reference/ManPages/man7/groff_man.7.html
29[Haskell]: http://www.haskell.org/
31© 2006-7 John MacFarlane (jgm at berkeley dot edu). Released under the
32[GPL], version 2 or greater. This software carries no warranty of
33any kind. (See COPYRIGHT for full copyright and warranty notices.)
34Recai Oktaş (roktas at debian dot org) deserves credit for the build
35system, the debian package, and the robust wrapper scripts.
37[GPL]: http://www.gnu.org/copyleft/gpl.html "GNU General Public License"
39Requirements
40============
42The `pandoc` program itself does not depend on any external libraries
43or programs.
45The wrapper script `html2markdown` requires
47 - `pandoc` (which must be in the PATH)
48 - a POSIX-compliant shell (installed by default on all linux and unix
49 systems, including Mac OS X, and in [Cygwin] for Windows),
50 - `HTML Tidy`
51 - `iconv` (for character encoding conversion). (If `iconv` is absent,
52 `html2markdown` will still work, but it will treat everything as UTF-8.)
54The wrapper script `markdown2pdf` requires
56 - `pandoc` (which must be in the PATH)
57 - a POSIX-compliant shell
58 - `pdflatex`, which should be part of any [LaTeX] distribution
59 - the following LaTeX packages (available from [CTAN], if they
60 are not already included in your LaTeX distribution):
61 + `unicode`
62 + `fancyhdr` (if you have verbatim text in footnotes)
63 + `graphicx` (if you use images)
64 + `array` (if you use tables)
65 + `ulem` (if you use strikeout text)
67The wrapper script `hsmarkdown` requires only a POSIX-compliant shell.
69[Cygwin]: http://www.cygwin.com/
70[HTML Tidy]: http://tidy.sourceforge.net/
71[`iconv`]: http://www.gnu.org/software/libiconv/
72[CTAN]: http://www.ctan.org "Comprehensive TeX Archive Network"
74Using Pandoc
75============
77If you run `pandoc` without arguments, it will accept input from
78STDIN. If you run it with file names as arguments, it will take input
79from those files. By default, `pandoc` writes its output to STDOUT.
80If you want to write to a file, use the `-o` option:
82 pandoc -o hello.html hello.txt
84Note that you can specify multiple input files on the command line.
85`pandoc` will concatenate them all (with blank lines between them)
86before parsing:
88 pandoc -s ch1.txt ch2.txt refs.txt > book.html
90(The `-s` option here tells `pandoc` to produce a standalone HTML file,
91with a proper header, rather than a fragment. For more details on this
92and many other command-line options, see below.)
94The format of the input and output can be specified explicitly using
95command-line options. The input format can be specified using the
96`-r/--read` or `-f/--from` options, the output format using the
97`-w/--write` or `-t/--to` options. Thus, to convert `hello.txt` from
98markdown to LaTeX, you could type:
100 pandoc -f markdown -t latex hello.txt
102To convert `hello.html` from html to markdown:
104 pandoc -f html -t markdown hello.html
106Supported output formats include `markdown`, `latex`, `context`
107(ConTeXt), `html`, `rtf` (rich text format), `rst` (reStructuredText),
108`docbook` (DocBook XML), `man` (groff man), and `s5` (which produces an
109HTML file that acts like powerpoint). Supported input formats include
110`markdown`, `html`, `latex`, and `rst`. Note that the `rst` reader only
111parses a subset of reStructuredText syntax. For example, it doesn't
112handle tables, option lists, or footnotes. But for simple documents it
113should be adequate. The `latex` and `html` readers are also limited in
114what they can do. Because the `html` reader is picky about the HTML it
115parses, it is recommended that you pipe HTML through [HTML Tidy] before
116sending it to `pandoc`, or use the `html2markdown` script described
117below.
119If you don't specify a reader or writer explicitly, `pandoc` will
120try to determine the input and output format from the extensions of
121the input and output filenames. Thus, for example,
123 pandoc -o hello.tex hello.txt
125will convert `hello.txt` from markdown to LaTeX. If no output file
126is specified (so that output goes to STDOUT), or if the output file's
127extension is unknown, the output format will default to HTML.
128If no input file is specified (so that input comes from STDIN), or
129if the input files' extensions are unknown, the input format will
130be assumed to be markdown unless explicitly specified.
132Character encodings
133-------------------
135All input is assumed to be in the UTF-8 encoding, and all output
136is in UTF-8. If your local character encoding is not UTF-8 and you use
137accented or foreign characters, you should pipe the input and output
138through [`iconv`]. For example,
140 iconv -t utf-8 source.txt | pandoc | iconv -f utf-8 > output.html
142will convert `source.txt` from the local encoding to UTF-8, then
143convert it to HTML, then convert back to the local encoding,
144putting the output in `output.html`.
146The shell scripts (described below) automatically convert the input
147from the local encoding to UTF-8 before running them through `pandoc`,
148then convert the output back to the local encoding.
150Shell scripts
151=============
153Three shell scripts, `markdown2pdf`, `html2markdown`, and `hsmarkdown`,
154are included in the standard Pandoc installation. (They are not included
155in the Windows binary package, as they require a POSIX shell, but they
156may be used in Windows under Cygwin.)
1581. `markdown2pdf` produces a PDF file from markdown-formatted
159 text, using `pandoc` and `pdflatex`. The default
160 behavior of `markdown2pdf` is to create a file with the same
161 base name as the first argument and the extension `pdf`; thus,
162 for example,
164 markdown2pdf sample.txt endnotes.txt
166 will produce `sample.pdf`. (If `sample.pdf` exists already,
167 it will be backed up before being overwritten.) An output file
168 name can be specified explicitly using the `-o` option:
170 markdown2pdf -o book.pdf chap1 chap2
172 If no input file is specified, input will be taken from STDIN.
173 All of `pandoc`'s options will work with `markdown2pdf` as well.
1752. `html2markdown` grabs a web page from a file or URL and converts
176 it to markdown-formatted text, using `tidy` and `pandoc`.
178 All of `pandoc`'s options will work with `html2markdown` as well.
179 In addition, the following special options may be used.
180 The special options must be separated from the `html2markdown`
181 command and any regular Pandoc options by the delimiter `--`:
183 html2markdown -o out.txt -- -e latin1 -g curl google.com
185 The `-e` or `--encoding` option specifies the character encoding
186 of the HTML input. If this option is not specified, and input
187 is not from STDIN, `html2markdown` will attempt to determine the
188 page's character encoding from the "Content-type" meta tag.
189 If this is not present, UTF-8 is assumed.
191 The `-g` or `--grabber` option specifies the command to be used to
192 fetch the contents of a URL:
194 html2markdown -g 'curl --user foo:bar' www.mysite.com
196 If this option is not specified, `html2markdown` searches for an
197 available program (`wget`, `curl`, or a text-mode browser) to fetch
198 the contents of a URL.
2003. `hsmarkdown` is designed to be used as a drop-in replacement for
201 `Markdown.pl`. It forces `pandoc` to convert from markdown to
202 HTML, and to use the `--strict` flag for maximal compliance with
203 official markdown syntax. (All of Pandoc's syntax extensions and
204 variants, described below, are disabled.) No other command-line
205 options are allowed. (In fact, options will be interpreted as
206 filenames.)
208 As an alternative to using the `hsmarkdown` shell script, the
209 user may create a symbolic link to `pandoc` called `hsmarkdown`.
210 When invoked under the name `hsmarkdown`, `pandoc` will behave
211 as if the `--strict` flag had been selected, and no command-line
212 options will be recognized. However, this approach does not work
213 under Cygwin, due to problems with its simulation of symbolic
214 links.
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`.
227`-t`, `--to`, `-w`, or `--write` *format*
228: specifies the output format -- the format Pandoc will
229 be converting *to*. *format* can be `native`, `html`, `s5`,
230 `docbook`, `latex`, `context`, `markdown`, `man`, `rst`, and `rtf`.
232`-s` or `--standalone`
233: indicates that a standalone document is to be produced (with
234 appropriate headers and footers), rather than a fragment.
236`-o` or `--output` *filename*
237: sends output to *filename*. If this option is not specified,
238 or if its argument is `-`, output will be sent to STDOUT.
240`-p` or `--preserve-tabs`
241: causes tabs in the source text to be preserved, rather than converted
242 to spaces (the default).
244`--tabstop` *tabstop*
245: sets the number of spaces per tab to *tabstop* (defaults to 4).
247`--strict`
248: specifies that strict markdown syntax is to be used, without
249 pandoc's usual extensions and variants (described below). When the
250 input format is HTML, this means that constructs that have no
251 equivalents in standard markdown (e.g. definition lists or strikeout
252 text) will be parsed as raw HTML.
254`--reference-links`
255: causes reference-style links to be used in markdown
256 and reStructuredText output. By default inline links are used.
258`-R` or `--parse-raw`
259: causes the HTML and LaTeX readers to parse HTML codes and LaTeX
260 environments that it can't translate as raw HTML or LaTeX. Raw HTML can
261 be printed in markdown, reStructuredText, HTML, and S5 output; raw LaTeX
262 can be printed in markdown, reStructuredText, LaTeX, and ConTeXt output.
263 The default is for the readers to omit untranslatable HTML codes and
264 LaTeX environments. (The LaTeX reader does pass through untranslatable
265 LaTeX *commands*, even if `-R` is not specified.)
267`-C` or `--custom-header` *filename*
268: can be used to specify a custom document header. To see the headers
269 used by default, use the `-D` option: for example, `pandoc -D html`
270 prints the default HTML header.
272`--toc` or `--table-of-contents`
273: includes an automatically generated table of contents (or, in the
274 case of `latex`, `context`, and `rst`, an instruction to create
275 one) in the output document. This option has no effect with `man`,
276 `docbook`, or `s5` output formats.
278`-c` or `--css` *filename*
279: allows the user to specify a custom stylesheet that will be linked to
280 in HTML and S5 output.
282`-H` or `--include-in-header` *filename*
283: includes the contents of *filename* (verbatim) at the end of the
284 document header. This can be used, for example, to include special
285 CSS or javascript in HTML documents.
287`-B` or `--include-before-body` *filename*
288: includes the contents of *filename* (verbatim) at the beginning of
289 the document body (e.g. after the `<body>` tag in HTML, or the
290 `\begin{document}` command in LaTeX). This can be used to include
291 navigation bars or banners in HTML documents.
293`-A` or `--include-after-body` *filename*
294: includes the contents of *filename* (verbatim) at the end of
295 the document body (before the `</body>` tag in HTML, or the
296 `\end{document}` command in LaTeX).
298`-T` or `--title-prefix` *string*
299: includes *string* as a prefix at the beginning of the title that
300 appears in the HTML header (but not in the title as it appears at
301 the beginning of the HTML body). (See below on
302 [Title Blocks](#title-blocks).)
304`-S` or `--smart`
305: causes `pandoc` to produce typographically correct output, along the
306 lines of John Gruber's [Smartypants]. Straight quotes are converted
307 to curly quotes, `---` to dashes, and `...` to ellipses. (Note: This
308 option is only significant when the input format is `markdown`.
309 It is selected automatically when the output format is `latex` or
310 `context`.)
312`-m`*[url]* or `--asciimathml`*[=url]*
313: causes `pandoc` to use Peter Jipsen's [ASCIIMathML] script to display
314 TeX math in HTML or S5. If a local copy of `ASCIIMathML.js` is
315 available on the webserver where the page will be viewed, provide a
316 *url* and a link will be inserted in the generated HTML or S5. If
317 no *url* is provided, the contents of the script will be inserted
318 directly; this provides portability at the price of efficiency. If
319 you plan to use math on several pages, it is much better to link to
320 a copy of `ASCIIMathML.js`, which can be cached. (See `--gladtex`
321 and `--mimetex` for alternative ways of dealing with math in HTML.)
323`--gladtex`*[=url]*
324: causes TeX formulas to be enclosed in `<eq>` tags in HTML or S5 output.
325 This output can then be processed by [gladTeX] to produce links to
326 images with the typeset formulas. (See `--asciimathml` and
327 `--mimetex` for alternative ways of dealing with math in HTML.)
329`--mimetex`*[=url]*
330: causes TeX formulas to be replaced by `<img>` tags linking to the
331 [mimeTeX] CGI script, which will produce images with the typeset
332 formulas. (See `--asciimathml` and `--mimetex` for alternative
333 ways of dealing with math in HTML.)
335`-i` or `--incremental`
336: causes all lists in S5 output to be displayed incrementally by
337 default (one item at a time). The normal default is for lists to be
338 displayed all at once.
340`-N` or `--number-sections`
341: causes sections to be numbered in LaTeX or ConTeXt output. By default,
342 sections are not numbered.
344`--no-wrap`
345: disables text-wrapping in output. By default, text is wrapped
346 appropriately for the output format.
348`--sanitize-html`
349: sanitizes HTML (in markdown or HTML input) using a whitelist.
350 Unsafe tags are replaced by HTML comments; unsafe attributes
351 are omitted.
353`--dump-args`
354: is intended to make it easier to create wrapper scripts that use
355 Pandoc. It causes Pandoc to dump information about the arguments
356 with which it was called to STDOUT, then exit. The first line
357 printed is the name of the output file specified using the `-o`
358 or `--output` option, or `-` if output would go to STDOUT. The
359 remaining lines, if any, list command-line arguments. These will
360 include the names of input files and any special options passed
361 after ` -- ` on the command line. So, for example,
363: pandoc --dump-args -o foo.html -s foo.txt \
364 appendix.txt -- -e latin1
366: will cause the following to be printed to STDOUT:
368: foo.html foo.txt appendix.txt -e latin1
370`--ignore-args`
371: causes Pandoc to ignore all command-line arguments.
372 Regular Pandoc options are not ignored. Thus, for example,
374: pandoc --ignore-args -o foo.html -s foo.txt -- -e latin1
376: is equivalent to
378: pandoc -o foo.html -s
380`-v` or `--version`
381: prints the version number to STDERR.
383`-h` or `--help`
384: prints a usage message to STDERR.
386[Smartypants]: http://daringfireball.net/projects/smartypants/
387[ASCIIMathML]: http://www1.chapman.edu/~jipsen/mathml/asciimath.html
388[gladTeX]: http://www.math.uio.no/~martingu/gladtex/index.html
389[mimeTeX]: http://www.forkosh.com/mimetex.html
391Pandoc's markdown vs. standard markdown
392=======================================
394In parsing markdown, Pandoc departs from and extends [standard markdown]
395in a few respects. (To run Pandoc on the official markdown test suite,
396type `make test-markdown`.) Except where noted, these differences can
397be suppressed by specifying the `--strict` command-line option or by
398using the `hsmarkdown` wrapper.
400[standard markdown]: http://daringfireball.net/projects/markdown/syntax
401 "Markdown syntax description"
403Backslash escapes
404-----------------
406Except inside a code block or inline code, any punctuation or space
407character preceded by a backslash will be treated literally, even if it
408would normally indicate formatting. Thus, for example, if one writes
410 *\*hello\**
412one will get
414 <em>*hello*</em>
416instead of
418 <strong>hello</strong>
420This rule is easier to remember than standard markdown's rule,
421which allows only the following characters to be backslash-escaped:
423 \`*_{}[]()>#+-.!
425Subscripts and superscripts
426---------------------------
428Superscripts may be written by surrounding the superscripted text by `^`
429characters; subscripts may be written by surrounding the subscripted
430text by `~` characters. Thus, for example,
432 H~2~O is a liquid. 2^10^ is 1024.
434If the superscripted or subscripted text contains spaces, these spaces
435must be escaped with backslashes. (This is to prevent accidental
436superscripting and subscripting through the ordinary use of `~` and `^`.)
437Thus, if you want the letter P with 'a cat' in subscripts, use
438`P~a\ cat~`, not `P~a cat~`.
440Strikeout
441---------
443To strikeout a section of text with a horizontal line, begin and end it
444with `~~`. Thus, for example,
446 This ~~is deleted text.~~
448Lists
449-----
451Pandoc behaves differently from standard markdown on some "edge
452cases" involving lists. Consider this source:
454 1. First
455 2. Second:
456 - Fee
457 - Fie
458 - Foe
460 3. Third
462Pandoc transforms this into a "compact list" (with no `<p>` tags around
463"First", "Second", or "Third"), while markdown puts `<p>` tags around
464"Second" and "Third" (but not "First"), because of the blank space
465around "Third". Pandoc follows a simple rule: if the text is followed by
466a blank line, it is treated as a paragraph. Since "Second" is followed
467by a list, and not a blank line, it isn't treated as a paragraph. The
468fact that the list is followed by a blank line is irrelevant. (Note:
469Pandoc works this way even when the `--strict` option is specified. This
470behavior is consistent with the official markdown syntax description,
471even though it is different from that of `Markdown.pl`.)
473Unlike standard markdown, Pandoc allows ordered list items to be marked
474with uppercase and lowercase letters and roman numerals, in addition to
475arabic numerals. (This behavior can be turned off using the `--strict`
476option.) List markers may be enclosed in parentheses or followed by a
477single right-parentheses or period. They must be separated from the
478text that follows by at least one space, and, if the list marker is a
479capital letter with a period, by at least two spaces.[^2]
481[^2]: The point of this rule is to ensure that normal paragraphs
482 starting with people's initials, like
484 B. Russell was an English philosopher.
486 do not get treated as list items.
488 This rule will not prevent
490 (C) 2007 Joe Smith
492 from being interpreted as a list item. In this case, a backslash
493 escape can be used:
495 (C\) 2007 Joe Smith
497Pandoc also pays attention to the type of list marker used, and to the
498starting number, and both of these are preserved where possible in the
499output format. Thus, the following yields a list with numbers followed
500by a single parenthesis, starting with 9, and a sublist with lowercase
501roman numerals:
503 9) Ninth
504 10) Tenth
505 11) Eleventh
506 i. subone
507 ii. subtwo
508 iii. subthree
510Note that Pandoc pays attention only to the *starting* number in a list.
511So, the following yields a list numbered sequentially starting from 2:
513 (2) Two
514 (5) Three
515 (2) Four
517If default list markers are desired, use '`#.`':
519 #. one
520 #. two
521 #. three
523If you change list style in mid-list, Pandoc will notice and assume you
524are starting a sublist. So,
526 1. One
527 2. Two
528 A. Sub
529 B. Sub
530 3. Three
532gets treated as if it were
534 1. One
535 2. Two
536 A. Sub
537 B. Sub
538 3. Three
541Definition lists
542----------------
544Pandoc supports definition lists, using a syntax inspired by
545[PHP Markdown Extra] and [reStructuredText]:
547 [PHP Markdown Extra]: http://www.michelf.com/projects/php-markdown/extra/
549 Term 1
550 : Definition 1
552 Term 2
553 : Definition 2
555 : Second paragraph of definition 2.
557Each term must fit on one line. The definition must begin on the line
558after the term. The definition consists of one or more block elements
559(paragraph, code block, list, etc.), each beginning with a colon and
560(aside from the colon) indented one tab stop.
562 Term *with inline markup*
563 : Here is the definition. It may contain multiple blocks.
564 Here is some code:
566 : {* my code *}
568 : Here is the third paragraph of this definition.
570If you leave space after the definition (as in the first example above),
571the definitions will be considered paragraphs. In some output formats,
572this will mean greater spacing between term/definition pairs. For a
573compact definition list, do not leave space between the definition and
574the next term:
576 Term 1
577 : Definition 1
578 Term 2
579 : Definition 2
581Reference links
582---------------
584Pandoc allows implicit reference links with just a single set of
585brackets. So, the following links are equivalent:
587 1. Here's my [link]
588 2. Here's my [link][]
590 [link]: linky.com
592(Note: Pandoc works this way even if `--strict` is specified, because
593`Markdown.pl` 1.0.2b7 allows single-bracket links.)
595Footnotes
596---------
598Pandoc's markdown allows footnotes, using the following syntax:
600 Here is a footnote reference,[^1] and another.[^longnote]
602 [^1]: Here is the footnote.
604 [^longnote]: Here's one with multiple blocks.
606 Subsequent paragraphs are indented to show that they
607 belong to the previous footnote.
609 { some.code }
611 The whole paragraph can be indented, or just the first
612 line. In this way, multi-paragraph footnotes work like
613 multi-paragraph list items.
615 This paragraph won't be part of the note, because it isn't indented.
617The identifiers in footnote references may not contain spaces, tabs,
618or newlines. These identifiers are used only to correlate the
619footnote reference with the note itself; in the output, footnotes
620will be numbered sequentially.
622The footnotes themselves need not be placed at the end of the
623document. They may appear anywhere except inside other block elements
624(lists, block quotes, tables, etc.).
626Inline footnotes are also allowed (though, unlike regular notes,
627they cannot contain multiple paragraphs). The syntax is as follows:
629 Here is an inline note.^[Inlines notes are easier to write, since
630 you don't have to pick an identifier and move down to type the
631 note.]
633Inline and regular footnotes may be mixed freely.
635Tables
636------
638Two kinds of tables may be used. Both kinds presuppose the use of
639a fixed-width font, such as Courier.
641Simple tables look like this:
643 Right Left Center Default
644 ------- ------ ---------- -------
645 12 12 12 12
646 123 123 123 123
647 1 1 1 1
649 Table: Demonstration of simple table syntax.
651The headers and table rows must each fit on one line. Column
652alignments are determined by the position of the header text relative
653to the dashed line below it:[^1]
655 - If the dashed line is flush with the header text on the right side
656 but extends beyond it on the left, the column is right-aligned.
657 - If the dashed line is flush with the header text on the left side
658 but extends beyond it on the right, the column is left-aligned.
659 - If the dashed line extends beyond the header text on both sides,
660 the column is centered.
661 - If the dashed line is flush with the header text on both sides,
662 the default alignment is used (in most cases, this will be left).
664[^1]: This scheme is due to Michel Fortin, who proposed it on the
665 Markdown discussion list:
666 <http://six.pairlist.net/pipermail/markdown-discuss/2005-March/001097.html>.
668The table must end with a blank line. Optionally, a caption may be
669provided (as illustrated in the example above). A caption is a paragraph
670beginning with the string `Table:`, which will be stripped off.
672The table parser pays attention to the widths of the columns, and
673the writers try to reproduce these relative widths in the output.
674So, if you find that one of the columns is too narrow in the output,
675try widening it in the markdown source.
677Multiline tables allow headers and table rows to span multiple lines
678of text. Here is an example:
680 -------------------------------------------------------------
681 Centered Default Right Left
682 Header Aligned Aligned Aligned
683 ----------- ------- --------------- -------------------------
684 First row 12.0 Example of a row that
685 spans multiple lines.
687 Second row 5.0 Here's another one. Note
688 the blank line between
689 rows.
690 -------------------------------------------------------------
692 Table: Here's the caption. It, too, may span
693 multiple lines.
695These work like simple tables, but with the following differences:
697 - They must begin with a row of dashes, before the header text.
698 - They must end with a row of dashes, then a blank line.
699 - The rows must be separated by blank lines.
701Title blocks
702------------
704If the file begins with a title block
706 % title
707 % author(s) (separated by commas)
708 % date
710it will be parsed as bibliographic information, not regular text. (It
711will be used, for example, in the title of standalone LaTeX or HTML
712output.) The block may contain just a title, a title and an author,
713or all three lines. Each must begin with a % and fit on one line.
714The title may contain standard inline formatting. If you want to
715include an author but no title, or a title and a date but no author,
716you need a blank line:
718 % My title
719 %
720 % June 15, 2006
722Titles will be written only when the `--standalone` (`-s`) option is
723chosen. In HTML output, titles will appear twice: once in the
724document head -- this is the title that will appear at the top of the
725window in a browser -- and once at the beginning of the document body.
726The title in the document head can have an optional prefix attached
727(`--title-prefix` or `-T` option). The title in the body appears as
728an H1 element with class "title", so it can be suppressed or
729reformatted with CSS. If a title prefix is specified with `-T` and no
730title block appears in the document, the title prefix will be used by
731itself as the HTML title.
733The man page writer extracts a title, man page section number, and
734other header and footer information from the title line. The title
735is assumed to be the first word on the title line, which may optionally
736end with a (single-digit) section number in parentheses. (There should
737be no space between the title and the parentheses.) Anything after
738this is assumed to be additional footer and header text. A single pipe
739character (`|`) should be used to separate the footer text from the header
740text. Thus,
742 % PANDOC(1)
744will yield a man page with the title `PANDOC` and section 1.
746 % PANDOC(1) Pandoc User Manuals
748will also have "Pandoc User Manuals" in the footer.
750 % PANDOC(1) Pandoc User Manuals | Version 4.0
752will also have "Version 4.0" in the header.
754Markdown in HTML blocks
755-----------------------
757While standard markdown leaves HTML blocks exactly as they are, Pandoc
758treats text between HTML tags as markdown. Thus, for example, Pandoc
759will turn
761 <table>
762 <tr>
763 <td>*one*</td>
764 <td>[a link](http://google.com)</td>
765 </tr>
766 </table>
768into
770 <table>
771 <tr>
772 <td><em>one</em></td>
773 <td><a href="http://google.com">a link</a></td>
774 </tr>
775 </table>
777whereas `Markdown.pl` will preserve it as is.
779There is one exception to this rule: text between `<script>` and
780`</script>` tags is not interpreted as markdown.
782This departure from standard markdown should make it easier to mix
783markdown with HTML block elements. For example, one can surround
784a block of markdown text with `<div>` tags without preventing it
785from being interpreted as markdown.
787Header identifiers in HTML
788--------------------------
790Each header element in pandoc's HTML output is given a unique
791identifier. This identifier is based on the text of the header. To
792derive the identifier from the header text,
794 - Remove all formatting, links, etc.
795 - Remove all punctuation, except dashes and hyphens.
796 - Replace all spaces, dashes, newlines, and hyphens with hyphens.
797 - Convert all alphabetic characters to lowercase.
798 - Remove everything up to the first letter (identifiers may
799 not begin with a number or punctuation mark).
800 - If nothing is left after this, use the identifier `section`.
802Thus, for example,
804 Header Identifier
805 ------------------------------------- ---------------------------
806 Header identifiers in HTML `header-identifiers-in-html`
807 *Dogs*?--in *my* house? `dogs--in-my-house`
808 [HTML], [S5], or [RTF]? `html-s5-or-rtf`
809 3. Applications `applications`
810 33 `section`
812These rules should, in most cases, allow one to determine the identifier
813from the header text. The exception is when several headers have the
814same text; in this case, the first will get an identifier as described
815above; the second will get the same identifier with `-1` appended; the
816third with `-2`; and so on.
818These identifiers are used to provide link targets in the table of
819contents generated by the `--toc|--table-of-contents` option. They
820also make it easy to provide links from one section of a document to
821another. A link to this section, for example, might look like this:
823 See the section on [header identifiers](#header-identifiers-in-html).
825Note, however, that this method of providing links to sections works
826only in HTML.
828Blank lines before headers and blockquotes
829------------------------------------------
831Standard markdown syntax does not require a blank line before a header
832or blockquote. Pandoc does require this (except, of course, at the
833beginning of the document). The reason for the requirement is that
834it is all too easy for a `>` or `#` to end up at the beginning of a
835line by accident (perhaps through line wrapping). Consider, for
836example:
838 I like several of their flavors of ice cream: #22, for example, and
839 #5.
841Math
842----
844Anything between two $ characters will be treated as TeX math. The
845opening $ must have a character immediately to its right, while the
846closing $ must have a character immediately to its left. Thus,
847`$20,000 and $30,000` won't parse as math. If for some reason
848you need to enclose text in literal $ characters, backslash-escape
849them and they won't be treated as math delimiters.
851TeX math will be printed in all output formats. In Markdown,
852reStructuredText, LaTeX, and ConTeXt output, it will appear verbatim
853between $ characters.
855In reStructuredText output, it will be rendered using an interpreted
856text role `:math:`, as described
857[here](http://www.american.edu/econ/itex2mml/mathhack.rst).
859In groff man output, it will be rendered verbatim without $'s.
861In RTF and Docbook output, it will be rendered, as far as possible,
862using unicode characters, and will otherwise appear verbatim. Unknown
863commands and symbols, and commands that cannot be dealt with this way
864(like `\frac`), will be rendered verbatim. So the results may be a mix
865of raw TeX code and properly rendered unicode math.
867In HTML and S5 output, the way math is rendered will depend on the
868command-line options selected:
8701. The default is to render TeX math as far as possible using unicode
871 characters, as with RTF and Docbook output. Formulas are put inside
872 a `span` with `class="math"`, so that they may be styled differently
873 from the surrounding text if needed.
8752. If the `--asciimathml` option is used, TeX math will be displayed
876 between $ characters, as in LaTeX, and the [ASCIIMathML] script will
877 be used to render it as formulas. (This trick does not work in all
878 browsers, but it works in Firefox. In browsers that do not support
879 ASCIIMathML, TeX math will appear verbatim between $ characters.)
8813. If the `--mimetex` option is used, the [mimeTeX] CGI script will
882 be called to generate images for each TeX formula. This should
883 work in all browsers. The `--mimetex` option takes an optional URL
884 as argument. If no URL is specified, it will be assumed that the
885 mimeTeX CGI script is at `/cgi-bin/mimetex.cgi`.
8874. If the `--gladtex` option is used, TeX formulas will be enclosed
888 in `<eq>` tags in the HTML output. The resulting `htex` file may then
889 be processed by [gladTeX], which will produce image files for each
890 formula and an `html` file with links to these images. So, the
891 procedure is:
893 pandoc -s --gladtex myfile.txt -o myfile.htex
894 gladtex -d myfile-images myfile.htex # produces myfile.html
895 # and images in myfile-images
897Inline TeX
898----------
900Inline TeX commands will be preserved and passed unchanged to the
901LaTeX and ConTeXt writers. Thus, for example, you can use LaTeX to
902include BibTeX citations:
904 This result was proved in \cite{jones.1967}.
906Note that in LaTeX environments, like
908 \begin{tabular}{|l|l|}\hline
909 Age & Frequency \\ \hline
910 18--25 & 15 \\
911 26--35 & 33 \\
912 36--45 & 22 \\ \hline
913 \end{tabular}
915the material between the begin and end tags will be interpreted as raw
916LaTeX, not as markdown.
918Inline LaTeX is ignored in output formats other than Markdown, LaTeX,
919and ConTeXt.
921Custom headers
922==============
924When run with the "standalone" option (`-s`), `pandoc` creates a
925standalone file, complete with an appropriate header. To see the
926default headers used for html and latex, use the following commands:
928 pandoc -D html
930 pandoc -D latex
932If you want to use a different header, just create a file containing
933it and specify it on the command line as follows:
935 pandoc --header=MyHeaderFile
937Producing S5 with Pandoc
938========================
940Producing an [S5] web-based slide show with Pandoc is easy. A title
941page is constructed automatically from the document's title block (see
942above). Each section (with a level-one header) produces a single slide.
943(Note that if the section is too big, the slide will not fit on the page;
944S5 is not smart enough to produce multiple pages.)
946Here's the markdown source for a simple slide show, `eating.txt`:
948 % Eating Habits
949 % John Doe
950 % March 22, 2005
952 # In the morning
954 - Eat eggs
955 - Drink coffee
957 # In the evening
959 - Eat spaghetti
960 - Drink wine
962To produce the slide show, simply type
964 pandoc -w s5 -s eating.txt > eating.html
966and open up `eating.html` in a browser. The HTML file embeds
967all the required javascript and CSS, so no other files are necessary.
969Note that by default, the S5 writer produces lists that display
970"all at once." If you want your lists to display incrementally
971(one item at a time), use the `-i` option. If you want a
972particular list to depart from the default (that is, to display
973incrementally without the `-i` option and all at once with the
974`-i` option), put it in a block quote:
976 > - Eat spaghetti
977 > - Drink wine
979In this way incremental and nonincremental lists can be mixed in
980a single document.