@@ -30,7 +30,7 @@ writers.
3030-}
3131module Main where
3232import Text.Pandoc
33−import Text.Pandoc.PDF (tex2pdf)
33+import Text.Pandoc.PDF (tex2pdf, TeXProgram(..))
3434import Text.Pandoc.Shared ( tabFilter, ObfuscationMethod (..), readDataFile,
3535 headerShift, findDataFile, normalize )
3636import Text.Pandoc.SelfContained ( makeSelfContained )
@@ -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"]
86+nonTextFormats = ["odt","docx","epub","pdf"]
8787
8888-- | Data structure for command line options.
8989data Opt = Opt
@@ -709,6 +709,7 @@ defaultWriterName x =
709709 ".epub" -> "epub"
710710 ".org" -> "org"
711711 ".asciidoc" -> "asciidoc"
712+ ".pdf" -> "pdf"
712713 ['.',y] | y `elem` ['1'..'9'] -> "man"
713714 _ -> "html"
714715
@@ -965,20 +966,24 @@ main = do
965966
966967 case lookup writerName' writers of
967968 Nothing | writerName' == "epub" ->
968− writeEPUB epubStylesheet writerOptions doc2
969− >>= B.writeFile (encodeString outputFile)
969+ writeEPUB epubStylesheet writerOptions doc2 >>= writeBinary
970970 | writerName' == "odt" ->
971− writeODT referenceODT writerOptions doc2
972− >>= B.writeFile (encodeString outputFile)
971+ writeODT referenceODT writerOptions doc2 >>= writeBinary
973972 | writerName' == "docx" ->
974− writeDocx referenceDocx writerOptions doc2
975− >>= B.writeFile (encodeString outputFile)
973+ writeDocx referenceDocx writerOptions doc2 >>= writeBinary
974+ | writerName' == "pdf" ->
975+ do res <- tex2pdf PDFLaTeX $ writeLaTeX writerOptions doc2
976+ case res of
977+ Right pdf -> writeBinary pdf
978+ Left err' -> B.hPutStr stderr err' >> B.hPutStr stderr nl
976979 | otherwise -> error $ "Unknown writer: " ++ writerName'
980+ where writeBinary = B.writeFile (encodeString outputFile)
981+ nl = B.singleton 10
977982 Just r -> writerFn outputFile =<< postProcess result
978− where writerFn "-" = UTF8.putStr
979− writerFn f = UTF8.writeFile f
980− result = r writerOptions doc2 ++ ['\n' | not standalone']
981− htmlFormats = ["html","html+lhs","s5","slidy","dzslides"]
982− postProcess = if selfContained && writerName' `elem` htmlFormats
983− then makeSelfContained datadir
984− else return
983+ where writerFn "-" = UTF8.putStr
984+ writerFn f = UTF8.writeFile f
985+ result = r writerOptions doc2 ++ ['\n' | not standalone']
986+ htmlFormats = ["html","html+lhs","s5","slidy","dzslides"]
987+ postProcess = if selfContained && writerName' `elem` htmlFormats
988+ then makeSelfContained datadir
989+ else return