Give more useful error message if '-t pdf' is specified.

Closes #1155.
This commit is contained in:
John MacFarlane 2014-04-05 23:43:28 -07:00
parent 971e4c4364
commit 11120d619b

View file

@ -1022,17 +1022,15 @@ main = do
let laTeXOutput = "latex" `isPrefixOf` writerName' || let laTeXOutput = "latex" `isPrefixOf` writerName' ||
"beamer" `isPrefixOf` writerName' "beamer" `isPrefixOf` writerName'
when pdfOutput $ do writer <- case getWriter writerName' of
-- make sure writer is latex or beamer Left e -> err 9 $
unless laTeXOutput $ if writerName' == "pdf"
err 47 $ "cannot produce pdf output with " ++ writerName' ++ " writer" then e ++ "\nTo create a pdf with pandoc, use the " ++
-- check for latex program "latex or beamer writer and specify\n" ++
mbLatex <- findExecutable latexEngine "an output file with .pdf extension " ++
case mbLatex of "(pandoc -t latex -o filename.pdf)."
Nothing -> err 41 $ else e
latexEngine ++ " not found. " ++ Right w -> return w
latexEngine ++ " is needed for pdf output."
Just _ -> return ()
reader <- case getReader readerName' of reader <- case getReader readerName' of
Right r -> return r Right r -> return r
@ -1179,12 +1177,22 @@ main = do
writerFn "-" = UTF8.putStr writerFn "-" = UTF8.putStr
writerFn f = UTF8.writeFile f writerFn f = UTF8.writeFile f
case getWriter writerName' of case writer of
Left e -> err 9 e IOStringWriter f -> f writerOptions doc2 >>= writerFn outputFile
Right (IOStringWriter f) -> f writerOptions doc2 >>= writerFn outputFile IOByteStringWriter f -> f writerOptions doc2 >>= writeBinary
Right (IOByteStringWriter f) -> f writerOptions doc2 >>= writeBinary PureStringWriter f
Right (PureStringWriter f)
| pdfOutput -> do | pdfOutput -> do
-- make sure writer is latex or beamer
unless laTeXOutput $
err 47 $ "cannot produce pdf output with " ++ writerName' ++
" writer"
-- check for latex program
mbLatex <- findExecutable latexEngine
when (mbLatex == Nothing) $
err 41 $ latexEngine ++ " not found. " ++
latexEngine ++ " is needed for pdf output."
res <- makePDF latexEngine f writerOptions doc2 res <- makePDF latexEngine f writerOptions doc2
case res of case res of
Right pdf -> writeBinary pdf Right pdf -> writeBinary pdf