git.iko.soy/typeable/pandoc
on master help sign in
Made `beamer` an output format, removed `pdf` as output format.

Removed `--beamer` option; instead, use `beamer` as output format. There is no longer a `pdf` output format; instead, pandoc tries to produce a pdf if the output file has a `.pdf` extension. (The output format can be latex -- the default for pdf output, latex+lhs, or beamer.) This seems more consistent with the way pandoc currently works (e.g. we have an `html5` output format, not an `--html5` option).

commit8abe08d6d43b77fe05f3b942a28b0f1a987753bd authorJohn MacFarlane <fiddlosopher@gmail.com> dateSat 28 Jan 2012, 11:41 (15 years ago) parent513af8d
4 files changed+74−78
README+39−49 src/Text/Pandoc.hs+2 src/Text/Pandoc/Templates.hs+1−1 src/pandoc.hs+32−28
README+39−49
@@ -14,11 +14,11 @@ Pandoc is a [Haskell] library for converting from one markup format to
1414another, and a command-line tool that uses this library. It can read
1515[markdown] and (subsets of) [Textile], [reStructuredText], [HTML],
1616and [LaTeX]; and it can write plain text, [markdown], [reStructuredText],
17−[XHTML], [HTML 5], [LaTeX], [ConTeXt], [RTF], [DocBook XML],
18−[OpenDocument XML], [ODT], [Word docx], [GNU Texinfo], [MediaWiki markup], [EPUB],
19−[Textile], [groff man] pages, [Emacs Org-Mode], [AsciiDoc], and [Slidy],
20−[DZSlides], or [S5] HTML slide shows. It can also produce [PDF] output
21−on systems where LaTeX is installed.
17+[XHTML], [HTML 5], [LaTeX] (including [beamer] slide shows),
18+[ConTeXt], [RTF], [DocBook XML], [OpenDocument XML], [ODT], [Word docx], [GNU
19+Texinfo], [MediaWiki markup], [EPUB], [Textile], [groff man] pages, [Emacs
20+Org-Mode], [AsciiDoc], and [Slidy], [DZSlides], or [S5] HTML slide shows. It
21+can also produce [PDF] output on systems where LaTeX is installed.
2222
2323Pandoc's enhanced version of markdown includes syntax for footnotes,
2424tables, flexible ordered lists, definition lists, delimited code blocks,
@@ -42,7 +42,7 @@ If no *input-file* is specified, input is read from *stdin*.
4242Otherwise, the *input-files* are concatenated (with a blank
4343line between each) and used as input. Output goes to *stdout* by
4444default (though output to *stdout* is disabled for the `odt`, `docx`,
45−`pdf`, and `epub` output formats). For output to a file, use the
45+and `epub` output formats). For output to a file, use the
4646`-o` option:
4747
4848 pandoc -o output.html input.txt
@@ -91,23 +91,25 @@ should pipe input and output through `iconv`:
9191
9292 iconv -t utf-8 input.txt | pandoc | iconv -f utf-8
9393
94−`markdown2pdf`
94+Creating a PDF
9595--------------
9696
9797Earlier versions of pandoc came with a program, `markdown2pdf`, that
9898used pandoc and pdflatex to produce a PDF. This is no longer needed,
99−since `pandoc` now has a `pdf` output format, and there is no reason
100−to limit input to markdown. Note that whereas `markdown2pdf` would
101−create an ouput file based on the input file name, `pandoc` requires
102−that you specify the output filename explicitly. So,
99+since `pandoc` can now produce `pdf` output itself. To produce a PDF, simply
100+specify an output file with a `.pdf` extension. Pandoc will create a latex
101+file and use pdflatex (or another engine, see `--latex-engine`) to convert it
102+to PDF:
103103
104− pandoc input.txt -o input.pdf --latex-engine=xelatex
104+ pandoc test.txt -o test.pdf
105105
106−does the same thing
107−
108− markdown2pdf --xetex input.txt
109−
110−used to do.
106+Production of a PDF requires that a LaTeX engine be installed (see
107+`--latex-engine`, below), and assumes that the following LaTeX packages are
108+available: `amssymb`, `amsmath`, `ifxetex`, `ifluatex`, `listings` (if the
109+`--listings` option is used), `fancyvrb`, `enumerate`, `ctable`, `url`,
110+`graphicx`, `hyperref`, `ulem`, `babel` (if the `lang` variable is set),
111+`fontspec` (if `xelatex` or `lualatex` is used as the LaTeX engine), `xltxtra`
112+and `xunicode` (if `xelatex` is used).
111113
112114`hsmarkdown`
113115------------
@@ -144,32 +146,24 @@ General options
144146: Specify output format. *FORMAT* can be `native` (native Haskell),
145147 `json` (JSON version of native AST), `plain` (plain text),
146148 `markdown` (markdown), `rst` (reStructuredText), `html` (XHTML 1),
147− `html5` (HTML 5), `latex` (LaTeX), `context` (ConTeXt),
148− `man` (groff man), `mediawiki` (MediaWiki markup), `textile`
149− (Textile), `org` (Emacs Org-Mode), `texinfo` (GNU Texinfo), `docbook`
150− (DocBook XML), `opendocument` (OpenDocument XML), `odt` (OpenOffice text
151− document), `docx` (Word docx), `epub` (EPUB book), `asciidoc` (AsciiDoc),
152− `slidy` (Slidy HTML and javascript slide show), `dzslides` (HTML5 +
153− javascript slide show), `s5` (S5 HTML and javascript slide show),
154− `rtf` (rich text format), or `pdf` (PDF). Note that `odt` and `epub` output
155− will not be directed to *stdout*; an output filename must be specified
156− using the `-o/--output` option. If `+lhs` is appended to `markdown`, `rst`,
157− `latex`, `html`, or `html5`, the output will be rendered as literate Haskell
158− source: see [Literate Haskell support](#literate-haskell-support), below.
159−
160− Production of `pdf` output requires that a LaTeX engine be installed
161− (see `--latex-engine`, below), and assumes that the following LaTeX
162− packages are available: `amssymb`, `amsmath`, `ifxetex`, `ifluatex`,
163− `listings` (if the `--listings` option is used), `fancyvrb`,
164− `enumerate`, `ctable`, `url`, `graphicx`, `hyperref`, `ulem`,
165− `babel` (if the `lang` variable is set), `fontspec` (if `xelatex`
166− or `lualatex` is used as the LaTeX engine), `xltxtra` and
167− `xunicode` (if `xelatex` is used).
149+ `html5` (HTML 5), `latex` (LaTeX), `beamer` (LaTeX beamer slide show),
150+ `context` (ConTeXt), `man` (groff man), `mediawiki` (MediaWiki markup),
151+ `textile` (Textile), `org` (Emacs Org-Mode), `texinfo` (GNU Texinfo),
152+ `docbook` (DocBook XML), `opendocument` (OpenDocument XML), `odt`
153+ (OpenOffice text document), `docx` (Word docx), `epub` (EPUB book),
154+ `asciidoc` (AsciiDoc), `slidy` (Slidy HTML and javascript slide show),
155+ `dzslides` (HTML5 + javascript slide show), `s5` (S5 HTML and javascript
156+ slide show), or `rtf` (rich text format). Note that `odt` and `epub`
157+ output will not be directed to *stdout*; an output filename must
158+ be specified using the `-o/--output` option. If `+lhs` is appended
159+ to `markdown`, `rst`, `latex`, `html`, or `html5`, the output will
160+ be rendered as literate Haskell source: see [Literate Haskell
161+ support](#literate-haskell-support), below.
168162
169163`-o` *FILE*, `--output=`*FILE*
170164: Write output to *FILE* instead of *stdout*. If *FILE* is
171165 `-`, output will go to *stdout*. (Exception: if the output
172− format is `odt`, `docx`, `pdf`, or `epub`, output to stdout is disabled.)
166+ format is `odt`, `docx`, or `epub`, output to stdout is disabled.)
173167
174168`--data-dir=`*DIRECTORY*
175169: Specify the user data directory to search for pandoc data files.
@@ -248,7 +242,8 @@ General writer options
248242
249243`-s`, `--standalone`
250244: Produce output with an appropriate header and footer (e.g. a
251− standalone HTML, LaTeX, or RTF file, not a fragment).
245+ standalone HTML, LaTeX, or RTF file, not a fragment). This option
246+ is set automatically for `pdf`, `epub`, `docx`, and `odt` output.
252247
253248`--template=`*FILE*
254249: Use *FILE* as a custom template for the generated document. Implies
@@ -359,10 +354,6 @@ Options affecting specific writers
359354`--listings`
360355: Use listings package for LaTeX code blocks
361356
362−`--beamer`
363−: Produce LaTeX output for the `beamer` document class.
364− This has an effect only for `latex` or `pdf` output.
365−
366357`-i`, `--incremental`
367358: Make list items in slide shows display incrementally (one by one).
368359 The default is for lists to be displayed all at once.
@@ -1979,8 +1970,7 @@ Producing slide shows with Pandoc
19791970You can use Pandoc to produce an HTML + javascript slide presentation
19801971that can be viewed via a web browser. There are three ways to do this,
19811972using [S5], [DZSlides], or [Slidy]. You can also produce a PDF slide
1982−show using [LaTeX beamer]: just use the `--beamer` option with `pdf`
1983−output.
1973+show using LaTeX [beamer].
19841974
19851975Here's the markdown source for a simple slide show, `habits.txt`:
19861976
@@ -2030,7 +2020,7 @@ for Slidy,
20302020
20312021for DZSlides, or
20322022
2033− pandoc --beamer habits.txt -o habits.pdf
2023+ pandoc -t beamer habits.txt -o habits.pdf
20342024
20352025for beamer.
20362026
@@ -2110,7 +2100,7 @@ be modified there.
21102100To style beamer slides, you can specify a beamer "theme" or "colortheme"
21112101using the `-V` option:
21122102
2113− pandoc --beamer habits.txt -V theme:Warsaw -o habits.pdf
2103+ pandoc -t beamer habits.txt -V theme:Warsaw -o habits.pdf
21142104
21152105Literate Haskell support
21162106========================
@@ -2177,7 +2167,7 @@ Christopher Sawicki, Kelsey Hightower.
21772167[HTML 5]: http://www.w3.org/TR/html5/
21782168[XHTML]: http://www.w3.org/TR/xhtml1/
21792169[LaTeX]: http://www.latex-project.org/
2180−[LaTeX beamer]: http://www.tex.ac.uk/CTAN/macros/latex/contrib/beamer
2170+[beamer]: http://www.tex.ac.uk/CTAN/macros/latex/contrib/beamer
21812171[ConTeXt]: http://www.pragma-ade.nl/
21822172[RTF]: http://en.wikipedia.org/wiki/Rich_Text_Format
21832173[DocBook XML]: http://www.docbook.org/
src/Text/Pandoc.hs+2
@@ -190,6 +190,8 @@ writers = [("native" , writeNative)
190190 ,("latex" , writeLaTeX)
191191 ,("latex+lhs" , \o ->
192192 writeLaTeX o{ writerLiterateHaskell = True })
193+ ,("beamer" , \o ->
194+ writeLaTeX o{ writerBeamer = True })
193195 ,("context" , writeConTeXt)
194196 ,("texinfo" , writeTexinfo)
195197 ,("man" , writeMan)
src/Text/Pandoc/Templates.hs+1−1
@@ -85,7 +85,7 @@ getDefaultTemplate _ "native" = return $ Right ""
8585getDefaultTemplate _ "json" = return $ Right ""
8686getDefaultTemplate _ "docx" = return $ Right ""
8787getDefaultTemplate user "odt" = getDefaultTemplate user "opendocument"
88−getDefaultTemplate user "pdf" = getDefaultTemplate user "latex"
88+getDefaultTemplate user "beamer" = getDefaultTemplate user "latex"
8989getDefaultTemplate user "epub" = getDefaultTemplate user "html"
9090getDefaultTemplate user writer = do
9191 let format = takeWhile (/='+') writer -- strip off "+lhs" if present
src/pandoc.hs+32−28
@@ -83,7 +83,7 @@ wrapWords indent c = wrap' (c - indent) (c - indent)
8383 else ", " ++ x ++ wrap' cols (remaining - (length x + 2)) xs
8484
8585nonTextFormats :: [String]
86−nonTextFormats = ["odt","docx","epub","pdf"]
86+nonTextFormats = ["odt","docx","epub"]
8787
8888-- | Data structure for command line options.
8989data Opt = Opt
@@ -130,7 +130,6 @@ data Opt = Opt
130130 , optAbbrevsFile :: Maybe FilePath
131131 , optListings :: Bool -- ^ Use listings package for code blocks
132132 , optLaTeXEngine :: String -- ^ Program to use for latex -> pdf
133− , optBeamer :: Bool -- ^ Produce latex output for beamer class
134133 , optSlideLevel :: Maybe Int -- ^ Header level that creates slides
135134 , optSetextHeaders :: Bool -- ^ Use atx headers for markdown level 1-2
136135 }
@@ -181,7 +180,6 @@ defaultOpts = Opt
181180 , optAbbrevsFile = Nothing
182181 , optListings = False
183182 , optLaTeXEngine = "pdflatex"
184− , optBeamer = False
185183 , optSlideLevel = Nothing
186184 , optSetextHeaders = True
187185 }
@@ -436,11 +434,6 @@ options =
436434 (\opt -> return opt { optListings = True }))
437435 "" -- "Use listings package for LaTeX code blocks"
438436
439− , Option "" ["beamer"]
440− (NoArg
441− (\opt -> return opt { optBeamer = True }))
442− "" -- "Produce latex output for beamer class"
443−
444437 , Option "i" ["incremental"]
445438 (NoArg
446439 (\opt -> return opt { optIncremental = True }))
@@ -732,7 +725,7 @@ defaultWriterName x =
732725 ".epub" -> "epub"
733726 ".org" -> "org"
734727 ".asciidoc" -> "asciidoc"
735− ".pdf" -> "pdf"
728+ ".pdf" -> "latex"
736729 ['.',y] | y `elem` ['1'..'9'] -> "man"
737730 _ -> "html"
738731
@@ -815,7 +808,6 @@ main = do
815808 , optCiteMethod = citeMethod
816809 , optListings = listings
817810 , optLaTeXEngine = latexEngine
818− , optBeamer = beamer
819811 , optSlideLevel = slideLevel
820812 , optSetextHeaders = setextHeaders
821813 } = opts
@@ -845,7 +837,13 @@ main = do
845837 then defaultWriterName outputFile
846838 else writerName
847839
848− when (writerName' == "pdf") $ do
840+ let pdfOutput = map toLower (takeExtension outputFile) == ".pdf"
841+
842+ when pdfOutput $ do
843+ -- make sure writer is latex or beamer
844+ unless (writerName' == "latex" || writerName' == "beamer" ||
845+ writerName' == "latex+lhs") $
846+ err 47 $ "cannot produce pdf output with " ++ writerName' ++ " writer"
849847 -- check for latex program
850848 mbLatex <- findExecutable latexEngine
851849 case mbLatex of
@@ -858,7 +856,7 @@ main = do
858856 Just r -> return r
859857 Nothing -> err 7 ("Unknown reader: " ++ readerName')
860858
861− let standalone' = standalone || (`elem` nonTextFormats) writerName'
859+ let standalone' = standalone || writerName' `elem` nonTextFormats || pdfOutput
862860
863861 templ <- case templatePath of
864862 _ | not standalone' -> return ""
@@ -925,13 +923,13 @@ main = do
925923 stateStandalone = standalone',
926924 stateCitations = map CSL.refId refs,
927925 stateSmart = smart || writerName' `elem`
928− ["latex", "context", "latex+lhs", "pdf"],
926+ ["latex", "context", "latex+lhs", "beamer"],
929927 stateOldDashes = oldDashes,
930928 stateColumns = columns,
931929 stateStrict = strict,
932930 stateIndentedCodeClasses = codeBlockClasses,
933931 stateApplyMacros = writerName' `notElem`
934− ["latex", "latex+lhs", "pdf"] }
932+ ["latex", "latex+lhs", "beamer"] }
935933
936934 let writerOptions = defaultWriterOptions
937935 { writerStandalone = standalone',
@@ -965,7 +963,7 @@ main = do
965963 slideVariant == DZSlides,
966964 writerChapters = chapters,
967965 writerListings = listings,
968− writerBeamer = beamer,
966+ writerBeamer = writerName' == "beamer",
969967 writerSlideLevel = slideLevel,
970968 writerHighlight = highlight,
971969 writerHighlightStyle = highlightStyle,
@@ -1013,24 +1011,30 @@ main = do
10131011 processBiblio cslfile' cslabbrevs refs doc1
10141012 else return doc1
10151013
1014+ let writeBinary :: B.ByteString -> IO ()
1015+ writeBinary = B.writeFile (encodeString outputFile)
1016+
1017+ let writerFn :: FilePath -> String -> IO ()
1018+ writerFn "-" = UTF8.putStr
1019+ writerFn f = UTF8.writeFile f
1020+
10161021 case lookup writerName' writers of
1017− Nothing | writerName' == "epub" ->
1018− writeEPUB epubStylesheet writerOptions doc2 >>= writeBinary
1019− | writerName' == "odt" ->
1020− writeODT referenceODT writerOptions doc2 >>= writeBinary
1021− | writerName' == "docx" ->
1022− writeDocx referenceDocx writerOptions doc2 >>= writeBinary
1023− | writerName' == "pdf" ->
1024− do res <- tex2pdf latexEngine $ writeLaTeX writerOptions doc2
1022+ Nothing
1023+ | writerName' == "epub" ->
1024+ writeEPUB epubStylesheet writerOptions doc2 >>= writeBinary
1025+ | writerName' == "odt" ->
1026+ writeODT referenceODT writerOptions doc2 >>= writeBinary
1027+ | writerName' == "docx" ->
1028+ writeDocx referenceDocx writerOptions doc2 >>= writeBinary
1029+ | otherwise -> err 9 ("Unknown writer: " ++ writerName')
1030+ Just _
1031+ | pdfOutput -> do
1032+ res <- tex2pdf latexEngine $ writeLaTeX writerOptions doc2
10251033 case res of
10261034 Right pdf -> writeBinary pdf
10271035 Left err' -> err 43 $ toString err'
1028− | otherwise -> err 9 ("Unknown writer: " ++ writerName')
1029− where writeBinary = B.writeFile (encodeString outputFile)
10301036 Just r -> writerFn outputFile =<< postProcess result
1031− where writerFn "-" = UTF8.putStr
1032− writerFn f = UTF8.writeFile f
1033− result = r writerOptions doc2 ++ ['\n' | not standalone']
1037+ where result = r writerOptions doc2 ++ ['\n' | not standalone']
10341038 htmlFormats = ["html","html+lhs","s5","slidy","dzslides"]
10351039 postProcess = if selfContained && writerName' `elem` htmlFormats
10361040 then makeSelfContained datadir