diff --git a/MakeManPage.hs b/MakeManPage.hs
--- a/MakeManPage.hs
+++ b/MakeManPage.hs
@@ -28,7 +28,7 @@
   modDeps <- modifiedDependencies markdown2pdfpage [markdown2pdfpage <.> "md"]
   unless (null modDeps) $ do
     mpdfContents <- liftM toString $ B.readFile $ markdown2pdfpage <.> "md"
-    templ <- liftM toString $ B.readFile $ "templates" </> "man.template"
+    templ <- liftM toString $ B.readFile $ "templates" </> "default.man"
     let doc = readMarkdown defaultParserState{ stateStandalone = True }
                                              mpdfContents
     writeManPage markdown2pdfpage templ doc
diff --git a/README b/README
--- a/README
+++ b/README
@@ -1,6 +1,6 @@
 % Pandoc User's Guide
 % John MacFarlane
-% January 29, 2011
+% July 30, 2011
 
 Synopsis
 ========
@@ -238,9 +238,11 @@
     no link to the jsMath load script will be inserted; it is then
     up to the author to provide such a link in the HTML template.
 
-`--mathjax=`*URL*
+`--mathjax`[=*URL*]
 :   Use [MathJax] to display embedded TeX math in HTML output.
     The *URL* should point to the `MathJax.js` load script.
+    If a *URL* is not provided, a link to the MathJax CDN will
+    be inserted.
 
 `--gladtex`
 :   Enclose TeX math in `<eq>` tags in HTML output.  These can then
@@ -265,9 +267,6 @@
     show in the output, so that the slide show will work even when no
     internet connection is available.
 
-`--xetex`
-:   Create LaTeX outut suitable for processing by XeTeX.
-
 `--chapters`
 :   Treat top-level headers as chapters in LaTeX, ConTeXt, and DocBook
     output.
@@ -327,13 +326,17 @@
 `--template=`*FILE*
 :   Use *FILE* as a custom template for the generated document. Implies
     `--standalone`. See [Templates](#templates) below for a description
-    of template syntax. If this option is not used, a default
-    template appropriate for the output format will be used. See also
-    `-D/--print-default-template`.
+    of template syntax. If no extension is specified, an extension
+    corresponding to the writer will be added, so that `--template=special`
+    looks for `special.html` for HTML output.  If the template is not
+    found, pandoc will search for it in the user data directory
+    (see `--data-dir`). If this option is not used, a default
+    template appropriate for the output format will be used (see
+    `-D/--print-default-template`).
 
 `-V` *KEY=VAL*, `--variable=`*KEY:VAL*
 :   Set the template variable *KEY* to the value *VAL* when rendering the
-    document in standalone mode. This is only useful when the
+    document in standalone mode. This is generally only useful when the
     `--template` option is used to specify a custom template, since
     pandoc automatically sets the variables used in the default
     templates.
@@ -501,7 +504,7 @@
 where `FORMAT` is the name of the output format. A custom template
 can be specified using the `--template` option.  You can also override
 the system default templates for a given output format `FORMAT`
-by putting a file `templates/FORMAT.template` in the user data
+by putting a file `templates/default.FORMAT` in the user data
 directory (see `--data-dir`, above).
 
 Templates may contain *variables*.  Variable names are sequences of
@@ -540,6 +543,11 @@
 :   date of document, as specified in title block
 `lang`
 :   language code for HTML documents
+`slidy-url`
+:   base URL for Slidy documents (defaults to
+    `http://www.w3.org/Talks/Tools/Slidy2`)
+`s5-url`
+:   base URL for S5 documents (defaults to `ui/default`)
 
 Variables may be set at the command line using the `-V/--variable`
 option. This allows users to include custom variables in their
@@ -570,6 +578,13 @@
 
     $for(author)$$author$$sep$, $endfor$
 
+If you use custom templates, you may need to revise them as pandoc
+changes.  We recommend tracking the changes in the default templates,
+and modifying your custom templates accordingly. An easy way to do this
+is to fork the pandoc-templates repository
+(<http://github.com/jgm/pandoc-templates>) and merge in changes after each
+pandoc release.
+
 Pandoc's markdown
 =================
 
@@ -1382,6 +1397,9 @@
 to Em-dashes, and `...` to ellipses. Nonbreaking spaces are inserted after
 certain abbreviations, such as "Mr."
 
+Note:  if your LaTeX template uses the `csquotes` package, pandoc will
+detect automatically this and use `\enquote{...}` for quoted text.
+
 Inline formatting
 -----------------
 
@@ -1815,6 +1833,7 @@
 <http://citationstyles.org/downloads/primer.html>.
 A repository of CSL styles can be found at
 <https://github.com/citation-style-language/styles>.
+See also <http://zotero.org/styles> for easy browsing.
 
 Citations go inside square brackets and are separated by semicolons.
 Each citation must have a key, composed of '@' + the citation
@@ -1893,7 +1912,9 @@
 The file produced by pandoc with the `-s/--standalone` option embeds a
 link to javascripts and CSS files, which are assumed to be available at
 the relative path `ui/default` (for S5) or at the Slidy website at
-`w3.org` (for Slidy). If the `--offline` option is specified, the
+`w3.org` (for Slidy).  (These paths can be changed by setting the
+`slidy-url` or `s5-url` variables; see `--variable`, above.)
+If the `--offline` option is specified, the
 scripts and CSS will be included directly in the generated file, so that
 it may be used offline.
 
@@ -1973,7 +1994,8 @@
 Other contributors include Recai Oktaş, Paulo Tanimoto, Peter Wang,
 Andrea Rossato, Eric Kow, infinity0x, Luke Plant, shreevatsa.public,
 Puneeth Chaganti, Paul Rivier, rodja.trappe, Bradley Kuhn, thsutton,
-Nathan Gass, Jonathan Daugherty, Jérémy Bobbio, Justin Bogner.
+Nathan Gass, Jonathan Daugherty, Jérémy Bobbio, Justin Bogner, qerub,
+Christopher Sawicki, Kelsey Hightower.
 
 [markdown]: http://daringfireball.net/projects/markdown/
 [reStructuredText]: http://docutils.sourceforge.net/docs/ref/rst/introduction.html
diff --git a/changelog b/changelog
--- a/changelog
+++ b/changelog
@@ -1,3 +1,124 @@
+pandoc (1.8.2)
+
+  * Added script to produce OS X package.
+
+  * Made `templates` directory a git submodule.  This should make it
+    easier for people to revise their custom templates when the default
+    templates change.
+
+  * Changed template naming scheme: `FORMAT.template` -> `default.FORMAT`.
+    **Note:** If you have existing templates in `~/.pandoc/templates`, you
+    must rename them to conform to the new scheme!
+
+  * Fixed smart quotes bug, now handling `'...hi'` properly.
+
+  * RST reader:
+
+    + Partial support for labeled footnotes.
+    + Improved accuracy of `simpleReferenceName` parser.
+
+  * HTML reader:
+
+    + Substitute correct unicode characters for
+      characters in the 128..159 range, which are often found even in
+      HTML that purports to be UTF-8.
+
+  * LaTeX reader:  Handle `\subtitle` command (a subtitle is added
+    to the title, after a colon and linebreak). Closes #280.
+
+  * Leaner `reference.odt`.
+
+  * Added unexported module `Text.Pandoc.MIME` for use in
+    the ODT writer.
+
+  * ODT writer:  Construct `manifest.xml` based on archive contents.
+    This fixes a bug in ODTs containing images. Recent versions of
+    LibreOffice would reject these as corrupt, because `manifest.xml`
+    did not contain a reference to the image files.
+
+  * LaTeX writer:
+
+    + Make verbatim environments flush to avoid spurious
+      blank lines.  Closes #277.
+    + Use `\texttt` and escapes insntead of `\verb!...!`, which
+      is too fragile (doesn't work in command arguments).
+    + Use `\enquote{}` for quotes if the template includes
+      the `csquotes` package. This provides better support for
+      local quoting styles. (Thanks to Andreas Wagner for the idea.)
+
+  * ConTeXt writer:  Make `\starttyping`/`\stoptyping` flush with
+    margin, preventing spurious blank lines.
+
+  * Slidy writer:
+
+    + Use non-minimized version of `slidy.css` with `--offline`
+      option, so users can more easily edit it.
+    + Also fixed a bug in the CSS that prevented proper centering
+      of title (now reported and fixed upstream).
+
+  * S5 writer:
+
+    + Replaced `s5/default/slides.js.{comment,packed}` with
+      new compressed `s5/default/slides.min.js`.
+    + Use `data:` protocol to embed S5 CSS in `<link>` tags,
+      when `--offline` is specified. Using inline CSS didn't
+      work with Chrome or Safari.  This fixes offline
+      S5 on those browsers.
+
+  * HTML writer:  Removed English title on footnote backlinks.
+    This is incongrous in non-English documents.
+
+  * Docbook writer:
+
+    + Use CALS tables.  (Some older docbook software does not work
+      well with XHTML tables.)  Closes #77.
+    + Use `programlisting` tags (instead of `screen`) for code blocks.
+
+  * `markdown2pdf`:
+
+    + Calls latex with `-halt-on-error -interaction nonstopmode` instead
+      of `-interaction=batchmode`, which essentially just ignored errors,
+      leading to bad results. Better to know when something is wrong.
+    + Fixed issues with non-UTF-8 output of `pdflatex`.
+    + Better error reporting.
+
+  * `--mathjax` now takes an optional URL argument. If it is not
+    provided, pandoc links directly to the (secure) mathjax CDN,
+    as now recommended (thanks to dsanson).
+
+  * Deprecated `--xetex` option in `pandoc`.  It is no longer needed,
+    since the LaTeX writer now produces a file that can be processed by
+    `latex`, `pdflatex`, `lualatex`, or `xelatex`.
+
+  * Introduced `--luatex` option to `markdown2pdf`. This causes `lualatex`
+    to be used to create the PDF.
+
+  * If a template specified with `--template` is not found, look for it
+    in `datadir`.  Also, if no extension is provided, supply one based
+    on the writer.  So now you can put your `special.latex` template in
+    `~/.pandoc/templates`, and use it from any directory via
+    `pandoc -t latex --template special`.
+
+  * Default template improvements:
+
+    + HTML:  Display author and date after title.
+    + HTML:  Made table of contents more customizable.  The container
+      for the TOC is now in the template, so users can insert a header
+      or other styling. (Thanks to Bruce D'Arcus for the suggestion.)
+    + HTML, Slidy, S5:  Enclose scripts in CDATA tags.
+    + Slidy, S5: Added `s5-url` and `slidy-url` variables, instead of
+      hard-coding.  If you want to put your slidy files in the slidy
+      subdirectory, for example, you can do
+      `pandoc -t slidy -V slidy-url=slidy -s`.
+    + LaTeX: Use `\and` to separate authors in LaTeX documents (reader
+      & writer).  Closes #279.
+    + LaTeX: Use different `hyperref` options for `xetex`, fixing
+      problems with unicode bookmarks (thanks to CircleCode).
+    + LaTeX: Removed `ucs` package, use `utf8` rather than `utf8x`
+      with `inputenc`.  This covers fewer characters but is more
+      robust with other packages, and `ucs` is unmaintained.  Users
+      who need better unicode support should use xelatex or lualatex.
+
 pandoc (1.8.1.2)
 
   * Added `--epub-cover-image` option.
@@ -33,8 +154,11 @@
     HTML tags can be used freely at the left margin of a markdown+lhs document.
     Thanks to Conal Elliot for the suggestion.
 
-  * Markdown reader: Fixed bug in footnote order (reported by CircleCode).
+  * Markdown reader:
 
+    + Improved emph/strong parsing; fixes bug found by Perry Wagle.
+    + Fixed bug in footnote order (reported by CircleCode).
+
   * RST reader:
       + Fixed bug in in field lists with multi-line items at the
         end of the list.
@@ -391,6 +515,8 @@
   * Moved `smartPunctuation` from `Text.Pandoc.Readers.Markdown`
     to `Text.Pandoc.Readers.Parsing`, and parameterized it with
     an inline parser.
+
+  * Added `nonspaceChar` to `Text.Pandoc.Parsing`.
 
   * Ellipses are no longer allowed to contain spaces.
     Previously we allowed '. . .', ' . . . ', etc.  This caused
diff --git a/man/man1/markdown2pdf.1 b/man/man1/markdown2pdf.1
--- a/man/man1/markdown2pdf.1
+++ b/man/man1/markdown2pdf.1
@@ -47,11 +47,6 @@
 .RS
 .RE
 .TP
-.B --xetex
-Use xelatex instead of pdflatex to create the PDF.
-.RS
-.RE
-.TP
 .B -N, --number-sections
 Number section headings in LaTeX output.
 (Default is not to number them.)
@@ -157,6 +152,16 @@
 A \f[C]reference.odt\f[], \f[C]epub.css\f[], \f[C]templates\f[]
 directory, or \f[C]s5\f[] directory placed in this directory will
 override pandoc\[aq]s normal defaults.
+.RE
+.TP
+.B --xetex
+Use xelatex instead of pdflatex to create the PDF.
+.RS
+.RE
+.TP
+.B --luatex
+Use lualatex instead of pdflatex to create the PDF.
+.RS
 .RE
 .SH SEE ALSO
 .PP
diff --git a/man/man1/markdown2pdf.1.md b/man/man1/markdown2pdf.1.md
--- a/man/man1/markdown2pdf.1.md
+++ b/man/man1/markdown2pdf.1.md
@@ -42,9 +42,6 @@
 \--strict
 :   Use strict markdown syntax, with no extensions or variants.
 
-\--xetex
-:   Use xelatex instead of pdflatex to create the PDF.
-
 -N, \--number-sections
 :   Number section headings in LaTeX output.  (Default is not to number them.)
 
@@ -108,6 +105,12 @@
     in Windows. A `reference.odt`, `epub.css`, `templates` directory,
     or `s5` directory placed in this directory will override pandoc's
     normal defaults.
+
+\--xetex
+:   Use xelatex instead of pdflatex to create the PDF.
+
+\--luatex
+:   Use lualatex instead of pdflatex to create the PDF.
 
 # SEE ALSO
 
diff --git a/man/man1/pandoc.1 b/man/man1/pandoc.1
--- a/man/man1/pandoc.1
+++ b/man/man1/pandoc.1
@@ -1,4 +1,4 @@
-.TH PANDOC 1 "January 29, 2011" "Pandoc"
+.TH PANDOC 1 "July 30, 2011" "Pandoc"
 .SH NAME
 pandoc - general markup converter
 .SH SYNOPSIS
@@ -263,9 +263,11 @@
 .RS
 .RE
 .TP
-.B \f[C]--mathjax=\f[]\f[I]URL\f[]
+.B \f[C]--mathjax\f[][=\f[I]URL\f[]]
 Use MathJax to display embedded TeX math in HTML output.
 The \f[I]URL\f[] should point to the \f[C]MathJax.js\f[] load script.
+If a \f[I]URL\f[] is not provided, a link to the MathJax CDN will be
+inserted.
 .RS
 .RE
 .TP
@@ -304,11 +306,6 @@
 .RS
 .RE
 .TP
-.B \f[C]--xetex\f[]
-Create LaTeX outut suitable for processing by XeTeX.
-.RS
-.RE
-.TP
 .B \f[C]--chapters\f[]
 Treat top-level headers as chapters in LaTeX, ConTeXt, and DocBook
 output.
@@ -397,18 +394,22 @@
 Use \f[I]FILE\f[] as a custom template for the generated document.
 Implies \f[C]--standalone\f[].
 See Templates below for a description of template syntax.
+If no extension is specified, an extension corresponding to the writer
+will be added, so that \f[C]--template=special\f[] looks for
+\f[C]special.html\f[] for HTML output.
+If the template is not found, pandoc will search for it in the user data
+directory (see \f[C]--data-dir\f[]).
 If this option is not used, a default template appropriate for the
-output format will be used.
-See also \f[C]-D/--print-default-template\f[].
+output format will be used (see \f[C]-D/--print-default-template\f[]).
 .RS
 .RE
 .TP
 .B \f[C]-V\f[] \f[I]KEY=VAL\f[], \f[C]--variable=\f[]\f[I]KEY:VAL\f[]
 Set the template variable \f[I]KEY\f[] to the value \f[I]VAL\f[] when
 rendering the document in standalone mode.
-This is only useful when the \f[C]--template\f[] option is used to
-specify a custom template, since pandoc automatically sets the variables
-used in the default templates.
+This is generally only useful when the \f[C]--template\f[] option is
+used to specify a custom template, since pandoc automatically sets the
+variables used in the default templates.
 .RS
 .RE
 .TP
@@ -656,7 +657,7 @@
 A custom template can be specified using the \f[C]--template\f[] option.
 You can also override the system default templates for a given output
 format \f[C]FORMAT\f[] by putting a file
-\f[C]templates/FORMAT.template\f[] in the user data directory (see
+\f[C]templates/default.FORMAT\f[] in the user data directory (see
 \f[C]--data-dir\f[], above).
 .PP
 Templates may contain \f[I]variables\f[].
@@ -727,6 +728,17 @@
 language code for HTML documents
 .RS
 .RE
+.TP
+.B \f[C]slidy-url\f[]
+base URL for Slidy documents (defaults to
+\f[C]http://www.w3.org/Talks/Tools/Slidy2\f[])
+.RS
+.RE
+.TP
+.B \f[C]s5-url\f[]
+base URL for S5 documents (defaults to \f[C]ui/default\f[])
+.RS
+.RE
 .PP
 Variables may be set at the command line using the
 \f[C]-V/--variable\f[] option.
@@ -770,6 +782,14 @@
 $for(author)$$author$$sep$,\ $endfor$
 \f[]
 .fi
+.PP
+If you use custom templates, you may need to revise them as pandoc
+changes.
+We recommend tracking the changes in the default templates, and
+modifying your custom templates accordingly.
+An easy way to do this is to fork the pandoc-templates repository
+(\f[C]http://github.com/jgm/pandoc-templates\f[]) and merge in changes
+after each pandoc release.
 .SH PRODUCING HTML SLIDE SHOWS WITH PANDOC
 .PP
 You can use Pandoc to produce an HTML + javascript slide presentation
@@ -827,7 +847,9 @@
 embeds a link to javascripts and CSS files, which are assumed to be
 available at the relative path \f[C]ui/default\f[] (for S5) or at the
 Slidy website at \f[C]w3.org\f[] (for Slidy).
-If the \f[C]--offline\f[] option is specified, the scripts and CSS will
+(These paths can be changed by setting the \f[C]slidy-url\f[] or
+\f[C]s5-url\f[] variables; see \f[C]--variable\f[], above.)
+ If the \f[C]--offline\f[] option is specified, the scripts and CSS will
 be included directly in the generated file, so that it may be used
 offline.
 .PP
@@ -921,7 +943,8 @@
  Other contributors include Recai Oktaş, Paulo Tanimoto, Peter Wang,
 Andrea Rossato, Eric Kow, infinity0x, Luke Plant, shreevatsa.public,
 Puneeth Chaganti, Paul Rivier, rodja.trappe, Bradley Kuhn, thsutton,
-Nathan Gass, Jonathan Daugherty, Jérémy Bobbio, Justin Bogner.
+Nathan Gass, Jonathan Daugherty, Jérémy Bobbio, Justin Bogner, qerub,
+Christopher Sawicki, Kelsey Hightower.
 .SH PANDOC'S MARKDOWN
 For a complete description of pandoc's extensions to standard markdown,
 see \f[C]pandoc_markdown\f[] (5).
diff --git a/man/man5/pandoc_markdown.5 b/man/man5/pandoc_markdown.5
--- a/man/man5/pandoc_markdown.5
+++ b/man/man5/pandoc_markdown.5
@@ -1,5 +1,5 @@
 .\"t
-.TH PANDOC_MARKDOWN 5 "January 29, 2011" "Pandoc"
+.TH PANDOC_MARKDOWN 5 "July 30, 2011" "Pandoc"
 .SH NAME
 pandoc_markdown - markdown syntax for pandoc(1)
 .SH DESCRIPTION
@@ -1040,6 +1040,10 @@
 ellipses.
 Nonbreaking spaces are inserted after certain abbreviations, such as
 "Mr."
+.PP
+Note: if your LaTeX template uses the \f[C]csquotes\f[] package, pandoc
+will detect automatically this and use \f[C]\\enquote{...}\f[] for
+quoted text.
 .SH INLINE FORMATTING
 .SS Emphasis
 .PP
@@ -1629,6 +1633,7 @@
 \f[C]http://citationstyles.org/downloads/primer.html\f[].
 A repository of CSL styles can be found at
 \f[C]https://github.com/citation-style-language/styles\f[].
+See also \f[C]http://zotero.org/styles\f[] for easy browsing.
 .PP
 Citations go inside square brackets and are separated by semicolons.
 Each citation must have a key, composed of \[aq]\@\[aq] + the citation
diff --git a/pandoc.cabal b/pandoc.cabal
--- a/pandoc.cabal
+++ b/pandoc.cabal
@@ -1,5 +1,5 @@
 Name:            pandoc
-Version:         1.8.1.2
+Version:         1.8.2
 Cabal-Version:   >= 1.6
 Build-Type:      Custom
 License:         GPL
@@ -11,7 +11,7 @@
 Stability:       alpha
 Homepage:        http://johnmacfarlane.net/pandoc
 Category:        Text
-Tested-With:     GHC == 6.10.4, GHC == 6.12.1, GHC == 6.12.3, GHC == 7.0.1
+Tested-With:     GHC == 6.12.3, GHC == 7.0.3
 Synopsis:        Conversion between markup formats
 Description:     Pandoc is a Haskell library for converting from one markup
                  format to another, and a command-line tool that uses
@@ -37,14 +37,14 @@
                  only adding a reader or writer.
 Data-Files:
                  -- templates
-                 templates/html.template, templates/docbook.template,
-                 templates/opendocument.template, templates/latex.template,
-                 templates/context.template, templates/texinfo.template,
-                 templates/man.template, templates/markdown.template,
-                 templates/rst.template, templates/plain.template,
-                 templates/mediawiki.template, templates/rtf.template,
-                 templates/s5.template, templates/slidy.template,
-                 templates/textile.template, templates/org.template
+                 templates/default.html, templates/default.docbook,
+                 templates/default.opendocument, templates/default.latex,
+                 templates/default.context, templates/default.texinfo,
+                 templates/default.man, templates/default.markdown,
+                 templates/default.rst, templates/default.plain,
+                 templates/default.mediawiki, templates/default.rtf,
+                 templates/default.s5, templates/default.slidy,
+                 templates/default.textile, templates/default.org
                  -- data for ODT writer
                  reference.odt,
                  -- stylesheet for EPUB writer
@@ -53,8 +53,7 @@
                  data/LaTeXMathML.js,
                  data/MathMLinHTML.js,
                  -- data for S5 writer
-                 s5/default/slides.js.comment,
-                 s5/default/slides.js.packed,
+                 s5/default/slides.min.js,
                  s5/default/s5-core.css,
                  s5/default/framing.css,
                  s5/default/pretty.css,
@@ -62,7 +61,7 @@
                  s5/default/outline.css,
                  s5/default/print.css,
                  -- data for slidy writer
-                 slidy/slidy.min.css,
+                 slidy/slidy.css,
                  slidy/slidy.min.js,
                  -- data for citeproc
                  default.csl,
@@ -208,10 +207,11 @@
                  random >= 1 && < 1.1,
                  extensible-exceptions >= 0.1 && < 0.2,
                  citeproc-hs >= 0.3.1 && < 0.4,
-                 pandoc-types == 1.8.*,
+                 pandoc-types == 1.8.0.2,
                  json >= 0.4 && < 0.5,
                  dlist >= 0.4 && < 0.6,
-                 tagsoup >= 0.12 && < 0.13
+                 tagsoup >= 0.12 && < 0.13,
+                 base64-bytestring >= 0.1 && < 0.2
   if impl(ghc >= 6.10)
     Build-depends: base >= 4 && < 5, syb >= 0.1 && < 0.4
   else
@@ -262,6 +262,7 @@
                    Text.Pandoc.Biblio
   Other-Modules:   Text.Pandoc.XML,
                    Text.Pandoc.UTF8,
+                   Text.Pandoc.MIME,
                    Text.Pandoc.UUID,
                    Paths_pandoc
 
@@ -292,10 +293,11 @@
                  random >= 1 && < 1.1,
                  extensible-exceptions >= 0.1 && < 0.2,
                  citeproc-hs >= 0.3.1 && < 0.4,
-                 pandoc-types == 1.8.*,
+                 pandoc-types == 1.8.0.2,
                  json >= 0.4 && < 0.5,
                  dlist >= 0.4 && < 0.6,
-                 tagsoup >= 0.12 && < 0.13
+                 tagsoup >= 0.12 && < 0.13,
+                 base64-bytestring >= 0.1 && < 0.2
   if impl(ghc >= 6.10)
     Build-depends: base >= 4 && < 5, syb >= 0.1 && < 0.4
   else
@@ -366,3 +368,4 @@
                       Tests.Writers.Native
                       Tests.Writers.ConTeXt
                       Tests.Writers.HTML
+                      Tests.Writers.Markdown
diff --git a/reference.odt b/reference.odt
Binary files a/reference.odt and b/reference.odt differ
diff --git a/s5/default/slides.js.comment b/s5/default/slides.js.comment
deleted file mode 100644
--- a/s5/default/slides.js.comment
+++ /dev/null
@@ -1,4 +0,0 @@
-// S5 v1.1 slides.js -- released into the Public Domain
-//
-// Please see http://www.meyerweb.com/eric/tools/s5/credits.html for information 
-// about all the wonderful and talented contributors to this code!
diff --git a/s5/default/slides.js.packed b/s5/default/slides.js.packed
deleted file mode 100644
--- a/s5/default/slides.js.packed
+++ /dev/null
@@ -1,74 +0,0 @@
-var undef;var slideCSS='';var snum=0;var smax=1;var incpos=0;var number=undef;var s5mode=true;var defaultView='slideshow';var controlVis='visible';var isIE=navigator.appName=='Microsoft Internet Explorer'&&navigator.userAgent.indexOf('Opera')<1?1:0;var isOp=navigator.userAgent.indexOf('Opera')>-1?1:0;var isGe=navigator.userAgent.indexOf('Gecko')>-1&&navigator.userAgent.indexOf('Safari')<1?1:0;function hasClass(object,className){if(!object.className)return false;return(object.className.search('(^|\\s)'+className+'(\\s|$)')!=-1);}
-function hasValue(object,value){if(!object)return false;return(object.search('(^|\\s)'+value+'(\\s|$)')!=-1);}
-function removeClass(object,className){if(!object)return;object.className=object.className.replace(new RegExp('(^|\\s)'+className+'(\\s|$)'),RegExp.$1+RegExp.$2);}
-function addClass(object,className){if(!object||hasClass(object,className))return;if(object.className){object.className+=' '+className;}else{object.className=className;}}
-function GetElementsWithClassName(elementName,className){var allElements=document.getElementsByTagName(elementName);var elemColl=new Array();for(var i=0;i<allElements.length;i++){if(hasClass(allElements[i],className)){elemColl[elemColl.length]=allElements[i];}}
-return elemColl;}
-function isParentOrSelf(element,id){if(element==null||element.nodeName=='BODY')return false;else if(element.id==id)return true;else return isParentOrSelf(element.parentNode,id);}
-function nodeValue(node){var result="";if(node.nodeType==1){var children=node.childNodes;for(var i=0;i<children.length;++i){result+=nodeValue(children[i]);}}
-else if(node.nodeType==3){result=node.nodeValue;}
-return(result);}
-function slideLabel(){var slideColl=GetElementsWithClassName('*','slide');var list=document.getElementById('jumplist');smax=slideColl.length;for(var n=0;n<smax;n++){var obj=slideColl[n];var did='slide'+n.toString();obj.setAttribute('id',did);if(isOp)continue;var otext='';var menu=obj.firstChild;if(!menu)continue;while(menu&&menu.nodeType==3){menu=menu.nextSibling;}
-if(!menu)continue;var menunodes=menu.childNodes;for(var o=0;o<menunodes.length;o++){otext+=nodeValue(menunodes[o]);}
-list.options[list.length]=new Option(n+' : '+otext,n);}}
-function currentSlide(){var cs;if(document.getElementById){cs=document.getElementById('currentSlide');}else{cs=document.currentSlide;}
-cs.innerHTML='<span id="csHere">'+snum+'<\/span> '+'<span id="csSep">\/<\/span> '+'<span id="csTotal">'+(smax-1)+'<\/span>';if(snum==0){cs.style.visibility='hidden';}else{cs.style.visibility='visible';}}
-function go(step){if(document.getElementById('slideProj').disabled||step==0)return;var jl=document.getElementById('jumplist');var cid='slide'+snum;var ce=document.getElementById(cid);if(incrementals[snum].length>0){for(var i=0;i<incrementals[snum].length;i++){removeClass(incrementals[snum][i],'current');removeClass(incrementals[snum][i],'incremental');}}
-if(step!='j'){snum+=step;lmax=smax-1;if(snum>lmax)snum=lmax;if(snum<0)snum=0;}else
-snum=parseInt(jl.value);var nid='slide'+snum;var ne=document.getElementById(nid);if(!ne){ne=document.getElementById('slide0');snum=0;}
-if(step<0){incpos=incrementals[snum].length}else{incpos=0;}
-if(incrementals[snum].length>0&&incpos==0){for(var i=0;i<incrementals[snum].length;i++){if(hasClass(incrementals[snum][i],'current'))
-incpos=i+1;else
-addClass(incrementals[snum][i],'incremental');}}
-if(incrementals[snum].length>0&&incpos>0)
-addClass(incrementals[snum][incpos-1],'current');ce.style.visibility='hidden';ne.style.visibility='visible';jl.selectedIndex=snum;currentSlide();number=0;}
-function goTo(target){if(target>=smax||target==snum)return;go(target-snum);}
-function subgo(step){if(step>0){removeClass(incrementals[snum][incpos-1],'current');removeClass(incrementals[snum][incpos],'incremental');addClass(incrementals[snum][incpos],'current');incpos++;}else{incpos--;removeClass(incrementals[snum][incpos],'current');addClass(incrementals[snum][incpos],'incremental');addClass(incrementals[snum][incpos-1],'current');}}
-function toggle(){var slideColl=GetElementsWithClassName('*','slide');var slides=document.getElementById('slideProj');var outline=document.getElementById('outlineStyle');if(!slides.disabled){slides.disabled=true;outline.disabled=false;s5mode=false;fontSize('1em');for(var n=0;n<smax;n++){var slide=slideColl[n];slide.style.visibility='visible';}}else{slides.disabled=false;outline.disabled=true;s5mode=true;fontScale();for(var n=0;n<smax;n++){var slide=slideColl[n];slide.style.visibility='hidden';}
-slideColl[snum].style.visibility='visible';}}
-function showHide(action){var obj=GetElementsWithClassName('*','hideme')[0];switch(action){case's':obj.style.visibility='visible';break;case'h':obj.style.visibility='hidden';break;case'k':if(obj.style.visibility!='visible'){obj.style.visibility='visible';}else{obj.style.visibility='hidden';}
-break;}}
-function keys(key){if(!key){key=event;key.which=key.keyCode;}
-if(key.which==84){toggle();return;}
-if(s5mode){switch(key.which){case 10:case 13:if(window.event&&isParentOrSelf(window.event.srcElement,'controls'))return;if(key.target&&isParentOrSelf(key.target,'controls'))return;if(number!=undef){goTo(number);break;}
-case 32:case 34:case 39:case 40:if(number!=undef){go(number);}else if(!incrementals[snum]||incpos>=incrementals[snum].length){go(1);}else{subgo(1);}
-break;case 33:case 37:case 38:if(number!=undef){go(-1*number);}else if(!incrementals[snum]||incpos<=0){go(-1);}else{subgo(-1);}
-break;case 36:goTo(0);break;case 35:goTo(smax-1);break;case 67:showHide('k');break;}
-if(key.which<48||key.which>57){number=undef;}else{if(window.event&&isParentOrSelf(window.event.srcElement,'controls'))return;if(key.target&&isParentOrSelf(key.target,'controls'))return;number=(((number!=undef)?number:0)*10)+(key.which-48);}}
-return false;}
-function clicker(e){number=undef;var target;if(window.event){target=window.event.srcElement;e=window.event;}else target=e.target;if(target.getAttribute('href')!=null||hasValue(target.rel,'external')||isParentOrSelf(target,'controls')||isParentOrSelf(target,'embed')||isParentOrSelf(target,'object'))return true;if(!e.which||e.which==1){if(!incrementals[snum]||incpos>=incrementals[snum].length){go(1);}else{subgo(1);}}}
-function findSlide(hash){var target=null;var slides=GetElementsWithClassName('*','slide');for(var i=0;i<slides.length;i++){var targetSlide=slides[i];if((targetSlide.name&&targetSlide.name==hash)||(targetSlide.id&&targetSlide.id==hash)){target=targetSlide;break;}}
-while(target!=null&&target.nodeName!='BODY'){if(hasClass(target,'slide')){return parseInt(target.id.slice(5));}
-target=target.parentNode;}
-return null;}
-function slideJump(){if(window.location.hash==null)return;var sregex=/^#slide(\d+)$/;var matches=sregex.exec(window.location.hash);var dest=null;if(matches!=null){dest=parseInt(matches[1]);}else{dest=findSlide(window.location.hash.slice(1));}
-if(dest!=null)
-go(dest-snum);}
-function fixLinks(){var thisUri=window.location.href;thisUri=thisUri.slice(0,thisUri.length-window.location.hash.length);var aelements=document.getElementsByTagName('A');for(var i=0;i<aelements.length;i++){var a=aelements[i].href;var slideID=a.match('\#slide[0-9]{1,2}');if((slideID)&&(slideID[0].slice(0,1)=='#')){var dest=findSlide(slideID[0].slice(1));if(dest!=null){if(aelements[i].addEventListener){aelements[i].addEventListener("click",new Function("e","if (document.getElementById('slideProj').disabled) return;"+"go("+dest+" - snum); "+"if (e.preventDefault) e.preventDefault();"),true);}else if(aelements[i].attachEvent){aelements[i].attachEvent("onclick",new Function("","if (document.getElementById('slideProj').disabled) return;"+"go("+dest+" - snum); "+"event.returnValue = false;"));}}}}}
-function externalLinks(){if(!document.getElementsByTagName)return;var anchors=document.getElementsByTagName('a');for(var i=0;i<anchors.length;i++){var anchor=anchors[i];if(anchor.getAttribute('href')&&hasValue(anchor.rel,'external')){anchor.target='_blank';addClass(anchor,'external');}}}
-function createControls(){var controlsDiv=document.getElementById("controls");if(!controlsDiv)return;var hider=' onmouseover="showHide(\'s\');" onmouseout="showHide(\'h\');"';var hideDiv,hideList='';if(controlVis=='hidden'){hideDiv=hider;}else{hideList=hider;}
-controlsDiv.innerHTML='<form action="#" id="controlForm"'+hideDiv+'>'+'<div id="navLinks">'+'<a accesskey="t" id="toggle" href="javascript:toggle();">&#216;<\/a>'+'<a accesskey="z" id="prev" href="javascript:go(-1);">&laquo;<\/a>'+'<a accesskey="x" id="next" href="javascript:go(1);">&raquo;<\/a>'+'<div id="navList"'+hideList+'><select id="jumplist" onchange="go(\'j\');"><\/select><\/div>'+'<\/div><\/form>';if(controlVis=='hidden'){var hidden=document.getElementById('navLinks');}else{var hidden=document.getElementById('jumplist');}
-addClass(hidden,'hideme');}
-function fontScale(){if(!s5mode)return false;var vScale=22;var hScale=32;if(window.innerHeight){var vSize=window.innerHeight;var hSize=window.innerWidth;}else if(document.documentElement.clientHeight){var vSize=document.documentElement.clientHeight;var hSize=document.documentElement.clientWidth;}else if(document.body.clientHeight){var vSize=document.body.clientHeight;var hSize=document.body.clientWidth;}else{var vSize=700;var hSize=1024;}
-var newSize=Math.min(Math.round(vSize/vScale),Math.round(hSize/hScale));fontSize(newSize+'px');if(isGe){var obj=document.getElementsByTagName('body')[0];obj.style.display='none';obj.style.display='block';}}
-function fontSize(value){if(!(s5ss=document.getElementById('s5ss'))){if(!isIE){document.getElementsByTagName('head')[0].appendChild(s5ss=document.createElement('style'));s5ss.setAttribute('media','screen, projection');s5ss.setAttribute('id','s5ss');}else{document.createStyleSheet();document.s5ss=document.styleSheets[document.styleSheets.length-1];}}
-if(!isIE){while(s5ss.lastChild)s5ss.removeChild(s5ss.lastChild);s5ss.appendChild(document.createTextNode('body {font-size: '+value+' !important;}'));}else{document.s5ss.addRule('body','font-size: '+value+' !important;');}}
-function notOperaFix(){slideCSS=document.getElementById('slideProj').href;var slides=document.getElementById('slideProj');var outline=document.getElementById('outlineStyle');slides.setAttribute('media','screen');outline.disabled=true;if(isGe){slides.setAttribute('href','null');slides.setAttribute('href',slideCSS);}
-if(isIE&&document.styleSheets&&document.styleSheets[0]){document.styleSheets[0].addRule('img','behavior: url(ui/default/iepngfix.htc)');document.styleSheets[0].addRule('div','behavior: url(ui/default/iepngfix.htc)');document.styleSheets[0].addRule('.slide','behavior: url(ui/default/iepngfix.htc)');}}
-function getIncrementals(obj){var incrementals=new Array();if(!obj)
-return incrementals;var children=obj.childNodes;for(var i=0;i<children.length;i++){var child=children[i];if(hasClass(child,'incremental')){if(child.nodeName=='OL'||child.nodeName=='UL'){removeClass(child,'incremental');for(var j=0;j<child.childNodes.length;j++){if(child.childNodes[j].nodeType==1){addClass(child.childNodes[j],'incremental');}}}else{incrementals[incrementals.length]=child;removeClass(child,'incremental');}}
-if(hasClass(child,'show-first')){if(child.nodeName=='OL'||child.nodeName=='UL'){removeClass(child,'show-first');if(child.childNodes[isGe].nodeType==1){removeClass(child.childNodes[isGe],'incremental');}}else{incrementals[incrementals.length]=child;}}
-incrementals=incrementals.concat(getIncrementals(child));}
-return incrementals;}
-function createIncrementals(){var incrementals=new Array();for(var i=0;i<smax;i++){incrementals[i]=getIncrementals(document.getElementById('slide'+i));}
-return incrementals;}
-function defaultCheck(){var allMetas=document.getElementsByTagName('meta');for(var i=0;i<allMetas.length;i++){if(allMetas[i].name=='defaultView'){defaultView=allMetas[i].content;}
-if(allMetas[i].name=='controlVis'){controlVis=allMetas[i].content;}}}
-function trap(e){if(!e){e=event;e.which=e.keyCode;}
-try{modifierKey=e.ctrlKey||e.altKey||e.metaKey;}
-catch(e){modifierKey=false;}
-return modifierKey||e.which==0;}
-function startup(){defaultCheck();if(!isOp)
-createControls();slideLabel();fixLinks();externalLinks();fontScale();if(!isOp){notOperaFix();incrementals=createIncrementals();slideJump();if(defaultView=='outline'){toggle();}
-document.onkeyup=keys;document.onkeypress=trap;document.onclick=clicker;}}
-window.onload=startup;window.onresize=function(){setTimeout('fontScale()',50);}
diff --git a/s5/default/slides.min.js b/s5/default/slides.min.js
new file mode 100644
--- /dev/null
+++ b/s5/default/slides.min.js
@@ -0,0 +1,1 @@
+var undef;var slideCSS="";var snum=0;var smax=1;var incpos=0;var number=undef;var s5mode=true;var defaultView="slideshow";var controlVis="visible";var isIE=navigator.appName=="Microsoft Internet Explorer"&&navigator.userAgent.indexOf("Opera")<1?1:0;var isOp=navigator.userAgent.indexOf("Opera")>-1?1:0;var isGe=navigator.userAgent.indexOf("Gecko")>-1&&navigator.userAgent.indexOf("Safari")<1?1:0;function hasClass(a,b){if(!a.className){return false}return(a.className.search("(^|\\s)"+b+"(\\s|$)")!=-1)}function hasValue(a,b){if(!a){return false}return(a.search("(^|\\s)"+b+"(\\s|$)")!=-1)}function removeClass(a,b){if(!a){return}a.className=a.className.replace(new RegExp("(^|\\s)"+b+"(\\s|$)"),RegExp.$1+RegExp.$2)}function addClass(a,b){if(!a||hasClass(a,b)){return}if(a.className){a.className+=" "+b}else{a.className=b}}function GetElementsWithClassName(a,c){var d=document.getElementsByTagName(a);var e=new Array();for(var b=0;b<d.length;b++){if(hasClass(d[b],c)){e[e.length]=d[b]}}return e}function isParentOrSelf(a,b){if(a==null||a.nodeName=="BODY"){return false}else{if(a.id==b){return true}else{return isParentOrSelf(a.parentNode,b)}}}function nodeValue(d){var a="";if(d.nodeType==1){var c=d.childNodes;for(var b=0;b<c.length;++b){a+=nodeValue(c[b])}}else{if(d.nodeType==3){a=d.nodeValue}}return(a)}function slideLabel(){var f=GetElementsWithClassName("*","slide");var g=document.getElementById("jumplist");smax=f.length;for(var c=0;c<smax;c++){var e=f[c];var i="slide"+c.toString();e.setAttribute("id",i);if(isOp){continue}var d="";var b=e.firstChild;if(!b){continue}while(b&&b.nodeType==3){b=b.nextSibling}if(!b){continue}var h=b.childNodes;for(var a=0;a<h.length;a++){d+=nodeValue(h[a])}g.options[g.length]=new Option(c+" : "+d,c)}}function currentSlide(){var a;if(document.getElementById){a=document.getElementById("currentSlide")}else{a=document.currentSlide}a.innerHTML='<span id="csHere">'+snum+'</span> <span id="csSep">/</span> <span id="csTotal">'+(smax-1)+"</span>";if(snum==0){a.style.visibility="hidden"}else{a.style.visibility="visible"}}function go(c){if(document.getElementById("slideProj").disabled||c==0){return}var b=document.getElementById("jumplist");var g="slide"+snum;var e=document.getElementById(g);if(incrementals[snum].length>0){for(var a=0;a<incrementals[snum].length;a++){removeClass(incrementals[snum][a],"current");removeClass(incrementals[snum][a],"incremental")}}if(c!="j"){snum+=c;lmax=smax-1;if(snum>lmax){snum=lmax}if(snum<0){snum=0}}else{snum=parseInt(b.value)}var f="slide"+snum;var d=document.getElementById(f);if(!d){d=document.getElementById("slide0");snum=0}if(c<0){incpos=incrementals[snum].length}else{incpos=0}if(incrementals[snum].length>0&&incpos==0){for(var a=0;a<incrementals[snum].length;a++){if(hasClass(incrementals[snum][a],"current")){incpos=a+1}else{addClass(incrementals[snum][a],"incremental")}}}if(incrementals[snum].length>0&&incpos>0){addClass(incrementals[snum][incpos-1],"current")}e.style.visibility="hidden";d.style.visibility="visible";b.selectedIndex=snum;currentSlide();number=0}function goTo(a){if(a>=smax||a==snum){return}go(a-snum)}function subgo(a){if(a>0){removeClass(incrementals[snum][incpos-1],"current");removeClass(incrementals[snum][incpos],"incremental");addClass(incrementals[snum][incpos],"current");incpos++}else{incpos--;removeClass(incrementals[snum][incpos],"current");addClass(incrementals[snum][incpos],"incremental");addClass(incrementals[snum][incpos-1],"current")}}function toggle(){var b=GetElementsWithClassName("*","slide");var d=document.getElementById("slideProj");var c=document.getElementById("outlineStyle");if(!d.disabled){d.disabled=true;c.disabled=false;s5mode=false;fontSize("1em");for(var e=0;e<smax;e++){var a=b[e];a.style.visibility="visible"}}else{d.disabled=false;c.disabled=true;s5mode=true;fontScale();for(var e=0;e<smax;e++){var a=b[e];a.style.visibility="hidden"}b[snum].style.visibility="visible"}}function showHide(a){var b=GetElementsWithClassName("*","hideme")[0];switch(a){case"s":b.style.visibility="visible";break;case"h":b.style.visibility="hidden";break;case"k":if(b.style.visibility!="visible"){b.style.visibility="visible"}else{b.style.visibility="hidden"}break}}function keys(a){if(!a){a=event;a.which=a.keyCode}if(a.which==84){toggle();return}if(s5mode){switch(a.which){case 10:case 13:if(window.event&&isParentOrSelf(window.event.srcElement,"controls")){return}if(a.target&&isParentOrSelf(a.target,"controls")){return}if(number!=undef){goTo(number);break}case 32:case 34:case 39:case 40:if(number!=undef){go(number)}else{if(!incrementals[snum]||incpos>=incrementals[snum].length){go(1)}else{subgo(1)}}break;case 33:case 37:case 38:if(number!=undef){go(-1*number)}else{if(!incrementals[snum]||incpos<=0){go(-1)}else{subgo(-1)}}break;case 36:goTo(0);break;case 35:goTo(smax-1);break;case 67:showHide("k");break}if(a.which<48||a.which>57){number=undef}else{if(window.event&&isParentOrSelf(window.event.srcElement,"controls")){return}if(a.target&&isParentOrSelf(a.target,"controls")){return}number=(((number!=undef)?number:0)*10)+(a.which-48)}}return false}function clicker(b){number=undef;var a;if(window.event){a=window.event.srcElement;b=window.event}else{a=b.target}if(a.getAttribute("href")!=null||hasValue(a.rel,"external")||isParentOrSelf(a,"controls")||isParentOrSelf(a,"embed")||isParentOrSelf(a,"object")){return true}if(!b.which||b.which==1){if(!incrementals[snum]||incpos>=incrementals[snum].length){go(1)}else{subgo(1)}}}function findSlide(d){var c=null;var b=GetElementsWithClassName("*","slide");for(var a=0;a<b.length;a++){var e=b[a];if((e.name&&e.name==d)||(e.id&&e.id==d)){c=e;break}}while(c!=null&&c.nodeName!="BODY"){if(hasClass(c,"slide")){return parseInt(c.id.slice(5))}c=c.parentNode}return null}function slideJump(){if(window.location.hash==null){return}var b=/^#slide(\d+)$/;var c=b.exec(window.location.hash);var a=null;if(c!=null){a=parseInt(c[1])}else{a=findSlide(window.location.hash.slice(1))}if(a!=null){go(a-snum)}}function fixLinks(){var f=window.location.href;f=f.slice(0,f.length-window.location.hash.length);var g=document.getElementsByTagName("A");for(var e=0;e<g.length;e++){var b=g[e].href;var d=b.match("#slide[0-9]{1,2}");if((d)&&(d[0].slice(0,1)=="#")){var c=findSlide(d[0].slice(1));if(c!=null){if(g[e].addEventListener){g[e].addEventListener("click",new Function("e","if (document.getElementById('slideProj').disabled) return;go("+c+" - snum); if (e.preventDefault) e.preventDefault();"),true)}else{if(g[e].attachEvent){g[e].attachEvent("onclick",new Function("","if (document.getElementById('slideProj').disabled) return;go("+c+" - snum); event.returnValue = false;"))}}}}}}function externalLinks(){if(!document.getElementsByTagName){return}var c=document.getElementsByTagName("a");for(var b=0;b<c.length;b++){var a=c[b];if(a.getAttribute("href")&&hasValue(a.rel,"external")){a.target="_blank";addClass(a,"external")}}}function createControls(){var e=document.getElementById("controls");if(!e){return}var c=" onmouseover=\"showHide('s');\" onmouseout=\"showHide('h');\"";var d,a="";if(controlVis=="hidden"){d=c}else{a=c}e.innerHTML='<form action="#" id="controlForm"'+d+'><div id="navLinks"><a accesskey="t" id="toggle" href="javascript:toggle();">&#216;</a><a accesskey="z" id="prev" href="javascript:go(-1);">&laquo;</a><a accesskey="x" id="next" href="javascript:go(1);">&raquo;</a><div id="navList"'+a+'><select id="jumplist" onchange="go(\'j\');"></select></div></div></form>';if(controlVis=="hidden"){var b=document.getElementById("navLinks")}else{var b=document.getElementById("jumplist")}addClass(b,"hideme")}function fontScale(){if(!s5mode){return false}var f=22;var a=32;if(window.innerHeight){var c=window.innerHeight;var e=window.innerWidth}else{if(document.documentElement.clientHeight){var c=document.documentElement.clientHeight;var e=document.documentElement.clientWidth}else{if(document.body.clientHeight){var c=document.body.clientHeight;var e=document.body.clientWidth}else{var c=700;var e=1024}}}var b=Math.min(Math.round(c/f),Math.round(e/a));fontSize(b+"px");if(isGe){var d=document.getElementsByTagName("body")[0];d.style.display="none";d.style.display="block"}}function fontSize(a){if(!(s5ss=document.getElementById("s5ss"))){if(!isIE){document.getElementsByTagName("head")[0].appendChild(s5ss=document.createElement("style"));s5ss.setAttribute("media","screen, projection");s5ss.setAttribute("id","s5ss")}else{document.createStyleSheet();document.s5ss=document.styleSheets[document.styleSheets.length-1]}}if(!isIE){while(s5ss.lastChild){s5ss.removeChild(s5ss.lastChild)}s5ss.appendChild(document.createTextNode("body {font-size: "+a+" !important;}"))}else{document.s5ss.addRule("body","font-size: "+a+" !important;")}}function notOperaFix(){slideCSS=document.getElementById("slideProj").href;var b=document.getElementById("slideProj");var a=document.getElementById("outlineStyle");b.setAttribute("media","screen");a.disabled=true;if(isGe){b.setAttribute("href","null");b.setAttribute("href",slideCSS)}if(isIE&&document.styleSheets&&document.styleSheets[0]){document.styleSheets[0].addRule("img","behavior: url(ui/default/iepngfix.htc)");document.styleSheets[0].addRule("div","behavior: url(ui/default/iepngfix.htc)");document.styleSheets[0].addRule(".slide","behavior: url(ui/default/iepngfix.htc)")}}function getIncrementals(e){var d=new Array();if(!e){return d}var c=e.childNodes;for(var b=0;b<c.length;b++){var f=c[b];if(hasClass(f,"incremental")){if(f.nodeName=="OL"||f.nodeName=="UL"){removeClass(f,"incremental");for(var a=0;a<f.childNodes.length;a++){if(f.childNodes[a].nodeType==1){addClass(f.childNodes[a],"incremental")}}}else{d[d.length]=f;removeClass(f,"incremental")}}if(hasClass(f,"show-first")){if(f.nodeName=="OL"||f.nodeName=="UL"){removeClass(f,"show-first");if(f.childNodes[isGe].nodeType==1){removeClass(f.childNodes[isGe],"incremental")}}else{d[d.length]=f}}d=d.concat(getIncrementals(f))}return d}function createIncrementals(){var b=new Array();for(var a=0;a<smax;a++){b[a]=getIncrementals(document.getElementById("slide"+a))}return b}function defaultCheck(){var a=document.getElementsByTagName("meta");for(var b=0;b<a.length;b++){if(a[b].name=="defaultView"){defaultView=a[b].content}if(a[b].name=="controlVis"){controlVis=a[b].content}}}function trap(a){if(!a){a=event;a.which=a.keyCode}try{modifierKey=a.ctrlKey||a.altKey||a.metaKey}catch(a){modifierKey=false}return modifierKey||a.which==0}function startup(){defaultCheck();if(!isOp){createControls()}slideLabel();fixLinks();externalLinks();fontScale();if(!isOp){notOperaFix();incrementals=createIncrementals();slideJump();if(defaultView=="outline"){toggle()}document.onkeyup=keys;document.onkeypress=trap;document.onclick=clicker}}window.onload=startup;window.onresize=function(){setTimeout("fontScale()",50)};
diff --git a/slidy/slidy.css b/slidy/slidy.css
new file mode 100644
--- /dev/null
+++ b/slidy/slidy.css
@@ -0,0 +1,401 @@
+/* slidy.css
+
+   Copyright (c) 2005-2010 W3C (MIT, ERCIM, Keio), All Rights Reserved.
+   W3C liability, trademark, document use and software licensing
+   rules apply, see:
+
+   http://www.w3.org/Consortium/Legal/copyright-documents
+   http://www.w3.org/Consortium/Legal/copyright-software
+*/
+body
+{
+  margin: 0 0 0 0;
+  padding: 0 0 0 0;
+  width: 100%;
+  height: 100%;
+  color: black;
+  background-color: white;
+  font-family: "Gill Sans MT", "Gill Sans", GillSans, sans-serif;
+  font-size: 14pt;
+}
+
+div.toolbar {
+  position: fixed; z-index: 200;
+  top: auto; bottom: 0; left: 0; right: 0;
+  height: 1.2em; text-align: right;
+  padding-left: 1em;
+  padding-right: 1em; 
+  font-size: 60%;
+  color: red;
+  background-color: rgb(240,240,240);
+  border-top: solid 1px rgb(180,180,180);
+}
+
+div.toolbar span.copyright {
+  color: black;
+  margin-left: 0.5em;
+}
+
+div.initial_prompt {
+  position: absolute;
+  z-index: 1000;
+  bottom: 1.2em;
+  width: 100%;
+  background-color: rgb(200,200,200);
+  opacity: 0.35;
+  background-color: rgb(200,200,200, 0.35);
+  cursor: pointer;
+}
+
+div.initial_prompt p.help {
+  text-align: center;
+}
+
+div.initial_prompt p.close {
+  text-align: right;
+  font-style: italic;
+}
+
+div.slidy_toc {
+  position: absolute;
+  z-index: 300;
+  width: 60%;
+  max-width: 30em;
+  height: 30em;
+  overflow: auto;
+  top: auto;
+  right: auto;
+  left: 4em;
+  bottom: 4em;
+  padding: 1em;
+  background: rgb(240,240,240);
+  border-style: solid;
+  border-width: 2px;
+  font-size: 60%;
+}
+
+div.slidy_toc .toc_heading {
+  text-align: center;
+  width: 100%;
+  margin: 0;
+  margin-bottom: 1em;
+  border-bottom-style: solid;
+  border-bottom-color: rgb(180,180,180);
+  border-bottom-width: 1px;
+}
+
+div.slide {
+  z-index: 20;
+  margin: 0 0 0 0;
+  padding-top: 0;
+  padding-bottom: 0;
+  padding-left: 20px;
+  padding-right: 20px;
+  border-width: 0;
+  clear: both;
+  top: 0;
+  bottom: 0;
+  left: 0;
+  right: 0;
+  line-height: 120%;
+  background-color: transparent;
+}
+
+div.background {
+  display: none;
+}
+
+div.handout {
+  margin-left: 20px;
+  margin-right: 20px;
+}
+
+div.slide.titlepage {
+  text-align: center;
+}
+
+div.slide.titlepage h1 {
+  padding-top: 10%;
+  margin-right: 0;
+}
+
+div.slide h1 {
+  padding-left: 0;
+  padding-right: 20pt;
+  padding-top: 4pt;
+  padding-bottom: 4pt;
+  margin-top: 0;
+  margin-left: 0;
+  margin-right: 60pt;
+  margin-bottom: 0.5em;
+  display: block; 
+  font-size: 160%;
+  line-height: 1.2em;
+  background: transparent;
+}
+
+div.toc {
+  position: absolute;
+  top: auto;
+  bottom: 4em;
+  left: 4em;
+  right: auto;
+  width: 60%;
+  max-width: 30em;
+  height: 30em;
+  border: solid thin black;
+  padding: 1em;
+  background: rgb(240,240,240);
+  color: black;
+  z-index: 300;
+  overflow: auto;
+  display: block;
+  visibility: visible;
+}
+
+div.toc-heading {
+  width: 100%;
+  border-bottom: solid 1px rgb(180,180,180);
+  margin-bottom: 1em;
+  text-align: center;
+}
+
+pre {
+ font-size: 80%;
+ font-weight: bold;
+ line-height: 120%;
+ padding-top: 0.2em;
+ padding-bottom: 0.2em;
+ padding-left: 1em;
+ padding-right: 1em;
+ border-style: solid;
+ border-left-width: 1em;
+ border-top-width: thin;
+ border-right-width: thin;
+ border-bottom-width: thin;
+ border-color: #95ABD0;
+ color: #00428C;
+ background-color: #E4E5E7;
+}
+
+li pre { margin-left: 0; }
+
+blockquote { font-style: italic }
+
+img { background-color: transparent }
+
+p.copyright { font-size: smaller }
+
+.center { text-align: center }
+.footnote { font-size: smaller; margin-left: 2em; }
+
+a img { border-width: 0; border-style: none }
+
+a:visited { color: navy }
+a:link { color: navy }
+a:hover { color: red; text-decoration: underline }
+a:active { color: red; text-decoration: underline }
+
+a {text-decoration: none}
+.navbar a:link {color: white}
+.navbar a:visited {color: yellow}
+.navbar a:active {color: red}
+.navbar a:hover {color: red}
+
+ul { list-style-type: square; }
+ul ul { list-style-type: disc; }
+ul ul ul { list-style-type: circle; }
+ul ul ul ul { list-style-type: disc; }
+li { margin-left: 0.5em; margin-top: 0.5em; }
+li li { font-size: 85%; font-style: italic }
+li li li { font-size: 85%; font-style: normal }
+
+div dt
+{
+  margin-left: 0;
+  margin-top: 1em;
+  margin-bottom: 0.5em;
+  font-weight: bold;
+}
+div dd
+{
+  margin-left: 2em;
+  margin-bottom: 0.5em;
+}
+
+
+p,pre,ul,ol,blockquote,h2,h3,h4,h5,h6,dl,table {
+  margin-left: 1em;
+  margin-right: 1em;
+}
+
+p.subhead { font-weight: bold; margin-top: 2em; }
+
+.smaller { font-size: smaller }
+.bigger { font-size: 130% }
+
+td,th { padding: 0.2em }
+
+ul {
+  margin: 0.5em 1.5em 0.5em 1.5em;
+  padding: 0;
+}
+
+ol {
+  margin: 0.5em 1.5em 0.5em 1.5em;
+  padding: 0;
+}
+
+ul { list-style-type: square; }
+ul ul { list-style-type: disc; }
+ul ul ul { list-style-type: circle; }
+ul ul ul ul { list-style-type: disc; }
+
+ul li { 
+  list-style: square;
+  margin: 0.1em 0em 0.6em 0;
+  padding: 0 0 0 0;
+  line-height: 140%;
+}
+
+ol li { 
+  margin: 0.1em 0em 0.6em 1.5em;
+  padding: 0 0 0 0px;
+  line-height: 140%;
+  list-style-type: decimal;
+}
+
+li ul li { 
+  font-size: 85%; 
+  font-style: italic;
+  list-style-type: disc;
+  background: transparent;
+  padding: 0 0 0 0;
+}
+li li ul li { 
+  font-size: 85%; 
+  font-style: normal;
+  list-style-type: circle;
+  background: transparent;
+  padding: 0 0 0 0;
+}
+li li li ul li {
+  list-style-type: disc;
+  background: transparent;
+  padding: 0 0 0 0;
+}
+
+li ol li {
+  list-style-type: decimal;
+}
+
+
+li li ol li {
+  list-style-type: decimal;
+}
+
+/*
+ setting class="outline on ol or ul makes it behave as an
+ ouline list where blocklevel content in li elements is
+ hidden by default and can be expanded or collapsed with
+ mouse click. Set class="expand" on li to override default
+*/
+
+ol.outline li:hover { cursor: pointer }
+ol.outline li.nofold:hover { cursor: default }
+
+ul.outline li:hover { cursor: pointer }
+ul.outline li.nofold:hover { cursor: default }
+
+ol.outline { list-style:decimal; }
+ol.outline ol { list-style-type:lower-alpha }
+
+ol.outline li.nofold {
+  padding: 0 0 0 20px;
+  background: transparent url(../graphics/nofold-dim.gif) no-repeat 0px 0.5em;
+}
+ol.outline li.unfolded {
+  padding: 0 0 0 20px;
+  background: transparent url(../graphics/fold-dim.gif) no-repeat 0px 0.5em;
+}
+ol.outline li.folded {
+  padding: 0 0 0 20px;
+  background: transparent url(../graphics/unfold-dim.gif) no-repeat 0px 0.5em;
+}
+ol.outline li.unfolded:hover {
+  padding: 0 0 0 20px;
+  background: transparent url(../graphics/fold.gif) no-repeat 0px 0.5em;
+}
+ol.outline li.folded:hover {
+  padding: 0 0 0 20px;
+  background: transparent url(../graphics/unfold.gif) no-repeat 0px 0.5em;
+}
+
+ul.outline li.nofold {
+  padding: 0 0 0 20px;
+  background: transparent url(../graphics/nofold-dim.gif) no-repeat 0px 0.5em;
+}
+ul.outline li.unfolded {
+  padding: 0 0 0 20px;
+  background: transparent url(../graphics/fold-dim.gif) no-repeat 0px 0.5em;
+}
+ul.outline li.folded {
+  padding: 0 0 0 20px;
+  background: transparent url(../graphics/unfold-dim.gif) no-repeat 0px 0.5em;
+}
+ul.outline li.unfolded:hover {
+  padding: 0 0 0 20px;
+  background: transparent url(../graphics/fold.gif) no-repeat 0px 0.5em;
+}
+ul.outline li.folded:hover {
+  padding: 0 0 0 20px;
+  background: transparent url(../graphics/unfold.gif) no-repeat 0px 0.5em;
+}
+
+/* for slides with class "title" in table of contents */
+a.titleslide { font-weight: bold; font-style: italic }
+
+/*
+ hide images for work around for save as bug
+ where browsers fail to save images used by CSS
+*/
+img.hidden { display: none; visibility: hidden }
+div.initial_prompt { display: none; visibility: hidden }
+
+  div.slide {
+     visibility: visible;
+     position: inherit;
+  }
+  div.handout {
+     border-top-style: solid;
+     border-top-width: thin;
+     border-top-color: black;
+  }
+
+@media screen {
+  .hidden { display: none; visibility: visible }
+
+  div.slide.hidden { display: block; visibility: visible }
+  div.handout.hidden { display: block; visibility: visible }
+  div.background { display: none; visibility: hidden }
+  body.single_slide div.initial_prompt { display: block; visibility: visible }
+  body.single_slide div.background { display: block; visibility: visible }
+  body.single_slide div.background.hidden { display: none; visibility: hidden }
+  body.single_slide .invisible { visibility: hidden }
+  body.single_slide .hidden { display: none; visibility: hidden }
+  body.single_slide div.slide { position: absolute }
+  body.single_slide div.handout { display: none; visibility: hidden }
+}
+
+@media print {
+  .hidden { display: block; visibility: visible }
+
+  div.slide pre { font-size: 60%; padding-left: 0.5em; }
+  div.toolbar { display: none; visibility: hidden; }
+  div.slidy_toc { display: none; visibility: hidden; }
+  div.background { display: none; visibility: hidden; }
+  div.slide { page-break-before: always }
+  /* :first-child isn't reliable for print media */
+  div.slide.first-slide { page-break-before: avoid }
+}
+
diff --git a/slidy/slidy.min.css b/slidy/slidy.min.css
deleted file mode 100644
--- a/slidy/slidy.min.css
+++ /dev/null
@@ -1,1 +0,0 @@
-body{margin:0;padding:0;width:100%;height:100%;color:black;background-color:white;font-family:"Gill Sans MT","Gill Sans",GillSans,sans-serif;font-size:14pt}div.toolbar{position:fixed;z-index:200;top:auto;bottom:0;left:0;right:0;height:1.2em;text-align:right;padding-left:1em;padding-right:1em;font-size:60%;color:red;background-color:#f0f0f0;border-top:solid 1px #b4b4b4}div.toolbar span.copyright{color:black;margin-left:.5em}div.initial_prompt{position:absolute;z-index:1000;bottom:1.2em;width:100%;background-color:#c8c8c8;opacity:.35;background-color:rgb(200,200,200,0.35);cursor:pointer}div.initial_prompt p.help{text-align:center}div.initial_prompt p.close{text-align:right;font-style:italic}div.slidy_toc{position:absolute;z-index:300;width:60%;max-width:30em;height:30em;overflow:auto;top:auto;right:auto;left:4em;bottom:4em;padding:1em;background:#f0f0f0;border-style:solid;border-width:2px;font-size:60%}div.slidy_toc .toc_heading{text-align:center;width:100%;margin:0;margin-bottom:1em;border-bottom-style:solid;border-bottom-color:#b4b4b4;border-bottom-width:1px}div.slide{z-index:20;margin:0;padding-top:0;padding-bottom:0;padding-left:20px;padding-right:20px;border-width:0;clear:both;top:0;bottom:0;left:0;right:0;line-height:120%;background-color:transparent}div.background{display:none}div.handout{margin-left:20px;margin-right:20px}div.slide.titlepage{text-align:center}div.slide.titlepage.h1{padding-top:10%}div.slide h1{padding-left:0;padding-right:20pt;padding-top:4pt;padding-bottom:4pt;margin-top:0;margin-left:0;margin-right:60pt;margin-bottom:.5em;display:block;font-size:160%;line-height:1.2em;background:transparent}div.toc{position:absolute;top:auto;bottom:4em;left:4em;right:auto;width:60%;max-width:30em;height:30em;border:solid thin black;padding:1em;background:#f0f0f0;color:black;z-index:300;overflow:auto;display:block;visibility:visible}div.toc-heading{width:100%;border-bottom:solid 1px #b4b4b4;margin-bottom:1em;text-align:center}pre{font-size:80%;font-weight:bold;line-height:120%;padding-top:.2em;padding-bottom:.2em;padding-left:1em;padding-right:1em;border-style:solid;border-left-width:1em;border-top-width:thin;border-right-width:thin;border-bottom-width:thin;border-color:#95abd0;color:#00428c;background-color:#e4e5e7}li pre{margin-left:0}blockquote{font-style:italic}img{background-color:transparent}p.copyright{font-size:smaller}.center{text-align:center}.footnote{font-size:smaller;margin-left:2em}a img{border-width:0;border-style:none}a:visited{color:navy}a:link{color:navy}a:hover{color:red;text-decoration:underline}a:active{color:red;text-decoration:underline}a{text-decoration:none}.navbar a:link{color:white}.navbar a:visited{color:yellow}.navbar a:active{color:red}.navbar a:hover{color:red}ul{list-style-type:square}ul ul{list-style-type:disc}ul ul ul{list-style-type:circle}ul ul ul ul{list-style-type:disc}li{margin-left:.5em;margin-top:.5em}li li{font-size:85%;font-style:italic}li li li{font-size:85%;font-style:normal}div dt{margin-left:0;margin-top:1em;margin-bottom:.5em;font-weight:bold}div dd{margin-left:2em;margin-bottom:.5em}p,pre,ul,ol,blockquote,h2,h3,h4,h5,h6,dl,table{margin-left:1em;margin-right:1em}p.subhead{font-weight:bold;margin-top:2em}.smaller{font-size:smaller}.bigger{font-size:130%}td,th{padding:.2em}ul{margin:.5em 1.5em .5em 1.5em;padding:0}ol{margin:.5em 1.5em .5em 1.5em;padding:0}ul{list-style-type:square}ul ul{list-style-type:disc}ul ul ul{list-style-type:circle}ul ul ul ul{list-style-type:disc}ul li{list-style:square;margin:.1em 0 .6em 0;padding:0;line-height:140%}ol li{margin:.1em 0 .6em 1.5em;padding:0;line-height:140%;list-style-type:decimal}li ul li{font-size:85%;font-style:italic;list-style-type:disc;background:transparent;padding:0}li li ul li{font-size:85%;font-style:normal;list-style-type:circle;background:transparent;padding:0}li li li ul li{list-style-type:disc;background:transparent;padding:0}li ol li{list-style-type:decimal}li li ol li{list-style-type:decimal}ol.outline li:hover{cursor:pointer}ol.outline li.nofold:hover{cursor:default}ul.outline li:hover{cursor:pointer}ul.outline li.nofold:hover{cursor:default}ol.outline{list-style:decimal}ol.outline ol{list-style-type:lower-alpha}ol.outline li.nofold{padding:0 0 0 20px;background:transparent url(../graphics/nofold-dim.gif) no-repeat 0 .5em}ol.outline li.unfolded{padding:0 0 0 20px;background:transparent url(../graphics/fold-dim.gif) no-repeat 0 .5em}ol.outline li.folded{padding:0 0 0 20px;background:transparent url(../graphics/unfold-dim.gif) no-repeat 0 .5em}ol.outline li.unfolded:hover{padding:0 0 0 20px;background:transparent url(../graphics/fold.gif) no-repeat 0 .5em}ol.outline li.folded:hover{padding:0 0 0 20px;background:transparent url(../graphics/unfold.gif) no-repeat 0 .5em}ul.outline li.nofold{padding:0 0 0 20px;background:transparent url(../graphics/nofold-dim.gif) no-repeat 0 .5em}ul.outline li.unfolded{padding:0 0 0 20px;background:transparent url(../graphics/fold-dim.gif) no-repeat 0 .5em}ul.outline li.folded{padding:0 0 0 20px;background:transparent url(../graphics/unfold-dim.gif) no-repeat 0 .5em}ul.outline li.unfolded:hover{padding:0 0 0 20px;background:transparent url(../graphics/fold.gif) no-repeat 0 .5em}ul.outline li.folded:hover{padding:0 0 0 20px;background:transparent url(../graphics/unfold.gif) no-repeat 0 .5em}a.titleslide{font-weight:bold;font-style:italic}img.hidden{display:none;visibility:hidden}div.initial_prompt{display:none;visibility:hidden}div.slide{visibility:visible;position:inherit}div.handout{border-top-style:solid;border-top-width:thin;border-top-color:black}@media screen{.hidden{display:none;visibility:visible}div.slide.hidden{display:block;visibility:visible}div.handout.hidden{display:block;visibility:visible}div.background{display:none;visibility:hidden}body.single_slide div.initial_prompt{display:block;visibility:visible}body.single_slide div.background{display:block;visibility:visible}body.single_slide div.background.hidden{display:none;visibility:hidden}body.single_slide .invisible{visibility:hidden}body.single_slide .hidden{display:none;visibility:hidden}body.single_slide div.slide{position:absolute}body.single_slide div.handout{display:none;visibility:hidden}}@media print{.hidden{display:block;visibility:visible}div.slide pre{font-size:60%;padding-left:.5em}div.toolbar{display:none;visibility:hidden}div.slidy_toc{display:none;visibility:hidden}div.background{display:none;visibility:hidden}div.slide{page-break-before:always}div.slide.first-slide{page-break-before:avoid}}
diff --git a/src/Tests/Readers/Markdown.hs b/src/Tests/Readers/Markdown.hs
--- a/src/Tests/Readers/Markdown.hs
+++ b/src/Tests/Readers/Markdown.hs
@@ -8,10 +8,14 @@
 import Text.Pandoc.Builder
 -- import Text.Pandoc.Shared ( normalize )
 import Text.Pandoc
+import Data.Sequence (singleton)
 
 markdown :: String -> Pandoc
 markdown = readMarkdown defaultParserState{ stateStandalone = True }
 
+markdownSmart :: String -> Pandoc
+markdownSmart = readMarkdown defaultParserState{ stateSmart = True }
+
 infix 5 =:
 (=:) :: ToString c
      => String -> (String, c) -> Test
@@ -39,6 +43,11 @@
           , "with attribute space" =:
             "`*` {.haskell .special x=\"7\"}"
             =?> para (codeWith ("",["haskell","special"],[("x","7")]) "*")
+          ]
+        , testGroup "smart punctuation"
+          [ test markdownSmart "quote before ellipses"
+            ("'...hi'"
+            =?> para (singleQuoted (singleton Ellipses +++ "hi")))
           ]
         , testGroup "mixed emphasis and strong"
           [ "emph and strong emph alternating" =:
diff --git a/src/Tests/Writers/Markdown.hs b/src/Tests/Writers/Markdown.hs
new file mode 100644
--- /dev/null
+++ b/src/Tests/Writers/Markdown.hs
@@ -0,0 +1,34 @@
+{-# LANGUAGE OverloadedStrings, QuasiQuotes #-}
+module Tests.Writers.Markdown (tests) where
+
+import Test.Framework
+import Text.Pandoc.Builder
+import Text.Pandoc
+import Tests.Helpers
+import Tests.Arbitrary()
+
+markdown :: (ToString a, ToPandoc a) => a -> String
+markdown = writeMarkdown defaultWriterOptions . toPandoc
+
+{-
+  "my test" =: X =?> Y
+
+is shorthand for
+
+  test markdown "my test" $ X =?> Y
+
+which is in turn shorthand for
+
+  test markdown "my test" (X,Y)
+-}
+
+infix 5 =:
+(=:) :: (ToString a, ToPandoc a)
+     => String -> (a, String) -> Test
+(=:) = test markdown
+
+tests :: [Test]
+tests = [ "indented code after list"
+             =: (orderedList [ para "one" +++ para "two" ] +++ codeBlock "test")
+             =?> "1.  one\n\n    two\n\n<!-- -->\n\n    test"
+        ]
diff --git a/src/Text/Pandoc/MIME.hs b/src/Text/Pandoc/MIME.hs
new file mode 100644
--- /dev/null
+++ b/src/Text/Pandoc/MIME.hs
@@ -0,0 +1,483 @@
+{-
+Copyright (C) 2011 John MacFarlane <jgm@berkeley.edu>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+-}
+
+{- |
+   Module      : Text.Pandoc.MIME
+   Copyright   : Copyright (C) 2011 John MacFarlane
+   License     : GNU GPL, version 2 or above 
+
+   Maintainer  : John MacFarlane <jgm@berkeley.edu>
+   Stability   : alpha
+   Portability : portable
+
+Mime type lookup for ODT writer.
+-}
+module Text.Pandoc.MIME ( getMimeType )
+where
+import System.FilePath
+import Data.Char ( toLower )
+import qualified Data.Map as M
+
+-- | Determine mime type appropriate for file path.
+getMimeType :: FilePath -> Maybe String
+getMimeType f = M.lookup (map toLower $ drop 1 $ takeExtension f) mimeTypes
+  where mimeTypes = M.fromList -- List borrowed from happstack-server.
+           [("gz","application/x-gzip")
+           ,("cabal","application/x-cabal")
+           ,("%","application/x-trash")
+           ,("323","text/h323")
+           ,("3gp","video/3gpp")
+           ,("7z","application/x-7z-compressed")
+           ,("abw","application/x-abiword")
+           ,("ai","application/postscript")
+           ,("aif","audio/x-aiff")
+           ,("aifc","audio/x-aiff")
+           ,("aiff","audio/x-aiff")
+           ,("alc","chemical/x-alchemy")
+           ,("art","image/x-jg")
+           ,("asc","text/plain")
+           ,("asf","video/x-ms-asf")
+           ,("asn","chemical/x-ncbi-asn1")
+           ,("aso","chemical/x-ncbi-asn1-binary")
+           ,("asx","video/x-ms-asf")
+           ,("atom","application/atom")
+           ,("atomcat","application/atomcat+xml")
+           ,("atomsrv","application/atomserv+xml")
+           ,("au","audio/basic")
+           ,("avi","video/x-msvideo")
+           ,("b","chemical/x-molconn-Z")
+           ,("bak","application/x-trash")
+           ,("bat","application/x-msdos-program")
+           ,("bcpio","application/x-bcpio")
+           ,("bib","text/x-bibtex")
+           ,("bin","application/octet-stream")
+           ,("bmp","image/x-ms-bmp")
+           ,("boo","text/x-boo")
+           ,("book","application/x-maker")
+           ,("bsd","chemical/x-crossfire")
+           ,("c","text/x-csrc")
+           ,("c++","text/x-c++src")
+           ,("c3d","chemical/x-chem3d")
+           ,("cab","application/x-cab")
+           ,("cac","chemical/x-cache")
+           ,("cache","chemical/x-cache")
+           ,("cap","application/cap")
+           ,("cascii","chemical/x-cactvs-binary")
+           ,("cat","application/vnd.ms-pki.seccat")
+           ,("cbin","chemical/x-cactvs-binary")
+           ,("cbr","application/x-cbr")
+           ,("cbz","application/x-cbz")
+           ,("cc","text/x-c++src")
+           ,("cdf","application/x-cdf")
+           ,("cdr","image/x-coreldraw")
+           ,("cdt","image/x-coreldrawtemplate")
+           ,("cdx","chemical/x-cdx")
+           ,("cdy","application/vnd.cinderella")
+           ,("cef","chemical/x-cxf")
+           ,("cer","chemical/x-cerius")
+           ,("chm","chemical/x-chemdraw")
+           ,("chrt","application/x-kchart")
+           ,("cif","chemical/x-cif")
+           ,("class","application/java-vm")
+           ,("cls","text/x-tex")
+           ,("cmdf","chemical/x-cmdf")
+           ,("cml","chemical/x-cml")
+           ,("cod","application/vnd.rim.cod")
+           ,("com","application/x-msdos-program")
+           ,("cpa","chemical/x-compass")
+           ,("cpio","application/x-cpio")
+           ,("cpp","text/x-c++src")
+           ,("cpt","application/mac-compactpro")
+           ,("crl","application/x-pkcs7-crl")
+           ,("crt","application/x-x509-ca-cert")
+           ,("csf","chemical/x-cache-csf")
+           ,("csh","application/x-csh")
+           ,("csm","chemical/x-csml")
+           ,("csml","chemical/x-csml")
+           ,("css","text/css")
+           ,("csv","text/csv")
+           ,("ctab","chemical/x-cactvs-binary")
+           ,("ctx","chemical/x-ctx")
+           ,("cu","application/cu-seeme")
+           ,("cub","chemical/x-gaussian-cube")
+           ,("cxf","chemical/x-cxf")
+           ,("cxx","text/x-c++src")
+           ,("d","text/x-dsrc")
+           ,("dat","chemical/x-mopac-input")
+           ,("dcr","application/x-director")
+           ,("deb","application/x-debian-package")
+           ,("dif","video/dv")
+           ,("diff","text/x-diff")
+           ,("dir","application/x-director")
+           ,("djv","image/vnd.djvu")
+           ,("djvu","image/vnd.djvu")
+           ,("dl","video/dl")
+           ,("dll","application/x-msdos-program")
+           ,("dmg","application/x-apple-diskimage")
+           ,("dms","application/x-dms")
+           ,("doc","application/msword")
+           ,("dot","application/msword")
+           ,("dv","video/dv")
+           ,("dvi","application/x-dvi")
+           ,("dx","chemical/x-jcamp-dx")
+           ,("dxr","application/x-director")
+           ,("emb","chemical/x-embl-dl-nucleotide")
+           ,("embl","chemical/x-embl-dl-nucleotide")
+           ,("eml","message/rfc822")
+           ,("ent","chemical/x-ncbi-asn1-ascii")
+           ,("eps","application/postscript")
+           ,("etx","text/x-setext")
+           ,("exe","application/x-msdos-program")
+           ,("ez","application/andrew-inset")
+           ,("fb","application/x-maker")
+           ,("fbdoc","application/x-maker")
+           ,("fch","chemical/x-gaussian-checkpoint")
+           ,("fchk","chemical/x-gaussian-checkpoint")
+           ,("fig","application/x-xfig")
+           ,("flac","application/x-flac")
+           ,("fli","video/fli")
+           ,("fm","application/x-maker")
+           ,("frame","application/x-maker")
+           ,("frm","application/x-maker")
+           ,("gal","chemical/x-gaussian-log")
+           ,("gam","chemical/x-gamess-input")
+           ,("gamin","chemical/x-gamess-input")
+           ,("gau","chemical/x-gaussian-input")
+           ,("gcd","text/x-pcs-gcd")
+           ,("gcf","application/x-graphing-calculator")
+           ,("gcg","chemical/x-gcg8-sequence")
+           ,("gen","chemical/x-genbank")
+           ,("gf","application/x-tex-gf")
+           ,("gif","image/gif")
+           ,("gjc","chemical/x-gaussian-input")
+           ,("gjf","chemical/x-gaussian-input")
+           ,("gl","video/gl")
+           ,("gnumeric","application/x-gnumeric")
+           ,("gpt","chemical/x-mopac-graph")
+           ,("gsf","application/x-font")
+           ,("gsm","audio/x-gsm")
+           ,("gtar","application/x-gtar")
+           ,("h","text/x-chdr")
+           ,("h++","text/x-c++hdr")
+           ,("hdf","application/x-hdf")
+           ,("hh","text/x-c++hdr")
+           ,("hin","chemical/x-hin")
+           ,("hpp","text/x-c++hdr")
+           ,("hqx","application/mac-binhex40")
+           ,("hs","text/x-haskell")
+           ,("hta","application/hta")
+           ,("htc","text/x-component")
+           ,("htm","text/html")
+           ,("html","text/html")
+           ,("hxx","text/x-c++hdr")
+           ,("ica","application/x-ica")
+           ,("ice","x-conference/x-cooltalk")
+           ,("ico","image/x-icon")
+           ,("ics","text/calendar")
+           ,("icz","text/calendar")
+           ,("ief","image/ief")
+           ,("iges","model/iges")
+           ,("igs","model/iges")
+           ,("iii","application/x-iphone")
+           ,("inp","chemical/x-gamess-input")
+           ,("ins","application/x-internet-signup")
+           ,("iso","application/x-iso9660-image")
+           ,("isp","application/x-internet-signup")
+           ,("ist","chemical/x-isostar")
+           ,("istr","chemical/x-isostar")
+           ,("jad","text/vnd.sun.j2me.app-descriptor")
+           ,("jar","application/java-archive")
+           ,("java","text/x-java")
+           ,("jdx","chemical/x-jcamp-dx")
+           ,("jmz","application/x-jmol")
+           ,("jng","image/x-jng")
+           ,("jnlp","application/x-java-jnlp-file")
+           ,("jpe","image/jpeg")
+           ,("jpeg","image/jpeg")
+           ,("jpg","image/jpeg")
+           ,("js","application/x-javascript")
+           ,("kar","audio/midi")
+           ,("key","application/pgp-keys")
+           ,("kil","application/x-killustrator")
+           ,("kin","chemical/x-kinemage")
+           ,("kml","application/vnd.google-earth.kml+xml")
+           ,("kmz","application/vnd.google-earth.kmz")
+           ,("kpr","application/x-kpresenter")
+           ,("kpt","application/x-kpresenter")
+           ,("ksp","application/x-kspread")
+           ,("kwd","application/x-kword")
+           ,("kwt","application/x-kword")
+           ,("latex","application/x-latex")
+           ,("lha","application/x-lha")
+           ,("lhs","text/x-literate-haskell")
+           ,("lsf","video/x-la-asf")
+           ,("lsx","video/x-la-asf")
+           ,("ltx","text/x-tex")
+           ,("lyx","application/x-lyx")
+           ,("lzh","application/x-lzh")
+           ,("lzx","application/x-lzx")
+           ,("m3u","audio/mpegurl")
+           ,("m4a","audio/mpeg")
+           ,("maker","application/x-maker")
+           ,("man","application/x-troff-man")
+           ,("mcif","chemical/x-mmcif")
+           ,("mcm","chemical/x-macmolecule")
+           ,("mdb","application/msaccess")
+           ,("me","application/x-troff-me")
+           ,("mesh","model/mesh")
+           ,("mid","audio/midi")
+           ,("midi","audio/midi")
+           ,("mif","application/x-mif")
+           ,("mm","application/x-freemind")
+           ,("mmd","chemical/x-macromodel-input")
+           ,("mmf","application/vnd.smaf")
+           ,("mml","text/mathml")
+           ,("mmod","chemical/x-macromodel-input")
+           ,("mng","video/x-mng")
+           ,("moc","text/x-moc")
+           ,("mol","chemical/x-mdl-molfile")
+           ,("mol2","chemical/x-mol2")
+           ,("moo","chemical/x-mopac-out")
+           ,("mop","chemical/x-mopac-input")
+           ,("mopcrt","chemical/x-mopac-input")
+           ,("mov","video/quicktime")
+           ,("movie","video/x-sgi-movie")
+           ,("mp2","audio/mpeg")
+           ,("mp3","audio/mpeg")
+           ,("mp4","video/mp4")
+           ,("mpc","chemical/x-mopac-input")
+           ,("mpe","video/mpeg")
+           ,("mpeg","video/mpeg")
+           ,("mpega","audio/mpeg")
+           ,("mpg","video/mpeg")
+           ,("mpga","audio/mpeg")
+           ,("ms","application/x-troff-ms")
+           ,("msh","model/mesh")
+           ,("msi","application/x-msi")
+           ,("mvb","chemical/x-mopac-vib")
+           ,("mxu","video/vnd.mpegurl")
+           ,("nb","application/mathematica")
+           ,("nc","application/x-netcdf")
+           ,("nwc","application/x-nwc")
+           ,("o","application/x-object")
+           ,("oda","application/oda")
+           ,("odb","application/vnd.oasis.opendocument.database")
+           ,("odc","application/vnd.oasis.opendocument.chart")
+           ,("odf","application/vnd.oasis.opendocument.formula")
+           ,("odg","application/vnd.oasis.opendocument.graphics")
+           ,("odi","application/vnd.oasis.opendocument.image")
+           ,("odm","application/vnd.oasis.opendocument.text-master")
+           ,("odp","application/vnd.oasis.opendocument.presentation")
+           ,("ods","application/vnd.oasis.opendocument.spreadsheet")
+           ,("odt","application/vnd.oasis.opendocument.text")
+           ,("oga","audio/ogg")
+           ,("ogg","application/ogg")
+           ,("ogv","video/ogg")
+           ,("ogx","application/ogg")
+           ,("old","application/x-trash")
+           ,("otg","application/vnd.oasis.opendocument.graphics-template")
+           ,("oth","application/vnd.oasis.opendocument.text-web")
+           ,("otp","application/vnd.oasis.opendocument.presentation-template")
+           ,("ots","application/vnd.oasis.opendocument.spreadsheet-template")
+           ,("ott","application/vnd.oasis.opendocument.text-template")
+           ,("oza","application/x-oz-application")
+           ,("p","text/x-pascal")
+           ,("p7r","application/x-pkcs7-certreqresp")
+           ,("pac","application/x-ns-proxy-autoconfig")
+           ,("pas","text/x-pascal")
+           ,("pat","image/x-coreldrawpattern")
+           ,("patch","text/x-diff")
+           ,("pbm","image/x-portable-bitmap")
+           ,("pcap","application/cap")
+           ,("pcf","application/x-font")
+           ,("pcf.Z","application/x-font")
+           ,("pcx","image/pcx")
+           ,("pdb","chemical/x-pdb")
+           ,("pdf","application/pdf")
+           ,("pfa","application/x-font")
+           ,("pfb","application/x-font")
+           ,("pgm","image/x-portable-graymap")
+           ,("pgn","application/x-chess-pgn")
+           ,("pgp","application/pgp-signature")
+           ,("php","application/x-httpd-php")
+           ,("php3","application/x-httpd-php3")
+           ,("php3p","application/x-httpd-php3-preprocessed")
+           ,("php4","application/x-httpd-php4")
+           ,("phps","application/x-httpd-php-source")
+           ,("pht","application/x-httpd-php")
+           ,("phtml","application/x-httpd-php")
+           ,("pk","application/x-tex-pk")
+           ,("pl","text/x-perl")
+           ,("pls","audio/x-scpls")
+           ,("pm","text/x-perl")
+           ,("png","image/png")
+           ,("pnm","image/x-portable-anymap")
+           ,("pot","text/plain")
+           ,("ppm","image/x-portable-pixmap")
+           ,("pps","application/vnd.ms-powerpoint")
+           ,("ppt","application/vnd.ms-powerpoint")
+           ,("prf","application/pics-rules")
+           ,("prt","chemical/x-ncbi-asn1-ascii")
+           ,("ps","application/postscript")
+           ,("psd","image/x-photoshop")
+           ,("py","text/x-python")
+           ,("pyc","application/x-python-code")
+           ,("pyo","application/x-python-code")
+           ,("qt","video/quicktime")
+           ,("qtl","application/x-quicktimeplayer")
+           ,("ra","audio/x-pn-realaudio")
+           ,("ram","audio/x-pn-realaudio")
+           ,("rar","application/rar")
+           ,("ras","image/x-cmu-raster")
+           ,("rd","chemical/x-mdl-rdfile")
+           ,("rdf","application/rdf+xml")
+           ,("rgb","image/x-rgb")
+           ,("rhtml","application/x-httpd-eruby")
+           ,("rm","audio/x-pn-realaudio")
+           ,("roff","application/x-troff")
+           ,("ros","chemical/x-rosdal")
+           ,("rpm","application/x-redhat-package-manager")
+           ,("rss","application/rss+xml")
+           ,("rtf","application/rtf")
+           ,("rtx","text/richtext")
+           ,("rxn","chemical/x-mdl-rxnfile")
+           ,("sct","text/scriptlet")
+           ,("sd","chemical/x-mdl-sdfile")
+           ,("sd2","audio/x-sd2")
+           ,("sda","application/vnd.stardivision.draw")
+           ,("sdc","application/vnd.stardivision.calc")
+           ,("sdd","application/vnd.stardivision.impress")
+           ,("sdf","application/vnd.stardivision.math")
+           ,("sds","application/vnd.stardivision.chart")
+           ,("sdw","application/vnd.stardivision.writer")
+           ,("ser","application/java-serialized-object")
+           ,("sgf","application/x-go-sgf")
+           ,("sgl","application/vnd.stardivision.writer-global")
+           ,("sh","application/x-sh")
+           ,("shar","application/x-shar")
+           ,("shtml","text/html")
+           ,("sid","audio/prs.sid")
+           ,("sik","application/x-trash")
+           ,("silo","model/mesh")
+           ,("sis","application/vnd.symbian.install")
+           ,("sisx","x-epoc/x-sisx-app")
+           ,("sit","application/x-stuffit")
+           ,("sitx","application/x-stuffit")
+           ,("skd","application/x-koan")
+           ,("skm","application/x-koan")
+           ,("skp","application/x-koan")
+           ,("skt","application/x-koan")
+           ,("smi","application/smil")
+           ,("smil","application/smil")
+           ,("snd","audio/basic")
+           ,("spc","chemical/x-galactic-spc")
+           ,("spl","application/futuresplash")
+           ,("spx","audio/ogg")
+           ,("src","application/x-wais-source")
+           ,("stc","application/vnd.sun.xml.calc.template")
+           ,("std","application/vnd.sun.xml.draw.template")
+           ,("sti","application/vnd.sun.xml.impress.template")
+           ,("stl","application/vnd.ms-pki.stl")
+           ,("stw","application/vnd.sun.xml.writer.template")
+           ,("sty","text/x-tex")
+           ,("sv4cpio","application/x-sv4cpio")
+           ,("sv4crc","application/x-sv4crc")
+           ,("svg","image/svg+xml")
+           ,("svgz","image/svg+xml")
+           ,("sw","chemical/x-swissprot")
+           ,("swf","application/x-shockwave-flash")
+           ,("swfl","application/x-shockwave-flash")
+           ,("sxc","application/vnd.sun.xml.calc")
+           ,("sxd","application/vnd.sun.xml.draw")
+           ,("sxg","application/vnd.sun.xml.writer.global")
+           ,("sxi","application/vnd.sun.xml.impress")
+           ,("sxm","application/vnd.sun.xml.math")
+           ,("sxw","application/vnd.sun.xml.writer")
+           ,("t","application/x-troff")
+           ,("tar","application/x-tar")
+           ,("taz","application/x-gtar")
+           ,("tcl","application/x-tcl")
+           ,("tex","text/x-tex")
+           ,("texi","application/x-texinfo")
+           ,("texinfo","application/x-texinfo")
+           ,("text","text/plain")
+           ,("tgf","chemical/x-mdl-tgf")
+           ,("tgz","application/x-gtar")
+           ,("tif","image/tiff")
+           ,("tiff","image/tiff")
+           ,("tk","text/x-tcl")
+           ,("tm","text/texmacs")
+           ,("torrent","application/x-bittorrent")
+           ,("tr","application/x-troff")
+           ,("ts","text/texmacs")
+           ,("tsp","application/dsptype")
+           ,("tsv","text/tab-separated-values")
+           ,("txt","text/plain")
+           ,("udeb","application/x-debian-package")
+           ,("uls","text/iuls")
+           ,("ustar","application/x-ustar")
+           ,("val","chemical/x-ncbi-asn1-binary")
+           ,("vcd","application/x-cdlink")
+           ,("vcf","text/x-vcard")
+           ,("vcs","text/x-vcalendar")
+           ,("vmd","chemical/x-vmd")
+           ,("vms","chemical/x-vamas-iso14976")
+           ,("vrm","x-world/x-vrml")
+           ,("vrml","model/vrml")
+           ,("vsd","application/vnd.visio")
+           ,("wad","application/x-doom")
+           ,("wav","audio/x-wav")
+           ,("wax","audio/x-ms-wax")
+           ,("wbmp","image/vnd.wap.wbmp")
+           ,("wbxml","application/vnd.wap.wbxml")
+           ,("wk","application/x-123")
+           ,("wm","video/x-ms-wm")
+           ,("wma","audio/x-ms-wma")
+           ,("wmd","application/x-ms-wmd")
+           ,("wml","text/vnd.wap.wml")
+           ,("wmlc","application/vnd.wap.wmlc")
+           ,("wmls","text/vnd.wap.wmlscript")
+           ,("wmlsc","application/vnd.wap.wmlscriptc")
+           ,("wmv","video/x-ms-wmv")
+           ,("wmx","video/x-ms-wmx")
+           ,("wmz","application/x-ms-wmz")
+           ,("wp5","application/wordperfect5.1")
+           ,("wpd","application/wordperfect")
+           ,("wrl","model/vrml")
+           ,("wsc","text/scriptlet")
+           ,("wvx","video/x-ms-wvx")
+           ,("wz","application/x-wingz")
+           ,("xbm","image/x-xbitmap")
+           ,("xcf","application/x-xcf")
+           ,("xht","application/xhtml+xml")
+           ,("xhtml","application/xhtml+xml")
+           ,("xlb","application/vnd.ms-excel")
+           ,("xls","application/vnd.ms-excel")
+           ,("xlt","application/vnd.ms-excel")
+           ,("xml","application/xml")
+           ,("xpi","application/x-xpinstall")
+           ,("xpm","image/x-xpixmap")
+           ,("xsl","application/xml")
+           ,("xtel","chemical/x-xtel")
+           ,("xul","application/vnd.mozilla.xul+xml")
+           ,("xwd","image/x-xwindowdump")
+           ,("xyz","chemical/x-xyz")
+           ,("zip","application/zip")
+           ,("zmt","chemical/x-mopac-input")
+           ]
+
diff --git a/src/Text/Pandoc/Parsing.hs b/src/Text/Pandoc/Parsing.hs
--- a/src/Text/Pandoc/Parsing.hs
+++ b/src/Text/Pandoc/Parsing.hs
@@ -33,6 +33,7 @@
                              notFollowedBy',
                              oneOfStrings,
                              spaceChar,
+                             nonspaceChar,
                              skipSpaces,
                              blankline,
                              blanklines,
@@ -122,6 +123,10 @@
 spaceChar :: CharParser st Char
 spaceChar = satisfy $ \c -> c == ' ' || c == '\t'
 
+-- | Parses a nonspace, nonnewline character.
+nonspaceChar :: CharParser st Char
+nonspaceChar = satisfy $ \x -> x /= '\t' && x /= '\n' && x /= ' ' && x /= '\r'
+
 -- | Skips zero or more spaces or tabs.
 skipSpaces :: GenParser Char st ()
 skipSpaces = skipMany spaceChar
@@ -758,8 +763,9 @@
 singleQuoteStart :: GenParser Char ParserState ()
 singleQuoteStart = do 
   failIfInQuoteContext InSingleQuote
-  try $ do charOrRef "'\8216"
-           notFollowedBy (oneOf ")!],.;:-? \t\n")
+  try $ do charOrRef "'\8216\145"
+           notFollowedBy (oneOf ")!],;:-? \t\n")
+           notFollowedBy (char '.') <|> lookAhead (string "..." >> return ())
            notFollowedBy (try (oneOfStrings ["s","t","m","ve","ll","re"] >>
                                satisfy (not . isAlphaNum))) 
                                -- possess/contraction
@@ -767,23 +773,23 @@
 
 singleQuoteEnd :: GenParser Char st ()
 singleQuoteEnd = try $ do
-  charOrRef "'\8217"
+  charOrRef "'\8217\146"
   notFollowedBy alphaNum
 
 doubleQuoteStart :: GenParser Char ParserState ()
 doubleQuoteStart = do
   failIfInQuoteContext InDoubleQuote
-  try $ do charOrRef "\"\8220"
+  try $ do charOrRef "\"\8220\147"
            notFollowedBy (satisfy (\c -> c == ' ' || c == '\t' || c == '\n'))
 
 doubleQuoteEnd :: GenParser Char st ()
 doubleQuoteEnd = do
-  charOrRef "\"\8221"
+  charOrRef "\"\8221\148"
   return ()
 
 ellipses :: GenParser Char st Inline
 ellipses = do
-  try (charOrRef "…") <|> try (string "..." >> return '…')
+  try (charOrRef "…\133") <|> try (string "..." >> return '…')
   return Ellipses
 
 dash :: GenParser Char st Inline
@@ -791,13 +797,13 @@
 
 enDash :: GenParser Char st Inline
 enDash = do
-  try (charOrRef "–") <|>
+  try (charOrRef "–\150") <|>
     try (char '-' >> lookAhead (satisfy isDigit) >> return '–')
   return EnDash
 
 emDash :: GenParser Char st Inline
 emDash = do
-  try (charOrRef "—") <|> (try $ string "--" >> optional (char '-') >> return '—')
+  try (charOrRef "—\151") <|> (try $ string "--" >> optional (char '-') >> return '—')
   return EmDash
 
 --
diff --git a/src/Text/Pandoc/Readers/HTML.hs b/src/Text/Pandoc/Readers/HTML.hs
--- a/src/Text/Pandoc/Readers/HTML.hs
+++ b/src/Text/Pandoc/Readers/HTML.hs
@@ -416,10 +416,12 @@
   guard $ all isSpace str
 
 pTagContents :: GenParser Char ParserState Inline
-pTagContents =  pStr <|> pSpace <|> smartPunctuation pTagContents <|> pSymbol
+pTagContents =
+  pStr <|> pSpace <|> smartPunctuation pTagContents <|> pSymbol <|> pBad
 
 pStr :: GenParser Char ParserState Inline
-pStr = liftM Str $ many1 $ satisfy $ \c -> not (isSpace c) && not (isSpecial c)
+pStr = liftM Str $ many1 $ satisfy $ \c ->
+           not (isSpace c) && not (isSpecial c) && not (isBad c)
 
 isSpecial :: Char -> Bool
 isSpecial '"' = True
@@ -434,6 +436,43 @@
 
 pSymbol :: GenParser Char ParserState Inline
 pSymbol = satisfy isSpecial >>= return . Str . (:[])
+
+isBad :: Char -> Bool
+isBad c = c >= '\128' && c <= '\159' -- not allowed in HTML
+
+pBad :: GenParser Char ParserState Inline
+pBad = do
+  c <- satisfy isBad
+  let c' = case c of
+                '\128' -> '\8364'
+                '\130' -> '\8218'
+                '\131' -> '\402'
+                '\132' -> '\8222'
+                '\133' -> '\8230'
+                '\134' -> '\8224'
+                '\135' -> '\8225'
+                '\136' -> '\710'
+                '\137' -> '\8240'
+                '\138' -> '\352'
+                '\139' -> '\8249'
+                '\140' -> '\338'
+                '\142' -> '\381'
+                '\145' -> '\8216'
+                '\146' -> '\8217'
+                '\147' -> '\8220'
+                '\148' -> '\8221'
+                '\149' -> '\8226'
+                '\150' -> '\8211'
+                '\151' -> '\8212'
+                '\152' -> '\732'
+                '\153' -> '\8482'
+                '\154' -> '\353'
+                '\155' -> '\8250'
+                '\156' -> '\339'
+                '\158' -> '\382'
+                '\159' -> '\376'
+                _      -> '?'
+  return $ Str [c']
 
 pSpace :: GenParser Char ParserState Inline
 pSpace = many1 (satisfy isSpace) >> return Space
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs
--- a/src/Text/Pandoc/Readers/LaTeX.hs
+++ b/src/Text/Pandoc/Readers/LaTeX.hs
@@ -391,7 +391,7 @@
 --
 
 bibliographic :: GenParser Char ParserState Block
-bibliographic = choice [ maketitle, title, authors, date ]
+bibliographic = choice [ maketitle, title, subtitle, authors, date ]
 
 maketitle :: GenParser Char st Block
 maketitle = try (string "\\maketitle") >> spaces >> return Null
@@ -404,11 +404,22 @@
   updateState (\state -> state { stateTitle = tit })
   return Null
 
+subtitle :: GenParser Char ParserState Block
+subtitle = try $ do
+  string "\\subtitle{"
+  tit <- manyTill inline (char '}')
+  spaces
+  updateState (\state -> state { stateTitle = stateTitle state ++
+                                   Str ":" : LineBreak : tit })
+  return Null
+
 authors :: GenParser Char ParserState Block
 authors = try $ do
   string "\\author{"
-  raw <- many1 (notFollowedBy (char '}') >> inline)
-  let authors' = map normalizeSpaces $ splitBy (== LineBreak) raw
+  let andsep = try $ string "\\and" >> notFollowedBy letter >>
+                     spaces >> return '&'
+  raw <- sepBy (many $ notFollowedBy (char '}' <|> andsep) >> inline) andsep
+  let authors' = map normalizeSpaces raw
   char '}'
   spaces
   updateState (\s -> s { stateAuthors = authors' })
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -1,3 +1,4 @@
+{-# LANGUAGE RelaxedPolyRec #-} -- needed for inlinesBetween on GHC < 7
 {-
 Copyright (C) 2006-2010 John MacFarlane <jgm@berkeley.edu>
 
@@ -907,7 +908,7 @@
                 , str
                 , endline
                 , code
-                , (fourOrMore '*' <|> fourOrMore '_')
+                , fours
                 , strong
                 , emph
                 , note
@@ -1018,24 +1019,45 @@
 
 -- to avoid performance problems, treat 4 or more _ or * in a row as a literal
 -- rather than attempting to parse for emph/strong
-fourOrMore :: Char -> GenParser Char st Inline
-fourOrMore c = try $ count 4 (char c) >> many (char c) >>= \s ->
-                       return (Str $ replicate 4 c ++ s)
+fours :: GenParser Char st Inline
+fours = try $ do
+  x <- char '*' <|> char '_'
+  count 2 $ satisfy (==x)
+  rest <- many1 (satisfy (==x))
+  return $ Str (x:x:x:rest)
 
+-- | Parses a list of inlines between start and end delimiters.
+inlinesBetween :: (Show b)
+               => GenParser Char ParserState a
+               -> GenParser Char ParserState b
+               -> GenParser Char ParserState [Inline]
+inlinesBetween start end =
+  normalizeSpaces `liftM` try (start >> many1Till inner end)
+    where inner      = innerSpace <|> (notFollowedBy' whitespace >> inline)
+          innerSpace = try $ whitespace >>~ notFollowedBy' end
+
 emph :: GenParser Char ParserState Inline
-emph = ((enclosed (char '*') (notFollowedBy' strong >> char '*') inline) <|>
-        (enclosed (char '_') (notFollowedBy' strong >> char '_' >> 
-                              notFollowedBy alphaNum) inline)) >>= 
-        return . Emph . normalizeSpaces
+emph = Emph `liftM`
+  (inlinesBetween starStart starEnd <|> inlinesBetween ulStart ulEnd)
+    where starStart = char '*' >> lookAhead nonspaceChar
+          starEnd   = notFollowedBy' strong >> char '*'
+          ulStart   = char '_' >> lookAhead nonspaceChar
+          ulEnd     = notFollowedBy' strong >> char '_'
 
 strong :: GenParser Char ParserState Inline
-strong = ((enclosed (string "**") (try $ string "**") inline) <|> 
-          (enclosed (string "__") (try $ string "__") inline)) >>=
-         return . Strong . normalizeSpaces
+strong = Strong `liftM`
+  (inlinesBetween starStart starEnd <|> inlinesBetween ulStart ulEnd)
+    where starStart = string "**" >> lookAhead nonspaceChar
+          starEnd   = try $ string "**"
+          ulStart   = string "__" >> lookAhead nonspaceChar
+          ulEnd     = try $ string "__"
 
 strikeout :: GenParser Char ParserState Inline
-strikeout = failIfStrict >> enclosed (string "~~") (try $ string "~~") inline >>=
-            return . Strikeout . normalizeSpaces
+strikeout = Strikeout `liftM`
+ (failIfStrict >> inlinesBetween strikeStart strikeEnd)
+    where strikeStart = string "~~" >> lookAhead nonspaceChar
+                        >> notFollowedBy (char '~')
+          strikeEnd   = try $ string "~~"
 
 superscript :: GenParser Char ParserState Inline
 superscript = failIfStrict >> enclosed (char '^') (char '^') 
diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs
--- a/src/Text/Pandoc/Readers/RST.hs
+++ b/src/Text/Pandoc/Readers/RST.hs
@@ -34,7 +34,7 @@
 import Text.Pandoc.Shared
 import Text.Pandoc.Parsing
 import Text.ParserCombinators.Parsec
-import Control.Monad ( when )
+import Control.Monad ( when, liftM )
 import Data.List ( findIndex, intercalate, transpose, sort, deleteFirstsBy )
 import qualified Data.Map as M
 import Text.Printf ( printf )
@@ -540,9 +540,15 @@
   return $ replicate (sourceLine endPos - sourceLine startPos) '\n'
 
 noteMarker :: GenParser Char ParserState [Char]
-noteMarker = char '[' >> (many1 digit <|> count 1 (oneOf "#*")) >>~ char ']'
+noteMarker = do
+  char '['
+  res <- many1 digit
+      <|> (try $ char '#' >> liftM ('#':) simpleReferenceName')
+      <|> count 1 (oneOf "#*")
+  char ']'
+  return res
 
--- 
+--
 -- reference key
 --
 
@@ -557,13 +563,20 @@
   label' <- many1Till inline (lookAhead $ char ':')
   return label'
 
-isolated :: Char -> GenParser Char st Char
-isolated ch = try $ char ch >>~ notFollowedBy (char ch)
+-- Simple reference names are single words consisting of alphanumerics
+-- plus isolated (no two adjacent) internal hyphens, underscores,
+-- periods, colons and plus signs; no whitespace or other characters
+-- are allowed.
+simpleReferenceName' :: GenParser Char st String
+simpleReferenceName' = do
+  x <- alphaNum
+  xs <- many $  alphaNum
+            <|> (try $ oneOf "-_:+." >> lookAhead alphaNum)
+  return (x:xs)
 
 simpleReferenceName :: GenParser Char st [Inline]
 simpleReferenceName = do
-  raw <- many1 (alphaNum <|> isolated '-' <|> isolated '.' <|>
-                (try $ char '_' >>~ lookAhead alphaNum))
+  raw <- simpleReferenceName'
   return [Str raw]
 
 referenceName :: GenParser Char ParserState [Inline]
diff --git a/src/Text/Pandoc/S5.hs b/src/Text/Pandoc/S5.hs
--- a/src/Text/Pandoc/S5.hs
+++ b/src/Text/Pandoc/S5.hs
@@ -31,6 +31,8 @@
 module Text.Pandoc.S5 ( s5HeaderIncludes) where
 import Text.Pandoc.Shared ( readDataFile )
 import System.FilePath ( (</>) )
+import Data.ByteString.UTF8 ( toString, fromString )
+import Data.ByteString.Base64 ( encode )
 
 s5HeaderIncludes :: Maybe FilePath -> IO String
 s5HeaderIncludes datadir = do
@@ -40,11 +42,15 @@
 
 s5Javascript :: Maybe FilePath -> IO String
 s5Javascript datadir = do
-  jsCom <- readDataFile datadir $ "s5" </> "default" </> "slides.js.comment"
-  jsPacked <- readDataFile datadir $ "s5" </> "default" </> "slides.js.packed"
-  return $ "<script type=\"text/javascript\">\n" ++ jsCom ++ jsPacked ++
-           "</script>\n"
+  js <- readDataFile datadir $ "s5" </> "default" </> "slides.min.js"
+  return $ "<script type=\"text/javascript\">\n" ++ inCDATA js ++ "</script>\n"
 
+inCDATA :: String -> String
+inCDATA s = "/*<![CDATA[*/\n" ++ s ++ "\n/*]]>*/\n"
+
+base64 :: String -> String
+base64 = toString . encode . fromString
+
 s5CSS :: Maybe FilePath -> IO String
 s5CSS datadir = do
   s5CoreCSS <- readDataFile datadir $ "s5" </> "default" </> "s5-core.css"
@@ -53,5 +59,11 @@
   s5OperaCSS <- readDataFile datadir $ "s5" </> "default" </> "opera.css"
   s5OutlineCSS <- readDataFile datadir $ "s5" </> "default" </> "outline.css"
   s5PrintCSS <- readDataFile datadir $ "s5" </> "default" </> "print.css"
-  return $ "<style type=\"text/css\" media=\"projection\" id=\"slideProj\">\n" ++ s5CoreCSS ++ "\n" ++ s5FramingCSS ++ "\n" ++ s5PrettyCSS ++ "\n</style>\n<style type=\"text/css\" media=\"projection\" id=\"operaFix\">\n" ++ s5OperaCSS ++ "\n</style>\n<style type=\"text/css\" media=\"screen\" id=\"outlineStyle\">\n" ++ s5OutlineCSS ++ "\n</style>\n<style type=\"text/css\" media=\"print\" id=\"slidePrint\">\n" ++ s5PrintCSS ++ "\n</style>\n"
-
+  return $ "<link rel=\"stylesheet\" type=\"text/css\" media=\"projection\" id=\"slideProj\" href=\"data:text/css;charset=utf-8;base64," ++
+          base64 (s5CoreCSS ++ "\n" ++ s5FramingCSS ++ "\n" ++ s5PrettyCSS) ++ "\" />\n" ++
+          "<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" id=\"outlineStyle\" href=\"data:text/css;charset=utf-8;base64," ++
+          base64 s5OutlineCSS ++ "\" />\n" ++
+          "<link rel=\"stylesheet\" type=\"text/css\" media=\"print\" id=\"slidePrint\" href=\"data:text/css;charset=utf-8;base64," ++
+          base64 s5PrintCSS ++ "\" />\n" ++
+          "<link rel=\"stylesheet\" type=\"text/css\" media=\"projection\" id=\"operaFix\" href=\"data:text/css;charset=utf-8;base64," ++
+          base64 s5OperaCSS ++ "\" />\n"
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs
--- a/src/Text/Pandoc/Shared.hs
+++ b/src/Text/Pandoc/Shared.hs
@@ -67,7 +67,7 @@
                      -- * File handling
                      inDirectory,
                      findDataFile,
-                     readDataFile
+                     readDataFile,
                     ) where
 
 import Text.Pandoc.Definition
@@ -493,6 +493,7 @@
   , writerAscii            :: Bool       -- ^ Avoid non-ascii characters
   } deriving Show
 
+{-# DEPRECATED writerXeTeX "writerXeTeX no longer does anything" #-}
 -- | Default writer options.
 defaultWriterOptions :: WriterOptions
 defaultWriterOptions = 
diff --git a/src/Text/Pandoc/Templates.hs b/src/Text/Pandoc/Templates.hs
--- a/src/Text/Pandoc/Templates.hs
+++ b/src/Text/Pandoc/Templates.hs
@@ -83,9 +83,10 @@
                    -> IO (Either E.IOException String)
 getDefaultTemplate _ "native" = return $ Right ""
 getDefaultTemplate user "odt" = getDefaultTemplate user "opendocument"
+getDefaultTemplate user "epub" = getDefaultTemplate user "html"
 getDefaultTemplate user writer = do
   let format = takeWhile (/='+') writer  -- strip off "+lhs" if present
-  let fname = "templates" </> format  <.> "template"
+  let fname = "templates" </> "default" <.> format
   E.try $ readDataFile user fname
 
 data TemplateState = TemplateState Int [(String,String)]
diff --git a/src/Text/Pandoc/Writers/ConTeXt.hs b/src/Text/Pandoc/Writers/ConTeXt.hs
--- a/src/Text/Pandoc/Writers/ConTeXt.hs
+++ b/src/Text/Pandoc/Writers/ConTeXt.hs
@@ -123,7 +123,7 @@
   contents <- blockListToConTeXt lst
   return $ "\\startblockquote" $$ nest 0 contents $$ "\\stopblockquote" <> blankline
 blockToConTeXt (CodeBlock _ str) =
-  return $ "\\starttyping" <> cr <> flush (text str) <> cr <> "\\stoptyping" $$ blankline
+  return $ flush ("\\starttyping" <> cr <> text str <> cr <> "\\stoptyping") $$ blankline
   -- blankline because \stoptyping can't have anything after it, inc. '}'
 blockToConTeXt (RawBlock "context" str) = return $ text str <> blankline
 blockToConTeXt (RawBlock _ _ ) = return empty
diff --git a/src/Text/Pandoc/Writers/Docbook.hs b/src/Text/Pandoc/Writers/Docbook.hs
--- a/src/Text/Pandoc/Writers/Docbook.hs
+++ b/src/Text/Pandoc/Writers/Docbook.hs
@@ -147,9 +147,9 @@
   inTagsIndented "para" $ inlinesToDocbook opts lst
 blockToDocbook opts (BlockQuote blocks) =
   inTagsIndented "blockquote" $ blocksToDocbook opts blocks
-blockToDocbook _ (CodeBlock (_,classes,_) str) = 
-  text ("<screen" ++ lang ++ ">") <> cr <>
-     flush (text (escapeStringForXML str) <> cr <> text "</screen>")
+blockToDocbook _ (CodeBlock (_,classes,_) str) =
+  text ("<programlisting" ++ lang ++ ">") <> cr <>
+     flush (text (escapeStringForXML str) <> cr <> text "</programlisting>")
     where lang  = if null langs
                      then ""
                      else " language=\"" ++ escapeStringForXML (head langs) ++
@@ -185,24 +185,24 @@
 blockToDocbook _ (RawBlock _ _) = empty
 blockToDocbook _ HorizontalRule = empty -- not semantic
 blockToDocbook opts (Table caption aligns widths headers rows) =
-  let alignStrings = map alignmentToString aligns
-      captionDoc   = if null caption
+  let captionDoc   = if null caption
                         then empty
-                        else inTagsIndented "caption" 
+                        else inTagsIndented "title"
                               (inlinesToDocbook opts caption)
       tableType    = if isEmpty captionDoc then "informaltable" else "table"
-      percent w    = show (truncate (100*w) :: Integer) ++ "%"
-      coltags = if all (== 0.0) widths
-                   then empty
-                   else vcat $ map (\w ->
-                          selfClosingTag "col" [("width", percent w)]) widths
+      percent w    = show (truncate (100*w) :: Integer) ++ "*"
+      coltags = vcat $ zipWith (\w al -> selfClosingTag "colspec"
+                       ([("colwidth", percent w) | w > 0] ++
+                        [("align", alignmentToString al)])) widths aligns
       head' = if all null headers
                  then empty
                  else inTagsIndented "thead" $
-                         tableRowToDocbook opts alignStrings "th" headers
+                         tableRowToDocbook opts headers
       body' = inTagsIndented "tbody" $
-              vcat $ map (tableRowToDocbook opts alignStrings "td") rows
-  in  inTagsIndented tableType $ captionDoc $$ coltags $$ head' $$ body'
+              vcat $ map (tableRowToDocbook opts) rows
+  in  inTagsIndented tableType $ captionDoc $$
+        (inTags True "tgroup" [("cols", show (length headers))] $
+         coltags $$ head' $$ body')
 
 alignmentToString :: Alignment -> [Char]
 alignmentToString alignment = case alignment of
@@ -212,22 +212,16 @@
                                  AlignDefault -> "left"
 
 tableRowToDocbook :: WriterOptions
-                  -> [String]
-                  -> String
                   -> [[Block]]
                   -> Doc
-tableRowToDocbook opts aligns celltype cols =
-  inTagsIndented "tr" $ vcat $
-     zipWith (tableItemToDocbook opts celltype) aligns cols
+tableRowToDocbook opts cols =
+  inTagsIndented "row" $ vcat $ map (tableItemToDocbook opts) cols
 
 tableItemToDocbook :: WriterOptions
-                   -> [Char]
-                   -> [Char]
                    -> [Block]
                    -> Doc
-tableItemToDocbook opts tag align item =
-  let attrib = [("align", align)]
-  in  inTags True tag attrib $ vcat $ map (blockToDocbook opts) item
+tableItemToDocbook opts item =
+  inTags True "entry" [] $ vcat $ map (blockToDocbook opts) item
 
 -- | Convert a list of inline elements to Docbook.
 inlinesToDocbook :: WriterOptions -> [Inline] -> Doc
diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs
--- a/src/Text/Pandoc/Writers/HTML.hs
+++ b/src/Text/Pandoc/Writers/HTML.hs
@@ -142,7 +142,8 @@
                            _ -> case lookup "mathml-script" (writerVariables opts) of
                                       Just s ->
                                         script ! [thetype "text/javascript"] <<
-                                           primHtml s
+                                           primHtml ("/*<![CDATA[*/\n" ++ s ++
+                                                     "/*]]>*/\n")
                                       Nothing -> noHtml
                 else noHtml
   let newvars = [("highlighting-css", defaultHighlightingCss) |
@@ -169,7 +170,10 @@
                     [ ("body", dropWhile (=='\n') $ showHtmlFragment body')
                     , ("pagetitle", topTitle')
                     , ("title", dropWhile (=='\n') $ showHtmlFragment tit)
-                    , ("date", date') ] ++
+                    , ("date", date')
+                    , ("idprefix", writerIdentifierPrefix opts)
+                    , ("slidy-url", "http://www.w3.org/Talks/Tools/Slidy2")
+                    , ("s5-url", "ui/default") ] ++
                     [ ("html5","true") | writerHtml5 opts ] ++
                     (case toc of
                          Just t  -> [ ("toc", showHtmlFragment t)]
@@ -198,14 +202,7 @@
   let tocList = catMaybes contents
   return $ if null tocList
               then Nothing
-              else Just $
-                   if writerHtml5 opts
-                      then (tag "nav" ! [prefixedId opts' "TOC"] $
-                            nl opts +++ unordList opts tocList +++ nl opts)
-                            +++ nl opts
-                      else (thediv ! [prefixedId opts' "TOC"] $
-                            nl opts +++ unordList opts tocList +++ nl opts)
-                            +++ nl opts
+              else Just $ unordList opts tocList
 
 -- | Convert section number to string
 showSecNum :: [Int] -> String
@@ -652,8 +649,7 @@
   -- If last block is Para or Plain, include the backlink at the end of
   -- that block. Otherwise, insert a new Plain block with the backlink.
   let backlink = [RawInline "html" $ " <a href=\"#" ++ writerIdentifierPrefix opts ++ "fnref" ++ ref ++
-                 "\" class=\"footnoteBackLink\"" ++
-                 " title=\"Jump back to footnote " ++ ref ++ "\">" ++
+                 "\" class=\"footnoteBackLink\">" ++
                  (if writerAscii opts then "&#8617;" else "↩") ++ "</a>"]
       blocks'  = if null blocks
                     then []
diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs
--- a/src/Text/Pandoc/Writers/LaTeX.hs
+++ b/src/Text/Pandoc/Writers/LaTeX.hs
@@ -35,7 +35,8 @@
 import Text.Pandoc.Templates
 import Text.Printf ( printf )
 import Network.URI ( isAbsoluteURI, unEscapeString )
-import Data.List ( (\\), isSuffixOf, isPrefixOf, intercalate, intersperse )
+import Data.List ( (\\), isSuffixOf, isInfixOf,
+                   isPrefixOf, intercalate, intersperse )
 import Data.Char ( toLower, isPunctuation )
 import Control.Monad.State
 import Text.Pandoc.Pretty
@@ -57,6 +58,7 @@
               , stGraphics   :: Bool          -- true if document contains images
               , stLHS        :: Bool          -- true if document has literate haskell code
               , stBook       :: Bool          -- true if document uses book or memoir class
+              , stCsquotes   :: Bool          -- true if document uses csquotes
               }
 
 -- | Convert Pandoc to LaTeX.
@@ -68,7 +70,8 @@
                 stVerbInNote = False, stEnumerate = False,
                 stTable = False, stStrikeout = False, stSubscript = False,
                 stUrl = False, stGraphics = False,
-                stLHS = False, stBook = writerChapters options }
+                stLHS = False, stBook = writerChapters options,
+                stCsquotes = False }
 
 pandocToLaTeX :: WriterOptions -> Pandoc -> State WriterState String
 pandocToLaTeX options (Pandoc (Meta title authors date) blocks) = do
@@ -78,6 +81,10 @@
           "{report}" `isSuffixOf` x)
   when (any usesBookClass (lines template)) $
     modify $ \s -> s{stBook = True}
+  -- check for \usepackage...{csquotes}; if present, we'll use
+  -- \enquote{...} for smart quotes:
+  when ("{csquotes}" `isInfixOf` template) $
+    modify $ \s -> s{stCsquotes = True}
   opts <- liftM stOptions get
   let colwidth = if writerWrapText opts
                     then Just $ writerColumns opts
@@ -111,7 +118,6 @@
                  , ("title", titletext)
                  , ("date", dateText) ] ++
                  [ ("author", a) | a <- authorsText ] ++
-                 [ ("xetex", "yes") | writerXeTeX options ] ++
                  [ ("verbatim-in-note", "yes") | stVerbInNote st ] ++
                  [ ("fancy-enums", "yes") | stEnumerate st ] ++
                  [ ("tables", "yes") | stTable st ] ++
@@ -152,21 +158,13 @@
 inCmd :: String -> Doc -> Doc
 inCmd cmd contents = char '\\' <> text cmd <> braces contents
 
--- | Remove all code elements from list of inline elements
--- (because it's illegal to have verbatim inside some command arguments)
-deVerb :: [Inline] -> [Inline]
-deVerb [] = []
-deVerb ((Code _ str):rest) = 
-  (RawInline "latex" $ "\\texttt{" ++ stringToLaTeX str ++ "}"):(deVerb rest)
-deVerb (other:rest) = other:(deVerb rest)
-
 -- | Convert Pandoc block element to LaTeX.
 blockToLaTeX :: Block     -- ^ Block to convert
              -> State WriterState Doc
 blockToLaTeX Null = return empty
 blockToLaTeX (Plain lst) = inlineListToLaTeX lst
 blockToLaTeX (Para [Image txt (src,tit)]) = do
-  capt <- inlineListToLaTeX $ deVerb txt
+  capt <- inlineListToLaTeX txt
   img <- inlineToLaTeX (Image txt (src,tit))
   return $ "\\begin{figure}[htbp]" $$ "\\centering" $$ img $$
            ("\\caption{" <> capt <> char '}') $$ "\\end{figure}" $$ blankline
@@ -216,8 +214,9 @@
           | null params = empty
           | otherwise   = "[" <> hsep (intersperse "," (map text params)) <>
                           "]"
-  return $ "\\begin{" <> text env <> "}" <> printParams $$ flush (text str) $$
-           "\\end{" <> text env <> "}" $$ cr   -- final cr needed because of footnotes
+  return $ flush ("\\begin{" <> text env <> "}" <> printParams $$ text str $$
+           "\\end{" <> text env <> "}") $$ cr
+           -- final cr needed because of footnotes
 blockToLaTeX (RawBlock "latex" x) = return $ text x <> blankline
 blockToLaTeX (RawBlock _ _) = return empty
 blockToLaTeX (BulletList lst) = do
@@ -249,14 +248,13 @@
 blockToLaTeX HorizontalRule = return $
   "\\begin{center}\\rule{3in}{0.4pt}\\end{center}" $$ blankline
 blockToLaTeX (Header level lst) = do
-  let lst' = deVerb lst
-  txt <- inlineListToLaTeX lst'
+  txt <- inlineListToLaTeX lst
   let noNote (Note _) = Str ""
       noNote x        = x
-  let lstNoNotes = bottomUp noNote lst'
+  let lstNoNotes = bottomUp noNote lst
   -- footnotes in sections don't work unless you specify an optional
   -- argument:  \section[mysec]{mysec\footnote{blah}}
-  optional <- if lstNoNotes == lst'
+  optional <- if lstNoNotes == lst
                  then return empty
                  else do
                    res <- inlineListToLaTeX lstNoNotes
@@ -279,7 +277,7 @@
                 then return empty
                 else liftM ($$ "\\ML")
                      $ (tableRowToLaTeX True aligns widths) heads
-  captionText <- inlineListToLaTeX $ deVerb caption
+  captionText <- inlineListToLaTeX caption
   let capt = if isEmpty captionText
                 then empty
                 else text "caption = " <> captionText <> "," <> space
@@ -336,7 +334,7 @@
 
 defListItemToLaTeX :: ([Inline], [[Block]]) -> State WriterState Doc
 defListItemToLaTeX (term, defs) = do
-    term' <- inlineListToLaTeX $ deVerb term
+    term' <- inlineListToLaTeX term
     def'  <- liftM vsep $ mapM blockListToLaTeX defs
     return $ "\\item" <> brackets term' $$ def'
 
@@ -354,23 +352,23 @@
 inlineToLaTeX :: Inline    -- ^ Inline to convert
               -> State WriterState Doc
 inlineToLaTeX (Emph lst) =
-  inlineListToLaTeX (deVerb lst) >>= return . inCmd "emph"
+  inlineListToLaTeX lst >>= return . inCmd "emph"
 inlineToLaTeX (Strong lst) = 
-  inlineListToLaTeX (deVerb lst) >>= return . inCmd "textbf" 
+  inlineListToLaTeX lst >>= return . inCmd "textbf" 
 inlineToLaTeX (Strikeout lst) = do
-  contents <- inlineListToLaTeX $ deVerb lst
+  contents <- inlineListToLaTeX lst
   modify $ \s -> s{ stStrikeout = True }
   return $ inCmd "sout" contents
 inlineToLaTeX (Superscript lst) =
-  inlineListToLaTeX (deVerb lst) >>= return . inCmd "textsuperscript"
+  inlineListToLaTeX lst >>= return . inCmd "textsuperscript"
 inlineToLaTeX (Subscript lst) = do
   modify $ \s -> s{ stSubscript = True }
-  contents <- inlineListToLaTeX $ deVerb lst
+  contents <- inlineListToLaTeX lst
   -- oddly, latex includes \textsuperscript but not \textsubscript
   -- so we have to define it (using a different name so as not to conflict with memoir class):
   return $ inCmd "textsubscr" contents
 inlineToLaTeX (SmallCaps lst) =
-  inlineListToLaTeX (deVerb lst) >>= return . inCmd "textsc"
+  inlineListToLaTeX lst >>= return . inCmd "textsc"
 inlineToLaTeX (Cite cits lst) = do
   st <- get
   let opts = stOptions st
@@ -381,29 +379,38 @@
 
 inlineToLaTeX (Code _ str) = do
   st <- get
-  when (stInNote st) $ modify $ \s -> s{ stVerbInNote = True }
-  let chr = ((enumFromTo '!' '~') \\ str) !! 0
   if writerListings (stOptions st)
-    then return $ text $ "\\lstinline" ++ [chr] ++ str ++ [chr]
-    else return $ text $ "\\verb" ++ [chr] ++ str ++ [chr]
+    then do
+      when (stInNote st) $ modify $ \s -> s{ stVerbInNote = True }
+      let chr = ((enumFromTo '!' '~') \\ str) !! 0
+      return $ text $ "\\lstinline" ++ [chr] ++ str ++ [chr]
+    else return $ text $ "\\texttt{" ++ stringToLaTeX str ++ "}"
 inlineToLaTeX (Quoted SingleQuote lst) = do
   contents <- inlineListToLaTeX lst
-  let s1 = if (not (null lst)) && (isQuoted (head lst))
-              then "\\,"
-              else empty
-  let s2 = if (not (null lst)) && (isQuoted (last lst))
-              then "\\,"
-              else empty
-  return $ char '`' <> s1 <> contents <> s2 <> char '\''
+  csquotes <- liftM stCsquotes get
+  if csquotes
+     then return $ "\\enquote" <> braces contents
+     else do
+       let s1 = if (not (null lst)) && (isQuoted (head lst))
+                   then "\\,"
+                   else empty
+       let s2 = if (not (null lst)) && (isQuoted (last lst))
+                   then "\\,"
+                   else empty
+       return $ char '`' <> s1 <> contents <> s2 <> char '\''
 inlineToLaTeX (Quoted DoubleQuote lst) = do
   contents <- inlineListToLaTeX lst
-  let s1 = if (not (null lst)) && (isQuoted (head lst))
-              then "\\,"
-              else empty
-  let s2 = if (not (null lst)) && (isQuoted (last lst))
-              then "\\,"
-              else empty
-  return $ "``" <> s1 <> contents <> s2 <> "''"
+  csquotes <- liftM stCsquotes get
+  if csquotes
+     then return $ "\\enquote" <> braces contents
+     else do
+       let s1 = if (not (null lst)) && (isQuoted (head lst))
+                   then "\\,"
+                   else empty
+       let s2 = if (not (null lst)) && (isQuoted (last lst))
+                   then "\\,"
+                   else empty
+       return $ "``" <> s1 <> contents <> s2 <> "''"
 inlineToLaTeX Apostrophe = return $ char '\''
 inlineToLaTeX EmDash = return "---"
 inlineToLaTeX EnDash = return "--"
@@ -421,7 +428,7 @@
         [Code _ x] | x == src ->  -- autolink
              do modify $ \s -> s{ stUrl = True }
                 return $ text $ "\\url{" ++ x ++ "}"
-        _ -> do contents <- inlineListToLaTeX $ deVerb txt
+        _ -> do contents <- inlineListToLaTeX txt
                 return $ text ("\\href{" ++ stringToLaTeX src ++ "}{") <>
                          contents <> char '}'
 inlineToLaTeX (Image _ (source, _)) = do
diff --git a/src/Text/Pandoc/Writers/ODT.hs b/src/Text/Pandoc/Writers/ODT.hs
--- a/src/Text/Pandoc/Writers/ODT.hs
+++ b/src/Text/Pandoc/Writers/ODT.hs
@@ -29,6 +29,7 @@
 -}
 module Text.Pandoc.Writers.ODT ( writeODT ) where
 import Data.IORef
+import Data.List ( isPrefixOf )
 import System.FilePath ( (</>), takeExtension )
 import qualified Data.ByteString.Lazy as B
 import Data.ByteString.Lazy.UTF8 ( fromString )
@@ -36,12 +37,15 @@
 import System.Time
 import Paths_pandoc ( getDataFileName )
 import Text.Pandoc.Shared ( WriterOptions(..) )
+import Text.Pandoc.MIME ( getMimeType )
 import Text.Pandoc.Definition
 import Text.Pandoc.Generic
 import Text.Pandoc.Writers.OpenDocument ( writeOpenDocument )
 import System.Directory
 import Control.Monad (liftM)
 import Network.URI ( unEscapeString )
+import Text.Pandoc.XML
+import Text.Pandoc.Pretty
 
 -- | Produce an ODT file from a Pandoc document.
 writeODT :: Maybe FilePath -- ^ Path specified by --reference-odt
@@ -70,8 +74,30 @@
   (TOD epochtime _) <- getClockTime
   let contentEntry = toEntry "content.xml" epochtime $ fromString newContents
   picEntries <- readIORef picEntriesRef
-  let archive = foldr addEntryToArchive refArchive (contentEntry : picEntries)
-  return $ fromArchive archive
+  let archive = foldr addEntryToArchive refArchive $ contentEntry : picEntries
+  -- construct META-INF/manifest.xml based on archive
+  let toFileEntry fp = case getMimeType fp of
+                        Nothing  -> empty
+                        Just m   -> selfClosingTag "manifest:file-entry"
+                                     [("manifest:media-type", m)
+                                     ,("manifest:full-path", fp)
+                                     ]
+  let files = [ ent | ent <- filesInArchive archive, not ("META-INF" `isPrefixOf` ent) ]
+  let manifestEntry = toEntry "META-INF/manifest.xml" epochtime
+        $ fromString $ show
+        $ text "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
+        $$
+         ( inTags True "manifest:manifest"
+            [("xmlns:manifest","urn:oasis:names:tc:opendocument:xmlns:manifest:1.0")]
+            $ ( selfClosingTag "manifest:file-entry"
+                 [("manifest:media-type","application/vnd.oasis.opendocument.text")
+                 ,("manifest:version","1.2")
+                 ,("manifest:full-path","/")]
+                $$ vcat ( map toFileEntry $ files )
+              )
+         )
+  let archive' = addEntryToArchive manifestEntry archive
+  return $ fromArchive archive'
 
 transformPic :: FilePath -> IORef [Entry] -> Inline -> IO Inline
 transformPic sourceDir entriesRef (Image lab (src,tit)) = do
diff --git a/src/markdown2pdf.hs b/src/markdown2pdf.hs
--- a/src/markdown2pdf.hs
+++ b/src/markdown2pdf.hs
@@ -2,24 +2,63 @@
 
 import Data.List (isInfixOf, intercalate, isPrefixOf)
 import Data.Maybe (isNothing)
-
-import Control.Monad (unless, guard)
-import Control.Exception (tryJust, bracket)
+import qualified Data.ByteString as BS
+import Codec.Binary.UTF8.String (decodeString, encodeString)
+import Data.ByteString.UTF8 (toString)
+import Control.Monad (unless, guard, liftM, when)
+import Control.Concurrent (putMVar, takeMVar, newEmptyMVar, forkIO)
+import Control.Exception (tryJust, bracket, evaluate)
 
-import System.IO (stderr)
+import System.IO
 import System.IO.Error (isDoesNotExistError)
 import System.Environment ( getArgs, getProgName )
 import qualified Text.Pandoc.UTF8 as UTF8
 import System.Exit (ExitCode (..), exitWith)
 import System.FilePath
 import System.Directory
-import System.Process (readProcessWithExitCode)
-import Codec.Binary.UTF8.String (decodeString, encodeString)
-import Control.Monad (liftM)
+import System.Process
 
+-- A variant of 'readProcessWithExitCode' that does not
+-- cause an error if the output is not UTF-8. (Copied
+-- with slight variants from 'System.Process'.)
+readProcessWithExitCode'
+    :: FilePath                 -- ^ command to run
+    -> [String]                 -- ^ any arguments
+    -> String                   -- ^ standard input
+    -> IO (ExitCode,String,String) -- ^ exitcode, stdout, stderr
+readProcessWithExitCode' cmd args input = do
+    (Just inh, Just outh, Just errh, pid) <-
+        createProcess (proc cmd args){ std_in  = CreatePipe,
+                                       std_out = CreatePipe,
+                                       std_err = CreatePipe }
+
+    outMVar <- newEmptyMVar
+
+    -- fork off a thread to start consuming stdout
+    out  <- liftM toString $ BS.hGetContents outh
+    _ <- forkIO $ evaluate (length out) >> putMVar outMVar ()
+
+    -- fork off a thread to start consuming stderr
+    err  <- liftM toString $ BS.hGetContents errh
+    _ <- forkIO $ evaluate (length err) >> putMVar outMVar ()
+
+    -- now write and flush any input
+    when (not (null input)) $ do hPutStr inh input; hFlush inh
+    hClose inh -- done with stdin
+
+    -- wait on the output
+    takeMVar outMVar
+    takeMVar outMVar
+    hClose outh
+
+    -- wait on the process
+    ex <- waitForProcess pid
+
+    return (ex, out, err)
+
 run :: FilePath -> [String] -> IO (Either String String)
 run file opts = do
-  (code, out, err) <- readProcessWithExitCode (encodeString file)
+  (code, out, err) <- readProcessWithExitCode' (encodeString file)
                         (map encodeString opts) ""
   let msg = out ++ err
   case code of
@@ -48,11 +87,12 @@
 runLatexRaw :: String -> FilePath -> IO (Either (Either String String) FilePath)
 runLatexRaw latexProgram file = do
   -- we ignore the ExitCode because pdflatex always fails the first time
-  run latexProgram ["-interaction=batchmode", "-output-directory",
-    takeDirectory file, dropExtension file] >> return ()
+  run latexProgram ["-halt-on-error", "-interaction", "nonstopmode",
+    "-output-directory", takeDirectory file, dropExtension file] >> return ()
   let pdfFile = replaceExtension file "pdf"
   let logFile = replaceExtension file "log"
-  txt <- tryJust (guard . isDoesNotExistError) (UTF8.readFile logFile)
+  txt <- tryJust (guard . isDoesNotExistError)
+         (liftM toString $ BS.readFile logFile)
   let  checks = checkLatex $ either (const "") id txt
   case checks of
   -- err  , bib , ref , msg
@@ -79,7 +119,9 @@
 checkLatex txt = (err , bib, ref, unlines $! msgs ++ tips)
   where
   xs `oneOf` x = any (flip isInfixOf x) xs
-  msgs = filter (oneOf ["Error:", "Warning:"]) (lines txt)
+  msgs = dropWhile (not . errorline) $ lines txt
+  errorline ('!':_) = True
+  errorline _ = False
   tips = checkPackages msgs
   err = any (oneOf ["!", "LaTeX Error:", "Latex Error:"]) msgs
   bib = any (oneOf ["Warning: Citation"
@@ -122,7 +164,7 @@
 
 saveStdin :: FilePath -> IO (Either String FilePath)
 saveStdin file = do
-  text <- UTF8.getContents
+  text <- liftM toString $ BS.getContents
   UTF8.writeFile file text
   fileExist <- doesFileExist (encodeString file)
   case fileExist of
@@ -152,7 +194,7 @@
     let goodopts = ["-f","-r","-N", "-p","-R","-H","-B","-A", "-C","-o","-V"]
     let goodoptslong = ["--from","--read","--strict",
                    "--preserve-tabs","--tab-stop","--parse-raw",
-                   "--toc","--table-of-contents", "--xetex",
+                   "--toc","--table-of-contents", "--xetex", "--luatex",
                    "--number-sections","--include-in-header",
                    "--include-before-body","--include-after-body",
                    "--custom-header","--output",
@@ -164,17 +206,23 @@
     -- note that a long option can come in this form: --opt=val
     let isGoodopt x = x `elem` (goodopts ++ goodoptslong) ||
                       any (\o -> (o ++ "=") `isPrefixOf` x) goodoptslong
+    let markdown2pdfOpts = ["--xetex","--luatex"]
     unless (all isGoodopt opts) $ do
       (code, out, _err) <- readProcessWithExitCode "pandoc" ["--help"] ""
       UTF8.putStrLn "markdown2pdf [OPTIONS] [FILES]\nOptions:"
       UTF8.putStr $ unlines $
-               filter (\l -> any (`isInfixOf` l) goodoptslong) $ lines out
+                 filter (\l -> any (`isInfixOf` l) goodoptslong) (lines out)
+                 ++ map (replicate 24 ' ' ++) markdown2pdfOpts
       exitWith code
 
+    let args' = filter (`notElem` markdown2pdfOpts) args
+
     -- check for executable files
     let latexProgram = if "--xetex" `elem` opts
                           then "xelatex"
-                          else "pdflatex"
+                          else if "--luatex" `elem` opts
+                                  then "lualatex"
+                                  else "pdflatex"
     let execs = ["pandoc", latexProgram, "bibtex"]
     paths <- mapM findExecutable execs
     let miss = map snd $ filter (isNothing . fst) $ zip paths execs
@@ -182,7 +230,7 @@
 
     -- parse arguments
     -- if no input given, use 'stdin'
-    pandocArgs <- parsePandocArgs args
+    pandocArgs <- parsePandocArgs args'
     (input, output) <- case pandocArgs of
       Nothing      -> exit "Could not parse arguments"
       Just ([],out) -> do
@@ -193,7 +241,7 @@
       -- no need because we'll pass all arguments to pandoc
       Just (_ ,out) -> return ([], out)
     -- run pandoc
-    pandocRes <- runPandoc (input ++ args) $ replaceDirectory output tmp
+    pandocRes <- runPandoc (input ++ args') $ replaceDirectory output tmp
     case pandocRes of
       Left err -> exit err
       Right texFile  -> do
diff --git a/src/pandoc.hs b/src/pandoc.hs
--- a/src/pandoc.hs
+++ b/src/pandoc.hs
@@ -44,6 +44,8 @@
 import Data.List ( intercalate, isSuffixOf, isPrefixOf )
 import System.Directory ( getAppUserDataDirectory, doesFileExist )
 import System.IO ( stdout, stderr )
+import System.IO.Error ( isDoesNotExistError )
+import Control.Exception.Extensible ( throwIO )
 import qualified Text.Pandoc.UTF8 as UTF8
 import Text.CSL
 import Text.Pandoc.Biblio
@@ -93,7 +95,7 @@
     , optParseRaw          :: Bool    -- ^ Parse unconvertable HTML and TeX
     , optTableOfContents   :: Bool    -- ^ Include table of contents
     , optTransforms        :: [Pandoc -> Pandoc]  -- ^ Doc transforms to apply
-    , optTemplate          :: String  -- ^ Custom template
+    , optTemplate          :: Maybe FilePath  -- ^ Custom template
     , optVariables         :: [(String,String)] -- ^ Template variables to set
     , optOutputFile        :: String  -- ^ Name of output file
     , optNumberSections    :: Bool    -- ^ Number sections in LaTeX
@@ -137,7 +139,7 @@
     , optParseRaw          = False
     , optTableOfContents   = False
     , optTransforms        = []
-    , optTemplate          = ""
+    , optTemplate          = Nothing
     , optVariables         = []
     , optOutputFile        = "-"    -- "-" means stdout
     , optNumberSections    = False
@@ -286,8 +288,12 @@
                  "" -- "Use jsMath for HTML math"
 
     , Option "" ["mathjax"]
-                 (ReqArg
-                  (\arg opt -> return opt { optHTMLMathMethod = MathJax arg})
+                 (OptArg
+                  (\arg opt -> do
+                      let url' = case arg of
+                                      Just u   -> u
+                                      Nothing  -> "https://d3eoax9i5htok0.cloudfront.net/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
+                      return opt { optHTMLMathMethod = MathJax url'})
                   "URL")
                  "" -- "Use MathJax for HTML math"
 
@@ -309,7 +315,10 @@
 
     , Option "" ["xetex"]
                  (NoArg
-                  (\opt -> return opt { optXeTeX = True }))
+                  (\opt -> do
+                     UTF8.hPutStrLn stderr $ "pandoc: --xetex is deprecated. "
+                       ++ "It is no longer needed for use with XeTeX."
+                     return opt { optXeTeX = True }))
                  "" -- "Format latex for processing by XeTeX"
 
     , Option "" ["chapters"]
@@ -404,8 +413,7 @@
     , Option "" ["template"]
                  (ReqArg
                   (\arg opt -> do
-                     text <- UTF8.readFile arg
-                     return opt{ optTemplate = text,
+                     return opt{ optTemplate = Just arg,
                                  optStandalone = True })
                   "FILENAME")
                  "" -- "Use custom template"
@@ -669,13 +677,12 @@
               , optVariables         = variables
               , optTableOfContents   = toc
               , optTransforms        = transforms
-              , optTemplate          = template
+              , optTemplate          = templatePath
               , optOutputFile        = outputFile
               , optNumberSections    = numberSections
               , optSectionDivs       = sectionDivs
               , optIncremental       = incremental
               , optOffline           = offline
-              , optXeTeX             = xetex
               , optSmart             = smart
               , optHtml5             = html5
               , optChapters          = chapters
@@ -729,10 +736,25 @@
      Just r  -> return r
      Nothing -> error ("Unknown reader: " ++ readerName')
 
-  templ <- getDefaultTemplate datadir writerName'
-  let defaultTemplate = case templ of
-                             Right t -> t
-                             Left  e -> error (show e)
+  templ <- case templatePath of
+                Nothing -> do
+                           deftemp <- getDefaultTemplate datadir writerName'
+                           case deftemp of
+                                 Left e   -> throwIO e
+                                 Right t  -> return t
+                Just tp -> do
+                           -- strip off "+lhs" if present
+                           let format = takeWhile (/='+') writerName'
+                           let tp' = case takeExtension tp of
+                                          ""   -> tp <.> format
+                                          _    -> tp
+                           catch (UTF8.readFile tp')
+                             (\e -> if isDoesNotExistError e
+                                       then catch
+                                             (readDataFile datadir $
+                                               "templates" </> tp')
+                                             (\_ -> throwIO e)
+                                       else throwIO e)
 
   let standalone' = standalone || isNonTextOutput writerName'
 
@@ -744,7 +766,7 @@
                         slidyJs <- readDataFile datadir $
                                       "slidy" </> "slidy.min.js"
                         slidyCss <- readDataFile datadir $
-                                      "slidy" </> "slidy.min.css"
+                                      "slidy" </> "slidy.css"
                         return $ ("slidy-js", slidyJs) :
                             ("slidy-css", slidyCss) : variables
                       _ -> return variables
@@ -786,10 +808,9 @@
                               stateIndentedCodeClasses = codeBlockClasses,
                               stateApplyMacros     = writerName' `notElem` ["latex", "latex+lhs"] }
 
-  let writerOptions = WriterOptions { writerStandalone       = standalone',
-                                      writerTemplate         = if null template
-                                                                  then defaultTemplate
-                                                                  else template,
+  let writerOptions = defaultWriterOptions
+                                    { writerStandalone       = standalone',
+                                      writerTemplate         = templ,
                                       writerVariables        = variables'',
                                       writerEPUBMetadata     = epubMetadata,
                                       writerTabStop          = tabStop,
@@ -798,7 +819,6 @@
                                       writerHTMLMathMethod   = mathMethod,
                                       writerSlideVariant     = slideVariant,
                                       writerIncremental      = incremental,
-                                      writerXeTeX            = xetex,
                                       writerCiteMethod       = citeMethod,
                                       writerBiblioFiles      = reffiles,
                                       writerIgnoreNotes      = False,
diff --git a/templates/context.template b/templates/context.template
deleted file mode 100644
--- a/templates/context.template
+++ /dev/null
@@ -1,84 +0,0 @@
-\enableregime[utf]  % use UTF-8
-
-\setupcolors[state=start]
-\setupinteraction[state=start, color=middleblue] % needed for hyperlinks
-
-\setuppapersize[letter][letter]  % use letter paper
-\setuplayout[width=middle, backspace=1.5in, cutspace=1.5in,
-             height=middle, header=0.75in, footer=0.75in] % page layout
-\setuppagenumbering[location={footer,center}]  % number pages
-\setupbodyfont[11pt]  % 11pt font
-\setupwhitespace[medium]  % inter-paragraph spacing
-
-\setuphead[section][style=\tfc]
-\setuphead[subsection][style=\tfb]
-\setuphead[subsubsection][style=\bf]
-
-% define descr (for definition lists)
-\definedescription[descr][
-  headstyle=bold,style=normal,align=left,location=hanging,
-  width=broad,margin=1cm]
-
-% prevent orphaned list intros
-\setupitemize[autointro]
-
-% define defaults for bulleted lists 
-\setupitemize[1][symbol=1][indentnext=no]
-\setupitemize[2][symbol=2][indentnext=no]
-\setupitemize[3][symbol=3][indentnext=no]
-\setupitemize[4][symbol=4][indentnext=no]
-
-\setupthinrules[width=15em]  % width of horizontal rules
-
-% for block quotations
-\unprotect
-
-\startvariables all
-blockquote: blockquote
-\stopvariables
-
-\definedelimitedtext
-[\v!blockquote][\v!quotation]
-
-\setupdelimitedtext
-[\v!blockquote]
-[\c!left=,
-\c!right=,
-before={\blank[medium]},
-after={\blank[medium]},
-]
-
-\protect
-$for(header-includes)$
-$header-includes$
-$endfor$
-
-\starttext
-$if(title)$
-\startalignment[center]
-  \blank[2*big]
-  {\tfd $title$}
-$if(author)$
-  \blank[3*medium]
-  {\tfa $for(author)$$author$$sep$\crlf $endfor$}
-$endif$
-$if(date)$
-  \blank[2*medium]
-  {\tfa $date$}
-$endif$
-  \blank[3*medium]
-\stopalignment
-$endif$
-$for(include-before)$
-$include-before$
-$endfor$
-$if(toc)$
-\placecontent
-$endif$
-
-$body$
-
-$for(include-after)$
-$include-after$
-$endfor$
-\stoptext
diff --git a/templates/default.context b/templates/default.context
new file mode 100644
--- /dev/null
+++ b/templates/default.context
@@ -0,0 +1,84 @@
+\enableregime[utf]  % use UTF-8
+
+\setupcolors[state=start]
+\setupinteraction[state=start, color=middleblue] % needed for hyperlinks
+
+\setuppapersize[letter][letter]  % use letter paper
+\setuplayout[width=middle, backspace=1.5in, cutspace=1.5in,
+             height=middle, header=0.75in, footer=0.75in] % page layout
+\setuppagenumbering[location={footer,center}]  % number pages
+\setupbodyfont[11pt]  % 11pt font
+\setupwhitespace[medium]  % inter-paragraph spacing
+
+\setuphead[section][style=\tfc]
+\setuphead[subsection][style=\tfb]
+\setuphead[subsubsection][style=\bf]
+
+% define descr (for definition lists)
+\definedescription[descr][
+  headstyle=bold,style=normal,align=left,location=hanging,
+  width=broad,margin=1cm]
+
+% prevent orphaned list intros
+\setupitemize[autointro]
+
+% define defaults for bulleted lists 
+\setupitemize[1][symbol=1][indentnext=no]
+\setupitemize[2][symbol=2][indentnext=no]
+\setupitemize[3][symbol=3][indentnext=no]
+\setupitemize[4][symbol=4][indentnext=no]
+
+\setupthinrules[width=15em]  % width of horizontal rules
+
+% for block quotations
+\unprotect
+
+\startvariables all
+blockquote: blockquote
+\stopvariables
+
+\definedelimitedtext
+[\v!blockquote][\v!quotation]
+
+\setupdelimitedtext
+[\v!blockquote]
+[\c!left=,
+\c!right=,
+before={\blank[medium]},
+after={\blank[medium]},
+]
+
+\protect
+$for(header-includes)$
+$header-includes$
+$endfor$
+
+\starttext
+$if(title)$
+\startalignment[center]
+  \blank[2*big]
+  {\tfd $title$}
+$if(author)$
+  \blank[3*medium]
+  {\tfa $for(author)$$author$$sep$\crlf $endfor$}
+$endif$
+$if(date)$
+  \blank[2*medium]
+  {\tfa $date$}
+$endif$
+  \blank[3*medium]
+\stopalignment
+$endif$
+$for(include-before)$
+$include-before$
+$endfor$
+$if(toc)$
+\placecontent
+$endif$
+
+$body$
+
+$for(include-after)$
+$include-after$
+$endfor$
+\stoptext
diff --git a/templates/default.docbook b/templates/default.docbook
new file mode 100644
--- /dev/null
+++ b/templates/default.docbook
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
+                  "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
+<article>
+  <articleinfo>
+    <title>$title$</title>
+$for(author)$
+    <author>
+      $author$
+    </author>
+$endfor$
+$if(date)$
+    <date>$date$</date>
+$endif$
+  </articleinfo>
+$for(include-before)$
+$include-before$
+$endfor$
+$body$
+$for(include-after)$
+$include-after$
+$endfor$
+</article>
diff --git a/templates/default.html b/templates/default.html
new file mode 100644
--- /dev/null
+++ b/templates/default.html
@@ -0,0 +1,86 @@
+$if(html5)$
+<!DOCTYPE html>
+<html$if(lang)$ lang="$lang$"$endif$>
+$else$
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"$if(lang)$ lang="$lang$" xml:lang="$lang$"$endif$>
+$endif$
+<head>
+$if(html5)$
+  <meta charset="utf-8" />
+$else$
+  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+$endif$
+  <meta name="generator" content="pandoc" />
+$for(author)$
+  <meta name="author" content="$author$" />
+$endfor$
+$if(date)$
+  <meta name="date" content="$date$" />
+$endif$
+  <title>$if(title-prefix)$$title-prefix$ - $endif$$if(pagetitle)$$pagetitle$$endif$</title>
+$if(html5)$
+  <!--[if lt IE 9]>
+    <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
+  <![endif]-->
+$endif$
+$if(highlighting-css)$
+  <style type="text/css">
+/*<![CDATA[*/
+$highlighting-css$
+/*]]>*/
+  </style>
+$endif$
+$for(css)$
+  <link rel="stylesheet" href="$css$" $if(html5)$$else$type="text/css" $endif$/>
+$endfor$
+$if(math)$
+$if(html5)$
+$else$
+  $math$
+$endif$
+$endif$
+$for(header-includes)$
+  $header-includes$
+$endfor$
+</head>
+<body>
+$for(include-before)$
+$include-before$
+$endfor$
+$if(title)$
+$if(html5)$
+<header>
+$else$
+<div id="$idprefix$header">
+$endif$
+<h1 class="title">$title$</h1>
+$for(author)$
+<h3 class="author">$author$</h3>
+$endfor$
+$if(date)$
+<h4 class="date">$date$</h4>
+$endif$
+$if(html5)$
+</header>
+$else$
+</div>
+$endif$
+$endif$
+$if(toc)$
+$if(html5)$
+<nav id="$idprefix$TOC">
+$toc$
+</nav>
+$else$
+<div id="$idprefix$TOC">
+$toc$
+</div>
+$endif$
+$endif$
+$body$
+$for(include-after)$
+$include-after$
+$endfor$
+</body>
+</html>
diff --git a/templates/default.latex b/templates/default.latex
new file mode 100644
--- /dev/null
+++ b/templates/default.latex
@@ -0,0 +1,139 @@
+\documentclass$if(fontsize)$[$fontsize$]$endif${article}
+\usepackage{amssymb,amsmath}
+\usepackage{ifxetex,ifluatex}
+\ifxetex
+  \usepackage{fontspec,xltxtra,xunicode}
+  \defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}
+\else
+  \ifluatex
+    \usepackage{fontspec}
+    \defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}
+  \else
+    \usepackage[utf8]{inputenc}
+  \fi
+\fi
+$if(natbib)$
+\usepackage{natbib}
+\bibliographystyle{plainnat}
+$endif$
+$if(biblatex)$
+\usepackage{biblatex}
+$if(biblio-files)$
+\bibliography{$biblio-files$}
+$endif$
+$endif$
+$if(lhs)$
+\usepackage{listings}
+\lstnewenvironment{code}{\lstset{language=Haskell,basicstyle=\small\ttfamily}}{}
+$endif$
+$if(verbatim-in-note)$
+\usepackage{fancyvrb}
+$endif$
+$if(fancy-enums)$
+% Redefine labelwidth for lists; otherwise, the enumerate package will cause
+% markers to extend beyond the left margin.
+\makeatletter\AtBeginDocument{%
+  \renewcommand{\@listi}
+    {\setlength{\labelwidth}{4em}}
+}\makeatother
+\usepackage{enumerate}
+$endif$
+$if(tables)$
+\usepackage{ctable}
+\usepackage{float} % provides the H option for float placement
+$endif$
+$if(url)$
+\usepackage{url}
+$endif$
+$if(graphics)$
+\usepackage{graphicx}
+% We will generate all images so they have a width \maxwidth. This means
+% that they will get their normal width if they fit onto the page, but
+% are scaled down if they would overflow the margins.
+\makeatletter
+\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth
+\else\Gin@nat@width\fi}
+\makeatother
+\let\Oldincludegraphics\includegraphics
+\renewcommand{\includegraphics}[1]{\Oldincludegraphics[width=\maxwidth]{#1}}
+$endif$
+\ifxetex
+  \usepackage[setpagesize=false, % page size defined by xetex
+              unicode=false, % unicode breaks when used with xetex
+              xetex]{hyperref}
+\else
+  \usepackage[unicode=true]{hyperref}
+\fi
+\hypersetup{breaklinks=true, pdfborder={0 0 0}}
+$if(strikeout)$
+\usepackage[normalem]{ulem}
+% avoid problems with \sout in headers with hyperref:
+\pdfstringdefDisableCommands{\renewcommand{\sout}{}}
+$endif$
+$if(subscript)$
+\newcommand{\textsubscr}[1]{\ensuremath{_{\scriptsize\textrm{#1}}}}
+$endif$
+\setlength{\parindent}{0pt}
+\setlength{\parskip}{6pt plus 2pt minus 1pt}
+\setlength{\emergencystretch}{3em}  % prevent overfull lines
+$if(listings)$
+\usepackage{listings}
+$endif$
+$if(numbersections)$
+$else$
+\setcounter{secnumdepth}{0}
+$endif$
+$if(verbatim-in-note)$
+\VerbatimFootnotes % allows verbatim text in footnotes
+$endif$
+$for(header-includes)$
+$header-includes$
+$endfor$
+
+$if(title)$
+\title{$title$}
+$endif$
+$if(author)$
+\author{$for(author)$$author$$sep$ \and $endfor$}
+$endif$
+$if(date)$
+\date{$date$}
+$endif$
+
+\begin{document}
+$if(title)$
+\maketitle
+$endif$
+
+$for(include-before)$
+$include-before$
+
+$endfor$
+$if(toc)$
+\tableofcontents
+
+$endif$
+$body$
+
+$if(natbib)$
+$if(biblio-files)$
+$if(biblio-title)$
+$if(book-class)$
+\renewcommand\bibname{$biblio-title$}
+$else$
+\renewcommand\refname{$biblio-title$}
+$endif$
+$endif$
+\bibliography{$biblio-files$}
+
+$endif$
+$endif$
+$if(biblatex)$
+\printbibliography$if(biblio-title)$[title=$biblio-title$]$endif$
+
+$endif$
+$for(include-after)$
+$include-after$
+
+$endfor$
+\end{document}
diff --git a/templates/default.man b/templates/default.man
new file mode 100644
--- /dev/null
+++ b/templates/default.man
@@ -0,0 +1,18 @@
+$if(has-tables)$
+.\"t
+$endif$
+.TH $title$ $section$ "$date$" $description$
+$for(header-includes)$
+$header-includes$
+$endfor$
+$for(include-before)$
+$include-before$
+$endfor$
+$body$
+$for(include-after)$
+$include-after$
+$endfor$
+$if(author)$
+.SH AUTHORS
+$for(author)$$author$$sep$; $endfor$.
+$endif$
diff --git a/templates/default.markdown b/templates/default.markdown
new file mode 100644
--- /dev/null
+++ b/templates/default.markdown
@@ -0,0 +1,23 @@
+$if(titleblock)$
+% $title$
+% $for(author)$$author$$sep$; $endfor$
+% $date$
+
+$endif$
+$for(header-includes)$
+$header-includes$
+
+$endfor$
+$for(include-before)$
+$include-before$
+
+$endfor$
+$if(toc)$
+$toc$
+
+$endif$
+$body$
+$for(include-after)$
+
+$include-after$
+$endfor$
diff --git a/templates/default.mediawiki b/templates/default.mediawiki
new file mode 100644
--- /dev/null
+++ b/templates/default.mediawiki
@@ -0,0 +1,13 @@
+$for(include-before)$
+$include-before$
+
+$endfor$
+$if(toc)$
+__TOC__
+
+$endif$
+$body$
+$for(include-after)$
+
+$include-after$
+$endfor$
diff --git a/templates/default.opendocument b/templates/default.opendocument
new file mode 100644
--- /dev/null
+++ b/templates/default.opendocument
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" office:version="1.0">
+  $automatic-styles$
+$for(header-includes)$
+  $header-includes$
+$endfor$  
+<office:body>
+<office:text>
+$if(title)$
+<text:h text:style-name="Heading_20_1" text:outline-level="1">$title$</text:h>
+$endif$
+$for(author)$
+<text:p text:style-name="Author">$author$</text:p>
+$endfor$
+$if(date)$
+<text:p text:style-name="Date">$date$</text:p>
+$endif$
+$for(include-before)$
+$include-before$
+$endfor$
+$body$
+$for(include-after)$
+$include-after$
+$endfor$
+</office:text>
+</office:body>
+</office:document-content>
diff --git a/templates/default.org b/templates/default.org
new file mode 100644
--- /dev/null
+++ b/templates/default.org
@@ -0,0 +1,24 @@
+$if(title)$
+$title$
+
+$endif$
+$if(author)$
+#+AUTHOR: $for(author)$$author$$sep$; $endfor$
+$endif$
+$if(date)$
+#+DATE: $date$
+
+$endif$
+$for(header-includes)$
+$header-includes$
+
+$endfor$
+$for(include-before)$
+$include-before$
+
+$endfor$
+$body$
+$for(include-after)$
+
+$include-after$
+$endfor$
diff --git a/templates/default.plain b/templates/default.plain
new file mode 100644
--- /dev/null
+++ b/templates/default.plain
@@ -0,0 +1,23 @@
+$if(titleblock)$
+$title$
+$for(author)$$author$$sep$; $endfor$
+$date$
+
+$endif$
+$for(header-includes)$
+$header-includes$
+
+$endfor$
+$for(include-before)$
+$include-before$
+
+$endfor$
+$if(toc)$
+$toc$
+
+$endif$
+$body$
+$for(include-after)$
+
+$include-after$
+$endfor$
diff --git a/templates/default.rst b/templates/default.rst
new file mode 100644
--- /dev/null
+++ b/templates/default.rst
@@ -0,0 +1,39 @@
+$if(title)$
+$title$
+
+$endif$
+$for(author)$
+:Author: $author$
+$endfor$
+$if(date)$
+:Date:   $date$
+$endif$
+$if(author)$
+
+$else$
+$if(date)$
+
+$endif$
+$endif$
+$if(math)$
+.. role:: math(raw)
+   :format: html latex
+
+$endif$
+$for(include-before)$
+$include-before$
+
+$endfor$
+$if(toc)$
+.. contents::
+
+$endif$
+$for(header-includes)$
+$header-includes$
+
+$endfor$
+$body$
+$for(include-after)$
+
+$include-after$
+$endfor$
diff --git a/templates/default.rtf b/templates/default.rtf
new file mode 100644
--- /dev/null
+++ b/templates/default.rtf
@@ -0,0 +1,27 @@
+{\rtf1\ansi\deff0{\fonttbl{\f0 \fswiss Helvetica;}{\f1 Courier;}}
+{\colortbl;\red255\green0\blue0;\red0\green0\blue255;}
+\widowctrl\hyphauto
+$for(header-includes)$
+$header-includes$
+$endfor$
+
+$if(title)$
+{\pard \qc \f0 \sa180 \li0 \fi0 \b \fs36 $title$\par}
+$endif$
+$for(author)$
+{\pard \qc \f0 \sa180 \li0 \fi0  $author$\par}
+$endfor$
+$if(date)$
+{\pard \qc \f0 \sa180 \li0 \fi0  $date$\par}
+$endif$
+$if(spacer)$
+{\pard \ql \f0 \sa180 \li0 \fi0 \par}
+$endif$
+$for(include-before)$
+$include-before$
+$endfor$
+$body$
+$for(include-after)$
+$include-after$
+$endfor$
+}
diff --git a/templates/default.s5 b/templates/default.s5
new file mode 100644
--- /dev/null
+++ b/templates/default.s5
@@ -0,0 +1,69 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+  <meta name="generator" content="pandoc" />
+$for(author)$
+  <meta name="author" content="$author$" />
+$endfor$
+$if(date)$
+  <meta name="date" content="$date$" />
+$endif$
+  <title>$if(title-prefix)$$title-prefix$ - $endif$$if(pagetitle)$$pagetitle$$endif$</title>
+  <!-- configuration parameters -->
+  <meta name="defaultView" content="slideshow" />
+  <meta name="controlVis" content="hidden" />
+$if(highlighting-css)$
+  <style type="text/css">
+$highlighting-css$
+  </style>
+$endif$
+$for(css)$
+  <link rel="stylesheet" href="$css$" type="text/css" />
+$endfor$
+$if(s5includes)$
+$s5includes$
+$else$
+  <!-- style sheet links -->
+  <link rel="stylesheet" href="$s5-url$/slides.css" type="text/css" media="projection" id="slideProj" />
+  <link rel="stylesheet" href="$s5-url$/outline.css" type="text/css" media="screen" id="outlineStyle" />
+  <link rel="stylesheet" href="$s5-url$/print.css" type="text/css" media="print" id="slidePrint" />
+  <link rel="stylesheet" href="$s5-url$/opera.css" type="text/css" media="projection" id="operaFix" />
+  <!-- S5 JS -->
+  <script src="$s5-url$/slides.js" type="text/javascript"></script>
+$endif$
+$if(math)$
+  $math$
+$endif$
+$for(header-includes)$
+  $header-includes$
+$endfor$
+</head>
+<body>
+$for(include-before)$
+$include-before$
+$endfor$
+<div class="layout">
+<div id="controls"></div>
+<div id="currentSlide"></div>
+<div id="header"></div>
+<div id="footer">
+  <h1>$date$</h1>
+  <h2>$title$</h2>
+</div>
+</div>
+<div class="presentation">
+$if(title)$
+<div class="slide">
+  <h1>$title$</h1>
+  <h3>$for(author)$$author$$sep$<br/>$endfor$</h3>
+  <h4>$date$</h4>
+</div>
+$endif$
+$body$
+$for(include-after)$
+$include-after$
+$endfor$
+</div>
+</body>
+</html>
diff --git a/templates/default.slidy b/templates/default.slidy
new file mode 100644
--- /dev/null
+++ b/templates/default.slidy
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
+<head>
+  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+  <meta name="generator" content="pandoc" />
+$for(author)$
+  <meta name="author" content="$author$" />
+$endfor$
+$if(date)$
+  <meta name="date" content="$date$" />
+$endif$
+$if(highlighting-css)$
+  <title>$if(title-prefix)$$title-prefix$ - $endif$$if(pagetitle)$$pagetitle$$endif$</title>
+  <style type="text/css">
+/*<![CDATA[*/
+$highlighting-css$
+/*]]>*/
+  </style>
+$endif$
+$if(slidy-css)$
+  <style type="text/css">
+/*<![CDATA[*/
+$slidy-css$
+/*]]>*/
+  </style>
+$else$
+  <link rel="stylesheet" type="text/css" media="screen, projection, print"
+    href="$slidy-url$/styles/slidy.css" />
+$endif$
+$for(css)$
+  <link rel="stylesheet" type="text/css" media="screen, projection, print"
+   href="$css$" />
+$endfor$
+$if(math)$
+  $math$
+$endif$
+$for(header-includes)$
+  $header-includes$
+$endfor$
+$if(slidy-js)$
+<script type="text/javascript" charset="utf-8">
+/*<![CDATA[*/
+$slidy-js$
+/*]]>*/
+</script>
+$else$
+  <script src="$slidy-url$/scripts/slidy.js.gz"
+    charset="utf-8" type="text/javascript"></script>
+$endif$
+$if(duration)$
+  <meta name="duration" content="$duration$" />
+$endif$
+</head>
+<body>
+$for(include-before)$
+$include-before$
+$endfor$
+$if(title)$
+<div class="slide titlepage">
+  <h1 class="title">$title$</h1>
+  <p class="author">
+$for(author)$$author$$sep$<br/>$endfor$
+  </p>
+$if(date)$
+  <p class="date">$date$</p>
+$endif$
+</div>
+$endif$
+$body$
+$for(include-after)$
+$include-after$
+$endfor$
+</body>
+</html>
diff --git a/templates/default.texinfo b/templates/default.texinfo
new file mode 100644
--- /dev/null
+++ b/templates/default.texinfo
@@ -0,0 +1,64 @@
+\input texinfo
+@documentencoding utf-8
+$for(header-includes)$
+$header-includes$
+$endfor$
+
+$if(strikeout)$
+@macro textstrikeout{text}
+~~\text\~~
+@end macro
+
+$endif$
+$if(subscript)$
+@macro textsubscript{text}
+@iftex
+@textsubscript{\text\}
+@end iftex
+@ifnottex
+_@{\text\@}
+@end ifnottex
+@end macro
+
+$endif$
+$if(superscript)$
+@macro textsuperscript{text}
+@iftex
+@textsuperscript{\text\}
+@end iftex
+@ifnottex
+^@{\text\@}
+@end ifnottex
+@end macro
+
+$endif$
+@ifnottex
+@paragraphindent 0
+@end ifnottex
+$if(titlepage)$
+@titlepage
+@title $title$
+$for(author)$
+@author $author$
+$endfor$
+$if(date)$
+$date$
+$endif$
+@end titlepage
+
+$endif$
+$for(include-before)$
+$include-before$
+
+$endfor$
+$if(toc)$
+@contents
+
+$endif$
+$body$
+$for(include-after)$
+
+$include-after$
+$endfor$
+
+@bye
diff --git a/templates/default.textile b/templates/default.textile
new file mode 100644
--- /dev/null
+++ b/templates/default.textile
@@ -0,0 +1,9 @@
+$for(include-before)$
+$include-before$
+
+$endfor$
+$body$
+$for(include-after)$
+
+$include-after$
+$endfor$
diff --git a/templates/docbook.template b/templates/docbook.template
deleted file mode 100644
--- a/templates/docbook.template
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
-                  "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
-<article>
-  <articleinfo>
-    <title>$title$</title>
-$for(author)$
-    <author>
-      $author$
-    </author>
-$endfor$
-$if(date)$
-    <date>$date$</date>
-$endif$
-  </articleinfo>
-$for(include-before)$
-$include-before$
-$endfor$
-$body$
-$for(include-after)$
-$include-after$
-$endfor$
-</article>
diff --git a/templates/html.template b/templates/html.template
deleted file mode 100644
--- a/templates/html.template
+++ /dev/null
@@ -1,66 +0,0 @@
-$if(html5)$
-<!DOCTYPE html>
-<html$if(lang)$ lang="$lang$"$endif$>
-$else$
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml"$if(lang)$ lang="$lang$" xml:lang="$lang$"$endif$>
-$endif$
-<head>
-$if(html5)$
-  <meta charset="utf-8" />
-$else$
-  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-$endif$
-  <meta name="generator" content="pandoc" />
-$for(author)$
-  <meta name="author" content="$author$" />
-$endfor$
-$if(date)$
-  <meta name="date" content="$date$" />
-$endif$
-  <title>$if(title-prefix)$$title-prefix$ - $endif$$if(pagetitle)$$pagetitle$$endif$</title>
-$if(html5)$
-  <!--[if lt IE 9]>
-    <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
-  <![endif]-->
-$endif$
-$if(highlighting-css)$
-  <style type="text/css">
-$highlighting-css$
-  </style>
-$endif$
-$for(css)$
-  <link rel="stylesheet" href="$css$" $if(html5)$$else$type="text/css" $endif$/>
-$endfor$
-$if(math)$
-$if(html5)$
-$else$
-  $math$
-$endif$
-$endif$
-$for(header-includes)$
-  $header-includes$
-$endfor$
-</head>
-<body>
-$for(include-before)$
-$include-before$
-$endfor$
-$if(title)$
-$if(html5)$
-<header>
-$endif$
-<h1 class="title">$title$</h1>
-$if(html5)$
-</header>
-$endif$
-$endif$
-$if(toc)$
-$toc$
-$endif$
-$body$
-$for(include-after)$
-$include-after$
-$endfor$
-</body>
-</html>
diff --git a/templates/latex.template b/templates/latex.template
deleted file mode 100644
--- a/templates/latex.template
+++ /dev/null
@@ -1,130 +0,0 @@
-\documentclass$if(fontsize)$[$fontsize$]$endif${article}
-\usepackage{amssymb,amsmath}
-$if(xetex)$
-\usepackage{ifxetex}
-\ifxetex
-  \usepackage{fontspec,xltxtra,xunicode}
-  \defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}
-\else
-  \usepackage[mathletters]{ucs}
-  \usepackage[utf8x]{inputenc}
-\fi
-$else$
-\usepackage[mathletters]{ucs}
-\usepackage[utf8x]{inputenc}
-$endif$
-$if(natbib)$
-\usepackage{natbib}
-\bibliographystyle{plainnat}
-$endif$
-$if(biblatex)$
-\usepackage{biblatex}
-$if(biblio-files)$
-\bibliography{$biblio-files$}
-$endif$
-$endif$
-$if(lhs)$
-\usepackage{listings}
-\lstnewenvironment{code}{\lstset{language=Haskell,basicstyle=\small\ttfamily}}{}
-$endif$
-$if(verbatim-in-note)$
-\usepackage{fancyvrb}
-$endif$
-$if(fancy-enums)$
-% Redefine labelwidth for lists; otherwise, the enumerate package will cause
-% markers to extend beyond the left margin.
-\makeatletter\AtBeginDocument{%
-  \renewcommand{\@listi}
-    {\setlength{\labelwidth}{4em}}
-}\makeatother
-\usepackage{enumerate}
-$endif$
-$if(tables)$
-\usepackage{ctable}
-\usepackage{float} % provides the H option for float placement
-$endif$
-$if(strikeout)$
-\usepackage[normalem]{ulem}
-% avoid problems with \sout in headers with hyperref:
-\pdfstringdefDisableCommands{\renewcommand{\sout}{}}
-$endif$
-$if(subscript)$
-\newcommand{\textsubscr}[1]{\ensuremath{_{\scriptsize\textrm{#1}}}}
-$endif$
-$if(url)$
-\usepackage{url}
-$endif$
-$if(graphics)$
-\usepackage{graphicx}
-% We will generate all images so they have a width \maxwidth. This means
-% that they will get their normal width if they fit onto the page, but
-% are scaled down if they would overflow the margins.
-\makeatletter
-\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth
-\else\Gin@nat@width\fi}
-\makeatother
-\let\Oldincludegraphics\includegraphics
-\renewcommand{\includegraphics}[1]{\Oldincludegraphics[width=\maxwidth]{#1}}
-$endif$
-\usepackage[breaklinks=true,unicode=true,pdfborder={0 0 0}]{hyperref}
-\setlength{\parindent}{0pt}
-\setlength{\parskip}{6pt plus 2pt minus 1pt}
-$if(listings)$
-\usepackage{listings}
-$endif$
-$if(numbersections)$
-$else$
-\setcounter{secnumdepth}{0}
-$endif$
-$if(verbatim-in-note)$
-\VerbatimFootnotes % allows verbatim text in footnotes
-$endif$
-$for(header-includes)$
-$header-includes$
-$endfor$
-
-$if(title)$
-\title{$title$}
-$endif$
-$if(author)$
-\author{$for(author)$$author$$sep$\\$endfor$}
-$endif$
-$if(date)$
-\date{$date$}
-$endif$
-
-\begin{document}
-$if(title)$
-\maketitle
-$endif$
-
-$for(include-before)$
-$include-before$
-
-$endfor$
-$if(toc)$
-\tableofcontents
-
-$endif$
-$body$
-$if(biblio-files)$
-$if(natbib)$
-$if(biblio-title)$
-$if(book-class)$
-\renewcommand\bibname{$biblio-title$}
-$else$
-\renewcommand\refname{$biblio-title$}
-$endif$
-$endif$
-\bibliography{$biblio-files$}
-$endif$
-$endif$
-$if(biblatex)$
-\printbibliography$if(biblio-title)$[title=$biblio-title$]$endif$
-$endif$
-$for(include-after)$
-
-$include-after$
-$endfor$
-
-\end{document}
diff --git a/templates/man.template b/templates/man.template
deleted file mode 100644
--- a/templates/man.template
+++ /dev/null
@@ -1,18 +0,0 @@
-$if(has-tables)$
-.\"t
-$endif$
-.TH $title$ $section$ "$date$" $description$
-$for(header-includes)$
-$header-includes$
-$endfor$
-$for(include-before)$
-$include-before$
-$endfor$
-$body$
-$for(include-after)$
-$include-after$
-$endfor$
-$if(author)$
-.SH AUTHORS
-$for(author)$$author$$sep$; $endfor$.
-$endif$
diff --git a/templates/markdown.template b/templates/markdown.template
deleted file mode 100644
--- a/templates/markdown.template
+++ /dev/null
@@ -1,23 +0,0 @@
-$if(titleblock)$
-% $title$
-% $for(author)$$author$$sep$; $endfor$
-% $date$
-
-$endif$
-$for(header-includes)$
-$header-includes$
-
-$endfor$
-$for(include-before)$
-$include-before$
-
-$endfor$
-$if(toc)$
-$toc$
-
-$endif$
-$body$
-$for(include-after)$
-
-$include-after$
-$endfor$
diff --git a/templates/mediawiki.template b/templates/mediawiki.template
deleted file mode 100644
--- a/templates/mediawiki.template
+++ /dev/null
@@ -1,13 +0,0 @@
-$for(include-before)$
-$include-before$
-
-$endfor$
-$if(toc)$
-__TOC__
-
-$endif$
-$body$
-$for(include-after)$
-
-$include-after$
-$endfor$
diff --git a/templates/opendocument.template b/templates/opendocument.template
deleted file mode 100644
--- a/templates/opendocument.template
+++ /dev/null
@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" office:version="1.0">
-  $automatic-styles$
-$for(header-includes)$
-  $header-includes$
-$endfor$  
-<office:body>
-<office:text>
-$if(title)$
-<text:h text:style-name="Heading_20_1" text:outline-level="1">$title$</text:h>
-$endif$
-$for(author)$
-<text:p text:style-name="Author">$author$</text:p>
-$endfor$
-$if(date)$
-<text:p text:style-name="Date">$date$</text:p>
-$endif$
-$for(include-before)$
-$include-before$
-$endfor$
-$body$
-$for(include-after)$
-$include-after$
-$endfor$
-</office:text>
-</office:body>
-</office:document-content>
diff --git a/templates/org.template b/templates/org.template
deleted file mode 100644
--- a/templates/org.template
+++ /dev/null
@@ -1,24 +0,0 @@
-$if(title)$
-$title$
-
-$endif$
-$if(author)$
-#+AUTHOR: $for(author)$$author$$sep$; $endfor$
-$endif$
-$if(date)$
-#+DATE: $date$
-
-$endif$
-$for(header-includes)$
-$header-includes$
-
-$endfor$
-$for(include-before)$
-$include-before$
-
-$endfor$
-$body$
-$for(include-after)$
-
-$include-after$
-$endfor$
diff --git a/templates/plain.template b/templates/plain.template
deleted file mode 100644
--- a/templates/plain.template
+++ /dev/null
@@ -1,23 +0,0 @@
-$if(titleblock)$
-$title$
-$for(author)$$author$$sep$; $endfor$
-$date$
-
-$endif$
-$for(header-includes)$
-$header-includes$
-
-$endfor$
-$for(include-before)$
-$include-before$
-
-$endfor$
-$if(toc)$
-$toc$
-
-$endif$
-$body$
-$for(include-after)$
-
-$include-after$
-$endfor$
diff --git a/templates/rst.template b/templates/rst.template
deleted file mode 100644
--- a/templates/rst.template
+++ /dev/null
@@ -1,39 +0,0 @@
-$if(title)$
-$title$
-
-$endif$
-$for(author)$
-:Author: $author$
-$endfor$
-$if(date)$
-:Date:   $date$
-$endif$
-$if(author)$
-
-$else$
-$if(date)$
-
-$endif$
-$endif$
-$if(math)$
-.. role:: math(raw)
-   :format: html latex
-
-$endif$
-$for(include-before)$
-$include-before$
-
-$endfor$
-$if(toc)$
-.. contents::
-
-$endif$
-$for(header-includes)$
-$header-includes$
-
-$endfor$
-$body$
-$for(include-after)$
-
-$include-after$
-$endfor$
diff --git a/templates/rtf.template b/templates/rtf.template
deleted file mode 100644
--- a/templates/rtf.template
+++ /dev/null
@@ -1,27 +0,0 @@
-{\rtf1\ansi\deff0{\fonttbl{\f0 \fswiss Helvetica;}{\f1 Courier;}}
-{\colortbl;\red255\green0\blue0;\red0\green0\blue255;}
-\widowctrl\hyphauto
-$for(header-includes)$
-$header-includes$
-$endfor$
-
-$if(title)$
-{\pard \qc \f0 \sa180 \li0 \fi0 \b \fs36 $title$\par}
-$endif$
-$for(author)$
-{\pard \qc \f0 \sa180 \li0 \fi0  $author$\par}
-$endfor$
-$if(date)$
-{\pard \qc \f0 \sa180 \li0 \fi0  $date$\par}
-$endif$
-$if(spacer)$
-{\pard \ql \f0 \sa180 \li0 \fi0 \par}
-$endif$
-$for(include-before)$
-$include-before$
-$endfor$
-$body$
-$for(include-after)$
-$include-after$
-$endfor$
-}
diff --git a/templates/s5.template b/templates/s5.template
deleted file mode 100644
--- a/templates/s5.template
+++ /dev/null
@@ -1,69 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
-<head>
-  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-  <meta name="generator" content="pandoc" />
-$for(author)$
-  <meta name="author" content="$author$" />
-$endfor$
-$if(date)$
-  <meta name="date" content="$date$" />
-$endif$
-  <title>$if(title-prefix)$$title-prefix$ - $endif$$if(pagetitle)$$pagetitle$$endif$</title>
-  <!-- configuration parameters -->
-  <meta name="defaultView" content="slideshow" />
-  <meta name="controlVis" content="hidden" />
-$if(highlighting-css)$
-  <style type="text/css">
-$highlighting-css$
-  </style>
-$endif$
-$for(css)$
-  <link rel="stylesheet" href="$css$" type="text/css" />
-$endfor$
-$if(s5includes)$
-$s5includes$
-$else$
-  <!-- style sheet links -->
-  <link rel="stylesheet" href="ui/default/slides.css" type="text/css" media="projection" id="slideProj" />
-  <link rel="stylesheet" href="ui/default/outline.css" type="text/css" media="screen" id="outlineStyle" />
-  <link rel="stylesheet" href="ui/default/print.css" type="text/css" media="print" id="slidePrint" />
-  <link rel="stylesheet" href="ui/default/opera.css" type="text/css" media="projection" id="operaFix" />
-  <!-- S5 JS -->
-  <script src="ui/default/slides.js" type="text/javascript"></script>
-$endif$
-$if(math)$
-  $math$
-$endif$
-$for(header-includes)$
-  $header-includes$
-$endfor$
-</head>
-<body>
-$for(include-before)$
-$include-before$
-$endfor$
-<div class="layout">
-<div id="controls"></div>
-<div id="currentSlide"></div>
-<div id="header"></div>
-<div id="footer">
-  <h1>$date$</h1>
-  <h2>$title$</h2>
-</div>
-</div>
-<div class="presentation">
-$if(title)$
-<div class="slide">
-  <h1>$title$</h1>
-  <h3>$for(author)$$author$$sep$<br/>$endfor$</h3>
-  <h4>$date$</h4>
-</div>
-$endif$
-$body$
-$for(include-after)$
-$include-after$
-$endfor$
-</div>
-</body>
-</html>
diff --git a/templates/slidy.template b/templates/slidy.template
deleted file mode 100644
--- a/templates/slidy.template
+++ /dev/null
@@ -1,70 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
-<head>
-  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-  <meta name="generator" content="pandoc" />
-$for(author)$
-  <meta name="author" content="$author$" />
-$endfor$
-$if(date)$
-  <meta name="date" content="$date$" />
-$endif$
-$if(highlighting-css)$
-  <title>$if(title-prefix)$$title-prefix$ - $endif$$if(pagetitle)$$pagetitle$$endif$</title>
-  <style type="text/css">
-$highlighting-css$
-  </style>
-$endif$
-$if(slidy-css)$
-  <style type="text/css">
-$slidy-css$
-  </style>
-$else$
-  <link rel="stylesheet" type="text/css" media="screen, projection, print"
-    href="http://www.w3.org/Talks/Tools/Slidy2/styles/slidy.css" />
-$endif$
-$for(css)$
-  <link rel="stylesheet" type="text/css" media="screen, projection, print"
-   href="$css$" />
-$endfor$
-$if(math)$
-  $math$
-$endif$
-$for(header-includes)$
-  $header-includes$
-$endfor$
-$if(slidy-js)$
-  <script type="text/javascript" charset="utf-8">
-$slidy-js$
-  </script>
-$else$
-  <script src="http://www.w3.org/Talks/Tools/Slidy2/scripts/slidy.js.gz"
-    charset="utf-8" type="text/javascript"></script>
-$endif$
-$if(duration)$
-  <meta name="duration" content="$duration$" />
-$endif$
-</head>
-<body>
-$for(include-before)$
-$include-before$
-$endfor$
-$if(title)$
-<div class="slide titlepage">
-  <h1 class="title">$title$</h1>
-  <p class="author">
-$for(author)$$author$$sep$<br/>$endfor$
-  </p>
-$if(date)$
-  <p class="date">$date$</p>
-$endif$
-</div>
-$endif$
-$body$
-$for(include-after)$
-$include-after$
-$endfor$
-</body>
-</html>
diff --git a/templates/texinfo.template b/templates/texinfo.template
deleted file mode 100644
--- a/templates/texinfo.template
+++ /dev/null
@@ -1,64 +0,0 @@
-\input texinfo
-@documentencoding utf-8
-$for(header-includes)$
-$header-includes$
-$endfor$
-
-$if(strikeout)$
-@macro textstrikeout{text}
-~~\text\~~
-@end macro
-
-$endif$
-$if(subscript)$
-@macro textsubscript{text}
-@iftex
-@textsubscript{\text\}
-@end iftex
-@ifnottex
-_@{\text\@}
-@end ifnottex
-@end macro
-
-$endif$
-$if(superscript)$
-@macro textsuperscript{text}
-@iftex
-@textsuperscript{\text\}
-@end iftex
-@ifnottex
-^@{\text\@}
-@end ifnottex
-@end macro
-
-$endif$
-@ifnottex
-@paragraphindent 0
-@end ifnottex
-$if(titlepage)$
-@titlepage
-@title $title$
-$for(author)$
-@author $author$
-$endfor$
-$if(date)$
-$date$
-$endif$
-@end titlepage
-
-$endif$
-$for(include-before)$
-$include-before$
-
-$endfor$
-$if(toc)$
-@contents
-
-$endif$
-$body$
-$for(include-after)$
-
-$include-after$
-$endfor$
-
-@bye
diff --git a/templates/textile.template b/templates/textile.template
deleted file mode 100644
--- a/templates/textile.template
+++ /dev/null
@@ -1,9 +0,0 @@
-$for(include-before)$
-$include-before$
-
-$endfor$
-$body$
-$for(include-after)$
-
-$include-after$
-$endfor$
diff --git a/tests/latex-reader.latex b/tests/latex-reader.latex
--- a/tests/latex-reader.latex
+++ b/tests/latex-reader.latex
@@ -17,7 +17,7 @@
 \setcounter{secnumdepth}{0}
 \VerbatimFootnotes % allows verbatim text in footnotes
 \title{Pandoc Test Suite}
-\author{John MacFarlane\\Anonymous}
+\author{John MacFarlane \and Anonymous}
 \date{July 17, 2006}
 \begin{document}
 \maketitle
diff --git a/tests/lhs-test.html b/tests/lhs-test.html
--- a/tests/lhs-test.html
+++ b/tests/lhs-test.html
@@ -5,6 +5,7 @@
   <meta name="generator" content="pandoc" />
   <title></title>
   <style type="text/css">
+/*<![CDATA[*/
 table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode, table.sourceCode pre 
    { margin: 0; padding: 0; border: 0; vertical-align: baseline; border: none; }
 td.lineNumbers { border-right: 1px solid #AAAAAA; text-align: right; color: #AAAAAA; padding-right: 5px; padding-left: 5px; }
@@ -22,6 +23,7 @@
 code.sourceCode span.fu { color: #06287e; }
 code.sourceCode span.re { }
 code.sourceCode span.er { color: red; font-weight: bold; }
+/*]]>*/
   </style>
 </head>
 <body>
diff --git a/tests/lhs-test.html+lhs b/tests/lhs-test.html+lhs
--- a/tests/lhs-test.html+lhs
+++ b/tests/lhs-test.html+lhs
@@ -5,6 +5,7 @@
   <meta name="generator" content="pandoc" />
   <title></title>
   <style type="text/css">
+/*<![CDATA[*/
 table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode, table.sourceCode pre 
    { margin: 0; padding: 0; border: 0; vertical-align: baseline; border: none; }
 td.lineNumbers { border-right: 1px solid #AAAAAA; text-align: right; color: #AAAAAA; padding-right: 5px; padding-left: 5px; }
@@ -22,6 +23,7 @@
 code.sourceCode span.fu { color: #06287e; }
 code.sourceCode span.re { }
 code.sourceCode span.er { color: red; font-weight: bold; }
+/*]]>*/
   </style>
 </head>
 <body>
diff --git a/tests/lhs-test.latex b/tests/lhs-test.latex
--- a/tests/lhs-test.latex
+++ b/tests/lhs-test.latex
@@ -1,10 +1,28 @@
 \documentclass{article}
 \usepackage{amssymb,amsmath}
-\usepackage[mathletters]{ucs}
-\usepackage[utf8x]{inputenc}
-\usepackage[breaklinks=true,unicode=true,pdfborder={0 0 0}]{hyperref}
+\usepackage{ifxetex,ifluatex}
+\ifxetex
+  \usepackage{fontspec,xltxtra,xunicode}
+  \defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}
+\else
+  \ifluatex
+    \usepackage{fontspec}
+    \defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}
+  \else
+    \usepackage[utf8]{inputenc}
+  \fi
+\fi
+\ifxetex
+  \usepackage[setpagesize=false, % page size defined by xetex
+              unicode=false, % unicode breaks when used with xetex
+              xetex]{hyperref}
+\else
+  \usepackage[unicode=true]{hyperref}
+\fi
+\hypersetup{breaklinks=true, pdfborder={0 0 0}}
 \setlength{\parindent}{0pt}
 \setlength{\parskip}{6pt plus 2pt minus 1pt}
+\setlength{\emergencystretch}{3em}  % prevent overfull lines
 \setcounter{secnumdepth}{0}
 
 
@@ -12,7 +30,7 @@
 
 \section{lhs test}
 
-\verb!unsplit! is an arrow that takes a pair of values and combines them to
+\texttt{unsplit} is an arrow that takes a pair of values and combines them to
 return a single value:
 
 \begin{verbatim}
@@ -20,9 +38,9 @@
 unsplit = arr . uncurry       
           -- arr (\op (x,y) -> x `op` y) 
 \end{verbatim}
-\verb!(***)! combines two arrows into a new arrow by running the two arrows on
-a pair of values (one arrow on the first item of the pair and one arrow on the
-second item of the pair).
+\texttt{(***)} combines two arrows into a new arrow by running the two arrows
+on a pair of values (one arrow on the first item of the pair and one arrow on
+the second item of the pair).
 
 \begin{verbatim}
 f *** g = first f >>> second g
diff --git a/tests/lhs-test.latex+lhs b/tests/lhs-test.latex+lhs
--- a/tests/lhs-test.latex+lhs
+++ b/tests/lhs-test.latex+lhs
@@ -1,12 +1,30 @@
 \documentclass{article}
 \usepackage{amssymb,amsmath}
-\usepackage[mathletters]{ucs}
-\usepackage[utf8x]{inputenc}
+\usepackage{ifxetex,ifluatex}
+\ifxetex
+  \usepackage{fontspec,xltxtra,xunicode}
+  \defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}
+\else
+  \ifluatex
+    \usepackage{fontspec}
+    \defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}
+  \else
+    \usepackage[utf8]{inputenc}
+  \fi
+\fi
 \usepackage{listings}
 \lstnewenvironment{code}{\lstset{language=Haskell,basicstyle=\small\ttfamily}}{}
-\usepackage[breaklinks=true,unicode=true,pdfborder={0 0 0}]{hyperref}
+\ifxetex
+  \usepackage[setpagesize=false, % page size defined by xetex
+              unicode=false, % unicode breaks when used with xetex
+              xetex]{hyperref}
+\else
+  \usepackage[unicode=true]{hyperref}
+\fi
+\hypersetup{breaklinks=true, pdfborder={0 0 0}}
 \setlength{\parindent}{0pt}
 \setlength{\parskip}{6pt plus 2pt minus 1pt}
+\setlength{\emergencystretch}{3em}  % prevent overfull lines
 \setcounter{secnumdepth}{0}
 
 
@@ -14,7 +32,7 @@
 
 \section{lhs test}
 
-\verb!unsplit! is an arrow that takes a pair of values and combines them to
+\texttt{unsplit} is an arrow that takes a pair of values and combines them to
 return a single value:
 
 \begin{code}
@@ -22,9 +40,9 @@
 unsplit = arr . uncurry       
           -- arr (\op (x,y) -> x `op` y) 
 \end{code}
-\verb!(***)! combines two arrows into a new arrow by running the two arrows on
-a pair of values (one arrow on the first item of the pair and one arrow on the
-second item of the pair).
+\texttt{(***)} combines two arrows into a new arrow by running the two arrows
+on a pair of values (one arrow on the first item of the pair and one arrow on
+the second item of the pair).
 
 \begin{verbatim}
 f *** g = first f >>> second g
diff --git a/tests/s5.fancy.html b/tests/s5.fancy.html
--- a/tests/s5.fancy.html
+++ b/tests/s5.fancy.html
@@ -17,7 +17,8 @@
   <link rel="stylesheet" href="ui/default/opera.css" type="text/css" media="projection" id="operaFix" />
   <!-- S5 JS -->
   <script src="ui/default/slides.js" type="text/javascript"></script>
-  <script type="text/javascript">/*
+  <script type="text/javascript">/*<![CDATA[*/
+  /*
   LaTeXMathML.js from http://math.etsu.edu/LaTeXMathML/
   Adapted by Jeff Knisely and Douglas Woodall from ASCIIMathML.js v. 1.4.7,
   (c) 2005 Peter Jipsen http://www.chapman.edu/~jipsen.
@@ -215,6 +216,7 @@
   {existing();generic();};}
   else
   {window.onload=generic;}}
+  /*]]>*/
   </script>
 </head>
 <body>
diff --git a/tests/s5.inserts.html b/tests/s5.inserts.html
--- a/tests/s5.inserts.html
+++ b/tests/s5.inserts.html
@@ -12,7 +12,12 @@
 </head>
 <body>
 STUFF INSERTED
+<div id="header">
 <h1 class="title">My S5 Document</h1>
+<h3 class="author">Sam Smith</h3>
+<h3 class="author">Jen Jones</h3>
+<h4 class="date">July 15, 2006</h4>
+</div>
 <h1 id="first-slide">First slide</h1>
 <ul>
 <li>first bullet</li>
diff --git a/tests/tables.docbook b/tests/tables.docbook
--- a/tests/tables.docbook
+++ b/tests/tables.docbook
@@ -2,401 +2,431 @@
   Simple table with caption:
 </para>
 <table>
-  <caption>
+  <title>
     Demonstration of simple table syntax.
-  </caption>
-  <thead>
-    <tr>
-      <th align="right">
-        Right
-      </th>
-      <th align="left">
-        Left
-      </th>
-      <th align="center">
-        Center
-      </th>
-      <th align="left">
-        Default
-      </th>
-    </tr>
-  </thead>
-  <tbody>
-    <tr>
-      <td align="right">
-        12
-      </td>
-      <td align="left">
-        12
-      </td>
-      <td align="center">
-        12
-      </td>
-      <td align="left">
-        12
-      </td>
-    </tr>
-    <tr>
-      <td align="right">
-        123
-      </td>
-      <td align="left">
-        123
-      </td>
-      <td align="center">
-        123
-      </td>
-      <td align="left">
-        123
-      </td>
-    </tr>
-    <tr>
-      <td align="right">
-        1
-      </td>
-      <td align="left">
-        1
-      </td>
-      <td align="center">
-        1
-      </td>
-      <td align="left">
-        1
-      </td>
-    </tr>
-  </tbody>
+  </title>
+  <tgroup cols="4">
+    <colspec align="right" />
+    <colspec align="left" />
+    <colspec align="center" />
+    <colspec align="left" />
+    <thead>
+      <row>
+        <entry>
+          Right
+        </entry>
+        <entry>
+          Left
+        </entry>
+        <entry>
+          Center
+        </entry>
+        <entry>
+          Default
+        </entry>
+      </row>
+    </thead>
+    <tbody>
+      <row>
+        <entry>
+          12
+        </entry>
+        <entry>
+          12
+        </entry>
+        <entry>
+          12
+        </entry>
+        <entry>
+          12
+        </entry>
+      </row>
+      <row>
+        <entry>
+          123
+        </entry>
+        <entry>
+          123
+        </entry>
+        <entry>
+          123
+        </entry>
+        <entry>
+          123
+        </entry>
+      </row>
+      <row>
+        <entry>
+          1
+        </entry>
+        <entry>
+          1
+        </entry>
+        <entry>
+          1
+        </entry>
+        <entry>
+          1
+        </entry>
+      </row>
+    </tbody>
+  </tgroup>
 </table>
 <para>
   Simple table without caption:
 </para>
 <informaltable>
-  <thead>
-    <tr>
-      <th align="right">
-        Right
-      </th>
-      <th align="left">
-        Left
-      </th>
-      <th align="center">
-        Center
-      </th>
-      <th align="left">
-        Default
-      </th>
-    </tr>
-  </thead>
-  <tbody>
-    <tr>
-      <td align="right">
-        12
-      </td>
-      <td align="left">
-        12
-      </td>
-      <td align="center">
-        12
-      </td>
-      <td align="left">
-        12
-      </td>
-    </tr>
-    <tr>
-      <td align="right">
-        123
-      </td>
-      <td align="left">
-        123
-      </td>
-      <td align="center">
-        123
-      </td>
-      <td align="left">
-        123
-      </td>
-    </tr>
-    <tr>
-      <td align="right">
-        1
-      </td>
-      <td align="left">
-        1
-      </td>
-      <td align="center">
-        1
-      </td>
-      <td align="left">
-        1
-      </td>
-    </tr>
-  </tbody>
+  <tgroup cols="4">
+    <colspec align="right" />
+    <colspec align="left" />
+    <colspec align="center" />
+    <colspec align="left" />
+    <thead>
+      <row>
+        <entry>
+          Right
+        </entry>
+        <entry>
+          Left
+        </entry>
+        <entry>
+          Center
+        </entry>
+        <entry>
+          Default
+        </entry>
+      </row>
+    </thead>
+    <tbody>
+      <row>
+        <entry>
+          12
+        </entry>
+        <entry>
+          12
+        </entry>
+        <entry>
+          12
+        </entry>
+        <entry>
+          12
+        </entry>
+      </row>
+      <row>
+        <entry>
+          123
+        </entry>
+        <entry>
+          123
+        </entry>
+        <entry>
+          123
+        </entry>
+        <entry>
+          123
+        </entry>
+      </row>
+      <row>
+        <entry>
+          1
+        </entry>
+        <entry>
+          1
+        </entry>
+        <entry>
+          1
+        </entry>
+        <entry>
+          1
+        </entry>
+      </row>
+    </tbody>
+  </tgroup>
 </informaltable>
 <para>
   Simple table indented two spaces:
 </para>
 <table>
-  <caption>
+  <title>
     Demonstration of simple table syntax.
-  </caption>
-  <thead>
-    <tr>
-      <th align="right">
-        Right
-      </th>
-      <th align="left">
-        Left
-      </th>
-      <th align="center">
-        Center
-      </th>
-      <th align="left">
-        Default
-      </th>
-    </tr>
-  </thead>
-  <tbody>
-    <tr>
-      <td align="right">
-        12
-      </td>
-      <td align="left">
-        12
-      </td>
-      <td align="center">
-        12
-      </td>
-      <td align="left">
-        12
-      </td>
-    </tr>
-    <tr>
-      <td align="right">
-        123
-      </td>
-      <td align="left">
-        123
-      </td>
-      <td align="center">
-        123
-      </td>
-      <td align="left">
-        123
-      </td>
-    </tr>
-    <tr>
-      <td align="right">
-        1
-      </td>
-      <td align="left">
-        1
-      </td>
-      <td align="center">
-        1
-      </td>
-      <td align="left">
-        1
-      </td>
-    </tr>
-  </tbody>
+  </title>
+  <tgroup cols="4">
+    <colspec align="right" />
+    <colspec align="left" />
+    <colspec align="center" />
+    <colspec align="left" />
+    <thead>
+      <row>
+        <entry>
+          Right
+        </entry>
+        <entry>
+          Left
+        </entry>
+        <entry>
+          Center
+        </entry>
+        <entry>
+          Default
+        </entry>
+      </row>
+    </thead>
+    <tbody>
+      <row>
+        <entry>
+          12
+        </entry>
+        <entry>
+          12
+        </entry>
+        <entry>
+          12
+        </entry>
+        <entry>
+          12
+        </entry>
+      </row>
+      <row>
+        <entry>
+          123
+        </entry>
+        <entry>
+          123
+        </entry>
+        <entry>
+          123
+        </entry>
+        <entry>
+          123
+        </entry>
+      </row>
+      <row>
+        <entry>
+          1
+        </entry>
+        <entry>
+          1
+        </entry>
+        <entry>
+          1
+        </entry>
+        <entry>
+          1
+        </entry>
+      </row>
+    </tbody>
+  </tgroup>
 </table>
 <para>
   Multiline table with caption:
 </para>
 <table>
-  <caption>
+  <title>
     Here's the caption. It may span multiple lines.
-  </caption>
-  <col width="15%" />
-  <col width="13%" />
-  <col width="16%" />
-  <col width="33%" />
-  <thead>
-    <tr>
-      <th align="center">
-        Centered Header
-      </th>
-      <th align="left">
-        Left Aligned
-      </th>
-      <th align="right">
-        Right Aligned
-      </th>
-      <th align="left">
-        Default aligned
-      </th>
-    </tr>
-  </thead>
-  <tbody>
-    <tr>
-      <td align="center">
-        First
-      </td>
-      <td align="left">
-        row
-      </td>
-      <td align="right">
-        12.0
-      </td>
-      <td align="left">
-        Example of a row that spans multiple lines.
-      </td>
-    </tr>
-    <tr>
-      <td align="center">
-        Second
-      </td>
-      <td align="left">
-        row
-      </td>
-      <td align="right">
-        5.0
-      </td>
-      <td align="left">
-        Here's another one. Note the blank line between rows.
-      </td>
-    </tr>
-  </tbody>
+  </title>
+  <tgroup cols="4">
+    <colspec colwidth="15*" align="center" />
+    <colspec colwidth="13*" align="left" />
+    <colspec colwidth="16*" align="right" />
+    <colspec colwidth="33*" align="left" />
+    <thead>
+      <row>
+        <entry>
+          Centered Header
+        </entry>
+        <entry>
+          Left Aligned
+        </entry>
+        <entry>
+          Right Aligned
+        </entry>
+        <entry>
+          Default aligned
+        </entry>
+      </row>
+    </thead>
+    <tbody>
+      <row>
+        <entry>
+          First
+        </entry>
+        <entry>
+          row
+        </entry>
+        <entry>
+          12.0
+        </entry>
+        <entry>
+          Example of a row that spans multiple lines.
+        </entry>
+      </row>
+      <row>
+        <entry>
+          Second
+        </entry>
+        <entry>
+          row
+        </entry>
+        <entry>
+          5.0
+        </entry>
+        <entry>
+          Here's another one. Note the blank line between rows.
+        </entry>
+      </row>
+    </tbody>
+  </tgroup>
 </table>
 <para>
   Multiline table without caption:
 </para>
 <informaltable>
-  <col width="15%" />
-  <col width="13%" />
-  <col width="16%" />
-  <col width="33%" />
-  <thead>
-    <tr>
-      <th align="center">
-        Centered Header
-      </th>
-      <th align="left">
-        Left Aligned
-      </th>
-      <th align="right">
-        Right Aligned
-      </th>
-      <th align="left">
-        Default aligned
-      </th>
-    </tr>
-  </thead>
-  <tbody>
-    <tr>
-      <td align="center">
-        First
-      </td>
-      <td align="left">
-        row
-      </td>
-      <td align="right">
-        12.0
-      </td>
-      <td align="left">
-        Example of a row that spans multiple lines.
-      </td>
-    </tr>
-    <tr>
-      <td align="center">
-        Second
-      </td>
-      <td align="left">
-        row
-      </td>
-      <td align="right">
-        5.0
-      </td>
-      <td align="left">
-        Here's another one. Note the blank line between rows.
-      </td>
-    </tr>
-  </tbody>
+  <tgroup cols="4">
+    <colspec colwidth="15*" align="center" />
+    <colspec colwidth="13*" align="left" />
+    <colspec colwidth="16*" align="right" />
+    <colspec colwidth="33*" align="left" />
+    <thead>
+      <row>
+        <entry>
+          Centered Header
+        </entry>
+        <entry>
+          Left Aligned
+        </entry>
+        <entry>
+          Right Aligned
+        </entry>
+        <entry>
+          Default aligned
+        </entry>
+      </row>
+    </thead>
+    <tbody>
+      <row>
+        <entry>
+          First
+        </entry>
+        <entry>
+          row
+        </entry>
+        <entry>
+          12.0
+        </entry>
+        <entry>
+          Example of a row that spans multiple lines.
+        </entry>
+      </row>
+      <row>
+        <entry>
+          Second
+        </entry>
+        <entry>
+          row
+        </entry>
+        <entry>
+          5.0
+        </entry>
+        <entry>
+          Here's another one. Note the blank line between rows.
+        </entry>
+      </row>
+    </tbody>
+  </tgroup>
 </informaltable>
 <para>
   Table without column headers:
 </para>
 <informaltable>
-  <tbody>
-    <tr>
-      <td align="right">
-        12
-      </td>
-      <td align="left">
-        12
-      </td>
-      <td align="center">
-        12
-      </td>
-      <td align="right">
-        12
-      </td>
-    </tr>
-    <tr>
-      <td align="right">
-        123
-      </td>
-      <td align="left">
-        123
-      </td>
-      <td align="center">
-        123
-      </td>
-      <td align="right">
-        123
-      </td>
-    </tr>
-    <tr>
-      <td align="right">
-        1
-      </td>
-      <td align="left">
-        1
-      </td>
-      <td align="center">
-        1
-      </td>
-      <td align="right">
-        1
-      </td>
-    </tr>
-  </tbody>
+  <tgroup cols="4">
+    <colspec align="right" />
+    <colspec align="left" />
+    <colspec align="center" />
+    <colspec align="right" />
+    <tbody>
+      <row>
+        <entry>
+          12
+        </entry>
+        <entry>
+          12
+        </entry>
+        <entry>
+          12
+        </entry>
+        <entry>
+          12
+        </entry>
+      </row>
+      <row>
+        <entry>
+          123
+        </entry>
+        <entry>
+          123
+        </entry>
+        <entry>
+          123
+        </entry>
+        <entry>
+          123
+        </entry>
+      </row>
+      <row>
+        <entry>
+          1
+        </entry>
+        <entry>
+          1
+        </entry>
+        <entry>
+          1
+        </entry>
+        <entry>
+          1
+        </entry>
+      </row>
+    </tbody>
+  </tgroup>
 </informaltable>
 <para>
   Multiline table without column headers:
 </para>
 <informaltable>
-  <col width="15%" />
-  <col width="13%" />
-  <col width="16%" />
-  <col width="33%" />
-  <tbody>
-    <tr>
-      <td align="center">
-        First
-      </td>
-      <td align="left">
-        row
-      </td>
-      <td align="right">
-        12.0
-      </td>
-      <td align="left">
-        Example of a row that spans multiple lines.
-      </td>
-    </tr>
-    <tr>
-      <td align="center">
-        Second
-      </td>
-      <td align="left">
-        row
-      </td>
-      <td align="right">
-        5.0
-      </td>
-      <td align="left">
-        Here's another one. Note the blank line between rows.
-      </td>
-    </tr>
-  </tbody>
+  <tgroup cols="4">
+    <colspec colwidth="15*" align="center" />
+    <colspec colwidth="13*" align="left" />
+    <colspec colwidth="16*" align="right" />
+    <colspec colwidth="33*" align="left" />
+    <tbody>
+      <row>
+        <entry>
+          First
+        </entry>
+        <entry>
+          row
+        </entry>
+        <entry>
+          12.0
+        </entry>
+        <entry>
+          Example of a row that spans multiple lines.
+        </entry>
+      </row>
+      <row>
+        <entry>
+          Second
+        </entry>
+        <entry>
+          row
+        </entry>
+        <entry>
+          5.0
+        </entry>
+        <entry>
+          Here's another one. Note the blank line between rows.
+        </entry>
+      </row>
+    </tbody>
+  </tgroup>
 </informaltable>
diff --git a/tests/writer.context b/tests/writer.context
--- a/tests/writer.context
+++ b/tests/writer.context
@@ -490,9 +490,9 @@
 \startdescr{{\em orange}}
   orange fruit
 
-  \starttyping
+\starttyping
 { orange code block }
-  \stoptyping
+\stoptyping
 
   \startblockquote
   orange block quote
@@ -866,9 +866,9 @@
   Subsequent blocks are indented to show that they belong to the footnote (as
   with list items).
 
-  \starttyping
+\starttyping
   { <code> }
-  \stoptyping
+\stoptyping
 
   If you want, you can indent every line, but you can also be lazy and just
   indent the first line of each block.} This should {\em not} be a footnote
diff --git a/tests/writer.docbook b/tests/writer.docbook
--- a/tests/writer.docbook
+++ b/tests/writer.docbook
@@ -84,11 +84,11 @@
     <para>
       Code in a block quote:
     </para>
-    <screen>
+    <programlisting>
 sub status {
     print &quot;working&quot;;
 }
-</screen>
+</programlisting>
     <para>
       A list:
     </para>
@@ -130,7 +130,7 @@
   <para>
     Code:
   </para>
-  <screen>
+  <programlisting>
 ---- (should be four hyphens)
 
 sub status {
@@ -138,15 +138,15 @@
 }
 
 this code block is indented by one tab
-</screen>
+</programlisting>
   <para>
     And:
   </para>
-  <screen>
+  <programlisting>
     this code block is indented by two tabs
 
 These should not be escaped:  \$ \\ \&gt; \[ \{
-</screen>
+</programlisting>
 </section>
 <section id="lists">
   <title>Lists</title>
@@ -742,9 +742,9 @@
         <para>
           orange fruit
         </para>
-        <screen>
+        <programlisting>
 { orange code block }
-</screen>
+</programlisting>
         <blockquote>
           <para>
             orange block quote
@@ -902,17 +902,17 @@
   <para>
     This should be a code block, though:
   </para>
-  <screen>
+  <programlisting>
 &lt;div&gt;
     foo
 &lt;/div&gt;
-</screen>
+</programlisting>
   <para>
     As should this:
   </para>
-  <screen>
+  <programlisting>
 &lt;div&gt;foo&lt;/div&gt;
-</screen>
+</programlisting>
   <para>
     Now, nested:
   </para>
@@ -942,9 +942,9 @@
   <para>
     Code block:
   </para>
-  <screen>
+  <programlisting>
 &lt;!-- Comment --&gt;
-</screen>
+</programlisting>
   <para>
     Just plain comment, with trailing spaces on the line:
   </para>
@@ -952,9 +952,9 @@
   <para>
     Code:
   </para>
-  <screen>
+  <programlisting>
 &lt;hr /&gt;
-</screen>
+</programlisting>
   <para>
     Hr's:
   </para>
@@ -1291,9 +1291,9 @@
     <para>
       This should [not][] be a link.
     </para>
-    <screen>
+    <programlisting>
 [not]: /url
-</screen>
+</programlisting>
     <para>
       Foo <ulink url="/url/">bar</ulink>.
     </para>
@@ -1355,9 +1355,9 @@
       Auto-links should not occur here:
       <literal>&lt;http://example.com/&gt;</literal>
     </para>
-    <screen>
+    <programlisting>
 or here: &lt;http://example.com/&gt;
-</screen>
+</programlisting>
   </section>
 </section>
 <section id="images">
@@ -1398,9 +1398,9 @@
         Subsequent blocks are indented to show that they belong to the
         footnote (as with list items).
       </para>
-      <screen>
+      <programlisting>
   { &lt;code&gt; }
-</screen>
+</programlisting>
       <para>
         If you want, you can indent every line, but you can also be lazy and
         just indent the first line of each block.
diff --git a/tests/writer.html b/tests/writer.html
--- a/tests/writer.html
+++ b/tests/writer.html
@@ -9,7 +9,12 @@
   <title>Pandoc Test Suite</title>
 </head>
 <body>
+<div id="header">
 <h1 class="title">Pandoc Test Suite</h1>
+<h3 class="author">John MacFarlane</h3>
+<h3 class="author">Anonymous</h3>
+<h4 class="date">July 17, 2006</h4>
+</div>
 <p>This is a set of tests for pandoc. Most of them are adapted from John Gruber’s markdown test suite.</p>
 <hr />
 <h1 id="headers">Headers</h1>
@@ -559,15 +564,15 @@
 <div class="footnotes">
 <hr />
 <ol>
-<li id="fn1"><p>Here is the footnote. It can go anywhere after the footnote reference. It need not be placed at the end of the document. <a href="#fnref1" class="footnoteBackLink" title="Jump back to footnote 1">↩</a></p></li>
+<li id="fn1"><p>Here is the footnote. It can go anywhere after the footnote reference. It need not be placed at the end of the document. <a href="#fnref1" class="footnoteBackLink">↩</a></p></li>
 <li id="fn2"><p>Here’s the long note. This one contains multiple blocks.</p>
 <p>Subsequent blocks are indented to show that they belong to the footnote (as with list items).</p>
 <pre><code>  { &lt;code&gt; }
 </code></pre>
-<p>If you want, you can indent every line, but you can also be lazy and just indent the first line of each block. <a href="#fnref2" class="footnoteBackLink" title="Jump back to footnote 2">↩</a></p></li>
-<li id="fn3"><p>This is <em>easier</em> to type. Inline notes may contain <a href="http://google.com">links</a> and <code>]</code> verbatim characters, as well as [bracketed text]. <a href="#fnref3" class="footnoteBackLink" title="Jump back to footnote 3">↩</a></p></li>
-<li id="fn4"><p>In quote. <a href="#fnref4" class="footnoteBackLink" title="Jump back to footnote 4">↩</a></p></li>
-<li id="fn5"><p>In list. <a href="#fnref5" class="footnoteBackLink" title="Jump back to footnote 5">↩</a></p></li>
+<p>If you want, you can indent every line, but you can also be lazy and just indent the first line of each block. <a href="#fnref2" class="footnoteBackLink">↩</a></p></li>
+<li id="fn3"><p>This is <em>easier</em> to type. Inline notes may contain <a href="http://google.com">links</a> and <code>]</code> verbatim characters, as well as [bracketed text]. <a href="#fnref3" class="footnoteBackLink">↩</a></p></li>
+<li id="fn4"><p>In quote. <a href="#fnref4" class="footnoteBackLink">↩</a></p></li>
+<li id="fn5"><p>In list. <a href="#fnref5" class="footnoteBackLink">↩</a></p></li>
 </ol>
 </div>
 </body>
diff --git a/tests/writer.latex b/tests/writer.latex
--- a/tests/writer.latex
+++ b/tests/writer.latex
@@ -1,7 +1,17 @@
 \documentclass{article}
 \usepackage{amssymb,amsmath}
-\usepackage[mathletters]{ucs}
-\usepackage[utf8x]{inputenc}
+\usepackage{ifxetex,ifluatex}
+\ifxetex
+  \usepackage{fontspec,xltxtra,xunicode}
+  \defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}
+\else
+  \ifluatex
+    \usepackage{fontspec}
+    \defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}
+  \else
+    \usepackage[utf8]{inputenc}
+  \fi
+\fi
 \usepackage{fancyvrb}
 % Redefine labelwidth for lists; otherwise, the enumerate package will cause
 % markers to extend beyond the left margin.
@@ -10,10 +20,6 @@
     {\setlength{\labelwidth}{4em}}
 }\makeatother
 \usepackage{enumerate}
-\usepackage[normalem]{ulem}
-% avoid problems with \sout in headers with hyperref:
-\pdfstringdefDisableCommands{\renewcommand{\sout}{}}
-\newcommand{\textsubscr}[1]{\ensuremath{_{\scriptsize\textrm{#1}}}}
 \usepackage{url}
 \usepackage{graphicx}
 % We will generate all images so they have a width \maxwidth. This means
@@ -25,14 +31,26 @@
 \makeatother
 \let\Oldincludegraphics\includegraphics
 \renewcommand{\includegraphics}[1]{\Oldincludegraphics[width=\maxwidth]{#1}}
-\usepackage[breaklinks=true,unicode=true,pdfborder={0 0 0}]{hyperref}
+\ifxetex
+  \usepackage[setpagesize=false, % page size defined by xetex
+              unicode=false, % unicode breaks when used with xetex
+              xetex]{hyperref}
+\else
+  \usepackage[unicode=true]{hyperref}
+\fi
+\hypersetup{breaklinks=true, pdfborder={0 0 0}}
+\usepackage[normalem]{ulem}
+% avoid problems with \sout in headers with hyperref:
+\pdfstringdefDisableCommands{\renewcommand{\sout}{}}
+\newcommand{\textsubscr}[1]{\ensuremath{_{\scriptsize\textrm{#1}}}}
 \setlength{\parindent}{0pt}
 \setlength{\parskip}{6pt plus 2pt minus 1pt}
+\setlength{\emergencystretch}{3em}  % prevent overfull lines
 \setcounter{secnumdepth}{0}
 \VerbatimFootnotes % allows verbatim text in footnotes
 
 \title{Pandoc Test Suite}
-\author{John MacFarlane\\Anonymous}
+\author{John MacFarlane \and Anonymous}
 \date{July 17, 2006}
 
 \begin{document}
@@ -558,7 +576,8 @@
 
 So is \textbf{\emph{this}} word.
 
-This is code: \verb!>!, \verb!$!, \verb!\!, \verb!\$!, \verb!<html>!.
+This is code: \texttt{\textgreater{}}, \texttt{\$}, \texttt{\textbackslash{}},
+\texttt{\textbackslash{}\$}, \texttt{\textless{}html\textgreater{}}.
 
 \sout{This is \emph{strikeout}.}
 
@@ -582,7 +601,7 @@
 
 `He said, ``I want to go.''\,' Were you alive in the 70's?
 
-Here is some quoted `\verb!code!' and a
+Here is some quoted `\texttt{code}' and a
 ``\href{http://example.com/?foo=1\&bar=2}{quoted link}''.
 
 Some dashes: one---two --- three---four --- five.
@@ -618,14 +637,14 @@
 
 \begin{itemize}
 \item
-  To get the famous equation, write \verb!$e = mc^2$!.
+  To get the famous equation, write \texttt{\$e = mc\^{}2\$}.
 \item
   \$22,000 is a \emph{lot} of money. So is \$34,000. (It worked if ``lot'' is
   emphasized.)
 \item
   Shoes (\$20) and socks (\$5).
 \item
-  Escaped \verb!$!: \$73 \emph{this should be emphasized} 23\$.
+  Escaped \texttt{\$}: \$73 \emph{this should be emphasized} 23\$.
 \end{itemize}
 Here's a LaTeX table:
 
@@ -777,7 +796,8 @@
 Blockquoted: \url{http://example.com/}
 
 \end{quote}
-Auto-links should not occur here: \verb!<http://example.com/>!
+Auto-links should not occur here:
+\texttt{\textless{}http://example.com/\textgreater{}}
 
 \begin{verbatim}
 or here: <http://example.com/>
@@ -808,15 +828,15 @@
   Subsequent blocks are indented to show that they belong to the footnote (as
   with list items).
 
-  \begin{Verbatim}
+\begin{Verbatim}
   { <code> }
-  \end{Verbatim}
+\end{Verbatim}
   If you want, you can indent every line, but you can also be lazy and just
   indent the first line of each block.} This should \emph{not} be a footnote
 reference, because it contains a space.{[}\^{}my note{]} Here is an inline
 note.\footnote{This is \emph{easier} to type. Inline notes may contain
-  \href{http://google.com}{links} and \verb!]! verbatim characters, as well as
-  {[}bracketed text{]}.}
+  \href{http://google.com}{links} and \texttt{{]}} verbatim characters, as
+  well as {[}bracketed text{]}.}
 
 \begin{quote}
 Notes can go in quotes.\footnote{In quote.}
