@@ -20,7 +20,7 @@ or output format requires only adding a reader or writer.
2020[reStructuredText]: http://docutils.sourceforge.net/docs/ref/rst/introduction.html
2121[S5]: http://meyerweb.com/eric/tools/s5/
2222[HTML]: http://www.w3.org/TR/html40/
23−[LaTeX]: http://www.latex-project.org/
23+[LaTeX]: http://www.latex-project.org/
2424[RTF]: http://en.wikipedia.org/wiki/Rich_Text_Format
2525[Haskell]: http://www.haskell.org/
2626
@@ -30,9 +30,53 @@ any kind. (See COPYRIGHT for full copyright and warranty notices.)
3030Recai Oktaş (roktas at debian dot org) deserves credit for the build
3131system, the debian package, and the robust wrapper scripts.
3232
33−[GPL]: http://www.gnu.org/copyleft/gpl.html
33+[GPL]: http://www.gnu.org/copyleft/gpl.html "GNU General Public License"
3434
35−# Using Pandoc
35+Requirements
36+============
37+
38+The `pandoc` program itself does not depend on any external libraries
39+or programs. The convenience programs `markdown2html`, `markdown2latex`,
40+`markdown2rst`, `markdown2rtf`, `markdown2s5`, `html2markdown`,
41+`latex2markdown`, and `rst2markdown` are implemented as symbolic links to
42+`pandoc`.
43+
44+The wrapper script `web2markdown` requires
45+
46+ - `html2markdown` (included with Pandoc)
47+ - a POSIX-compliant shell (installed by default on all linux and unix
48+ systems, including Mac OS X, and in [Cygwin] for Windows),
49+ - `HTML Tidy`
50+ - `iconv` (for character encoding conversion). (If `iconv` is absent,
51+ `web2markdown` will still work, but it will treat everything as UTF-8.)
52+
53+[Cygwin]: http://www.cygwin.com/
54+[HTML Tidy]: http://tidy.sourceforge.net/
55+[`iconv`]: http://www.gnu.org/software/libiconv/
56+
57+The wrapper script `markdown2pdf` requires
58+
59+ - `markdown2latex` (included with Pandoc)
60+ - a POSIX-compliant shell
61+ - `pdflatex`, which should be part of any [LaTeX] distribution
62+ - the [unicode] and [fancyvrb] LaTeX packages, which are included
63+ in many LaTeX distributions. The [unicode] package allows LaTeX to
64+ process UTF-8 characters. [fancyvrb] allows code blocks and verbatim
65+ text to be used within footnotes. If your installation of LaTeX
66+ does not include these packages, you will get an error (complaining
67+ about missing `ucs.sty` or `fancyvrb.sty`) when you try to compile
68+ a LaTeX file produced by Pandoc, or when you use the `markdown2pdf`
69+ script (described below). If this happens, install the [unicode] and
70+ [fancyvrb] packages package from [CTAN]. (Get the zip file from CTAN
71+ and unpack it into `~/texmf/tex/latex/`. You may also need to run
72+ `mktexlsr` or `texhash` before the files can be found by TeX.)
73+
74+[CTAN]: http://www.ctan.org "Comprehensive TeX Archive Network"
75+[unicode]: http://www.ctan.org/tex-archive/macros/latex/contrib/unicode/
76+[fancyvrb]: http://www.ctan.org/tex-archive/macros/latex/contrib/fancyvrb/
77+
78+Using Pandoc
79+============
3680
3781If you run `pandoc` without arguments, it will accept input from
3882STDIN. If you run it with file names as arguments, it will take input
@@ -66,10 +110,14 @@ a subset of reStructuredText syntax. For example, it doesn't handle
66110tables, definition lists, option lists, or footnotes. It handles only the
67111constructs expressible in unextended markdown. But for simple documents
68112it should be adequate. The `latex` and `html` readers are also limited
69−in what they can do.
113+in what they can do. Because the `html` reader is picky about the HTML
114+it parses, it is recommended that you pipe HTML through [HTML Tidy] before
115+sending it to `pandoc`, or use the `web2markdown` script described below.
116+
117+By default, `pandoc` writes its output to STDOUT. If you want to
118+write to a file, use the `-o` option or shell redirection:
70119
71−`pandoc` writes its output to STDOUT. If you want to write to a file,
72−use redirection:
120+ pandoc -o hello.html hello.txt
73121
74122 pandoc hello.txt > hello.html
75123
@@ -77,13 +125,14 @@ Note that you can specify multiple input files on the command line.
77125`pandoc` will concatenate them all (with blank lines between them)
78126before parsing:
79127
80− pandoc -s chapter1.txt chapter2.txt chapter3.txt references.txt > book.html
128+ pandoc -s chapter1.txt chapter2.txt references.txt > book.html
81129
82130(The `-s` option here tells `pandoc` to produce a standalone HTML file,
83131with a proper header, rather than a fragment. For more details on this
84132and many other command-line options, see below.)
85133
86−# Character encodings
134+Character encodings
135+-------------------
87136
88137Unfortunately, due to limitations in GHC, `pandoc` does not automatically
89138detect the system's local character encoding. Hence, all input and
@@ -97,92 +146,65 @@ will convert `source.txt` from the local encoding to UTF-8, then
97146convert it to HTML, then convert back to the local encoding,
98147putting the output in `output.html`.
99148
100−[`iconv`]: http://www.gnu.org/software/libiconv/
101−
102149The shell scripts (described below) automatically convert the input
103150from the local encoding to UTF-8 before running them through `pandoc`,
104151then convert the output back to the local encoding.
105152
106−## LaTeX and UTF-8
107−
108−LaTeX sources produced by Pandoc use `ucs.sty`, which is included in many
109−LaTeX distributions. This allows LaTeX to process UTF-8 characters.
110−If your installation of LaTeX does not include `ucs.sty`, you will get an
111−error when you try to compile a LaTeX file produced by Pandoc, or when
112−you use the `markdown2pdf` script (described below). If this happens,
113−install the [unicode] package from [CTAN]. (Get the `unicode.zip`
114−file from CTAN, unpack it, and copy the whole `unicode` directory into
115−`~/texmf/tex/latex/`. You may also need to run `mktexlsr` or `texhash`
116−before the files can be found by TeX.)
153+Convenience programs and wrapper scripts
154+========================================
117155
118−[CTAN]: http://www.ctan.org
119−[unicode]: http://www.ctan.org/tex-archive/macros/latex/contrib/unicode/
156+For convenience, eight variant programs are included with Pandoc:
157+`markdown2html` (which is equivalent to `pandoc -w html`),
158+`markdown2latex` (equivalent to `pandoc -w latex`), `markdown2rst`
159+(equivalent to `pandoc -w rst`), `markdown2rtf` (equivalent to
160+`pandoc -w rtf`), `markdown2s5` (equivalent to `pandoc -w s5`),
161+`html2markdown` (equivalent to `pandoc -r html -w markdown`),
162+`latex2markdown` (equivalent to `pandoc -r latex -w markdown`), and
163+`rst2markdown` (equivalent to `pandoc -r rst -w markdown`). These
164+programs take an appropriately restricted subset of `pandoc`'s
165+options. (Run them with the `-h` flag for a full list of allowed
166+options.)
120167
121−# The shell scripts
168+Like `pandoc`, all of these programs produce fragments by default.
169+If you want to produce a standalone file, complete with a header
170+and footer appropriate to the format, use the `-s` option:
122171
123−Five shell scripts have been included that make it easy to run
124−`pandoc` without worrying about character encodings, and without
125−remembering all the command-line options:
172+ markdown2latex -s sample.txt > sample.tex
126173
127−- `markdown2html` converts markdown-formatted text to HTML
128−- `markdown2latex` converts markdown-formatted text to LaTeX
129−- `markdown2pdf` produces a PDF file from markdown-formatted
130− text, using `pdflatex`.
131−- `html2markdown` converts HTML to markdown-formatted text
132−- `latex2markdown` converts LaTeX to markdown-formatted text
174+Two shell scripts have also been included:
133175
134−All of the scripts use `iconv` (if available) to convert to and from
135−the local character encoding. All of the scripts presuppose that
136−`pandoc` is in the path, and some have additional requirements. (For
137−example, `html2markdown` uses `tidy`, and `markdown2pdf` uses
138−`pdflatex`.)
176+1. `markdown2pdf` produces a PDF file from markdown-formatted
177+ text, using `markdown2latex` and `pdflatex`. The default
178+ behavior of `markdown2pdf` is to create a file with the same
179+ base name as the first argument and the extension `pdf`; thus,
180+ for example,
139181
140−When no arguments are specified, text will be read from standard
141−input. Arguments specify input files (limited to one in the case of
142−`latex2markdown` and `html2markdown`; the other scripts accept any number
143−of arguments). `html2markdown` may take a URL as argument instead of
144−a filename; in this case, `curl`, `wget`, or an available text-based
145−browser will be used to fetch the contents of the URL. (The `-n` option
146−inhibits this behavior; the `-g` option allows the user to specify a
147−custom command that will be used to fetch from a URL.)
182+ markdown2pdf sample.txt endnotes.txt
148183
149−With the exception of `markdown2pdf`, the scripts write to standard output.
150−Output can be sent to a file using shell output redirection:
184+ will produce `sample.pdf`. (If `sample.pdf` exists already,
185+ it will be backed up before being overwritten.) An output file
186+ name can be specified explicitly using the `-o` option:
151187
152− latex2markdown sample.tex > sample.txt
188+ markdown2pdf -o "My Book.pdf" chap1.txt chap2.txt chap3.txt
153189
154−The default behavior of `markdown2pdf` is to create a file with the same
155−base name as the first argument and the extension `pdf`; thus, for example,
190+ If no input file is specified, input will be taken from STDIN.
156191
157− markdown2pdf sample.txt endnotes.txt
192+2. `web2markdown` grabs a web page from a file or URL and converts
193+ it to markdown-formatted text, using `tidy` and `html2markdown`.
194+ Unless input is from STDIN, an attempt is made to determine the
195+ character encoding of the page from the "Content-type" meta tag.
196+ If this is not present, UTF-8 is assumed. Alternatively, a character
197+ encoding may be specified explicitly using the `-e` option.
158198
159−will produce `sample.pdf`. (If `sample.pdf` exists already, it will be
160−backed up before being overwritten.) An output file name can be specified
161−explicitly using the `-o` option:
199+ `web2markdown` searches for an available program (`wget`, `curl`,
200+ or a text-mode browser) to fetch the contents of a URL.
201+ Optionally, the `-g` command may be used to specify the command
202+ to be used:
162203
163− markdown2pdf -o "My Book.pdf" chap1.txt chap2.txt chap3.txt
204+ web2markdown -g 'wget --user=foo --password=bar' mysite.com
164205
165−Options specific to the scripts, like `-o`, `-g`, and `-n`, must
166−be specified *before* any command-line arguments (file names or URLs).
167−Any options specified *after* the command-line arguments will be
168−passed directly to `pandoc`. For example,
169−
170− markdown2html tusks.txt -S -T Elephants
171−
172−will convert `tusks.txt` to `tusks.html` using smart quotes, ellipses,
173−and dashes, with "Elephants" as the page title prefix. (For a
174−complete list of `pandoc` options, see below.) When there are no
175−command-line arguments (because input is from STDIN), `pandoc`
176−options must be preceded by ` -- `:
177−
178− cat tusks.txt | markdown2html -- -S -T Elephants
179−
180−The ` -- ` separator may optionally be used when there are command-line
181−arguments:
182−
183− markdown2html -- tusks.txt -S -T Elephants
184−
185−# Command-line options
206+Command-line options
207+====================
186208
187209Various command-line options can be used to customize the output.
188210For a complete list, type
@@ -207,9 +229,11 @@ specified.)
207229complete with appropriate document headers. By default, `pandoc`
208230produces a fragment.
209231
210−`--custom-header` can be used to specify a custom document header. To
211−see the headers used by default, use the `-D` option: for example,
212−`pandoc -D html` prints the default HTML header.
232+`-o` or `--output-file` can be used to specify an output file.
233+
234+`-C` or `--custom-header` can be used to specify a custom document
235+header. To see the headers used by default, use the `-D` option:
236+for example, `pandoc -D html` prints the default HTML header.
213237
214238`-c` or `--css` allows the user to specify a custom stylesheet that
215239will be linked to in HTML and S5 output.
@@ -253,15 +277,38 @@ is for lists to be displayed all at once.
253277`-N` or `--number-sections` causes sections to be numbered in LaTeX
254278output. By default, sections are not numbered.
255279
256−# Pandoc's markdown vs. standard markdown
280+`-d` or `--debug` causes a debugging message to be written to STDERR.
281+The format of the message is as follows:
282+
283+ OUTPUT=foo
284+ INPUT=bar
285+ INPUT=Foo Baz
286+
287+Here `OUTPUT=` is followed by the name of the output file specified
288+using `-o`, if any. If no output file was specified, `OUTPUT=`
289+will appear with nothing following it. Lines beginning `INPUT=`
290+specify input files. If there are no input files, no `INPUT=` lines
291+will be printed. The `-d` option forces output to be written to
292+STDOUT, even if an output file was specified using the `-o` option.
293+(This option is provided to make it easier to write wrappers for
294+`pandoc`.)
295+
296+`-v` or `--version` prints the version number to STDERR.
297+
298+`-h` or `--help` prints a usage message to STDERR.
299+
300+Pandoc's markdown vs. standard markdown
301+=======================================
257302
258303In parsing markdown, Pandoc departs from and extends [standard markdown]
259304in a few respects. (To run Pandoc on the official
260305markdown test suite, type `make test-markdown`.)
261306
262307[standard markdown]: http://daringfireball.net/projects/markdown/syntax
308+ "Markdown syntax description"
263309
264−## Section Headings
310+Section Headings
311+----------------
265312
266313Pandoc creates an invisible anchor in front of every HTML section
267314heading. The ID of this anchor is derived from the section heading
@@ -281,7 +328,8 @@ example, just insert:
281328
282329 [Back to Aristotle](#Aristotle's_De_Anima)
283330
284−## Lists
331+Lists
332+-----
285333
286334Pandoc behaves differently from standard markdown on some "edge
287335cases" involving lists. Consider this source:
@@ -332,7 +380,8 @@ the example above:
332380 B) Fie
333381 C) Third
334382
335−## Literal quotes in titles
383+Literal quotes in titles
384+------------------------
336385
337386Standard markdown allows unescaped literal quotes in titles, as
338387in
@@ -343,7 +392,8 @@ Pandoc requires all quotes within titles to be escaped:
343392
344393 [foo]: "bar \"embedded\" baz"
345394
346−## Reference links
395+Reference links
396+---------------
347397
348398Pandoc allows implicit reference links in either of two styles:
349399
@@ -357,7 +407,8 @@ will appear as regular bracketed text. Note: even `[link][]` will
357407appear as `[link]` if there's no reference for `link`. If you want
358408`[link][]`, use a backslash escape: `\[link]\[]`.
359409
360−## Footnotes
410+Footnotes
411+---------
361412
362413Pandoc's markdown allows footnotes, using the following syntax:
363414
@@ -394,7 +445,8 @@ they cannot contain multiple paragraphs). The syntax is as follows:
394445
395446Inline and regular footnotes may be mixed freely.
396447
397−## Embedded HTML
448+Embedded HTML
449+-------------
398450
399451Pandoc treats embedded HTML in markdown a bit differently than
400452Markdown 1.0. While Markdown 1.0 leaves HTML blocks exactly as they
@@ -427,7 +479,8 @@ markdown with HTML block elements. For example, one can surround
427479a block of markdown text with `<div>` tags without preventing it
428480from being interpreted as markdown.
429481
430−## Title blocks
482+Title blocks
483+------------
431484
432485If the file begins with a title block
433486
@@ -460,7 +513,8 @@ If a title prefix is specified with `-T` and no title block appears
460513in the document, the title prefix will be used by itself as the
461514HTML title.
462515
463−## Box-style blockquotes
516+Box-style blockquotes
517+---------------------
464518
465519Pandoc supports emacs-style boxquote block quotes, in addition to
466520standard markdown (email-style) boxquotes:
@@ -469,7 +523,8 @@ standard markdown (email-style) boxquotes:
469523 | They look like this.
470524 `----
471525
472−## Inline LaTeX
526+Inline LaTeX
527+------------
473528
474529Anything between two $ characters will be parsed as LaTeX math. The
475530opening $ must have a character immediately to its right, while the
@@ -501,7 +556,8 @@ You can also use LaTeX environments. For example,
501556Note, however, that material between the begin and end tags will
502557be interpreted as raw LaTeX, not as markdown.
503558
504−## Custom headers
559+Custom headers
560+--------------
505561
506562When run with the "standalone" option (`-s`), `pandoc` creates a
507563standalone file, complete with an appropriate header. To see the
@@ -516,13 +572,14 @@ it and specify it on the command line as follows:
516572
517573 pandoc --header=MyHeaderFile
518574
519−# Producing S5 with Pandoc
575+Producing S5 with Pandoc
576+========================
520577
521−Producing an [S5] slide show with Pandoc is easy. A title page is
522−constructed automatically from the document's title block (see above).
523−Each section (with a level-one header) produces a single slide. (Note
524−that if the section is too big, the slide will not fit on the page; S5
525−is not smart enough to produce multiple pages.)
578+Producing an [S5] web-based slide show with Pandoc is easy. A title
579+page is constructed automatically from the document's title block (see
580+above). Each section (with a level-one header) produces a single slide.
581+(Note that if the section is too big, the slide will not fit on the page;
582+S5 is not smart enough to produce multiple pages.)
526583
527584Here's the markdown source for a simple slide show, `eating.txt`:
528585