git.iko.soy/typeable/pandoc
on master help sign in
Added `--verbose` flag for debugging output in PDF production.
e3422dcJohn MacFarlane
@@ -230,6 +230,10 @@ General options
230 `epub.css`, `templates`, `slidy`, `slideous`, or `s5` directory
230 `epub.css`, `templates`, `slidy`, `slideous`, or `s5` directory
231 placed in this directory will override pandoc's normal defaults.
231 placed in this directory will override pandoc's normal defaults.
232
232
233+`--verbose`
234+: Give verbose debugging output. Currently this only has an effect
235+ with PDF output.
236+
233`-v`, `--version`
237`-v`, `--version`
234: Print version.
238: Print version.
235
239
pandoc.hs+10−1
@@ -186,6 +186,7 @@ data Opt = Opt
186 , optTOCDepth :: Int -- ^ Number of levels to include in TOC
186 , optTOCDepth :: Int -- ^ Number of levels to include in TOC
187 , optDumpArgs :: Bool -- ^ Output command-line arguments
187 , optDumpArgs :: Bool -- ^ Output command-line arguments
188 , optIgnoreArgs :: Bool -- ^ Ignore command-line arguments
188 , optIgnoreArgs :: Bool -- ^ Ignore command-line arguments
189+ , optVerbose :: Bool -- ^ Verbose diagnostic output
189 , optReferenceLinks :: Bool -- ^ Use reference links in writing markdown, rst
190 , optReferenceLinks :: Bool -- ^ Use reference links in writing markdown, rst
190 , optWrapText :: Bool -- ^ Wrap text
191 , optWrapText :: Bool -- ^ Wrap text
191 , optColumns :: Int -- ^ Line length in characters
192 , optColumns :: Int -- ^ Line length in characters
@@ -246,6 +247,7 @@ defaultOpts = Opt
246 , optTOCDepth = 3
247 , optTOCDepth = 3
247 , optDumpArgs = False
248 , optDumpArgs = False
248 , optIgnoreArgs = False
249 , optIgnoreArgs = False
250+ , optVerbose = False
249 , optReferenceLinks = False
251 , optReferenceLinks = False
250 , optWrapText = True
252 , optWrapText = True
251 , optColumns = 72
253 , optColumns = 72
@@ -858,6 +860,11 @@ options =
858 (\opt -> return opt { optIgnoreArgs = True }))
860 (\opt -> return opt { optIgnoreArgs = True }))
859 "" -- "Ignore command-line arguments."
861 "" -- "Ignore command-line arguments."
860
862
863+ , Option "" ["verbose"]
864+ (NoArg
865+ (\opt -> return opt { optVerbose = True }))
866+ "" -- "Verbose diagnostic output."
867+
861 , Option "v" ["version"]
868 , Option "v" ["version"]
862 (NoArg
869 (NoArg
863 (\_ -> do
870 (\_ -> do
@@ -1061,6 +1068,7 @@ main = do
1061 , optTOCDepth = epubTOCDepth
1068 , optTOCDepth = epubTOCDepth
1062 , optDumpArgs = dumpArgs
1069 , optDumpArgs = dumpArgs
1063 , optIgnoreArgs = ignoreArgs
1070 , optIgnoreArgs = ignoreArgs
1071+ , optVerbose = verbose
1064 , optReferenceLinks = referenceLinks
1072 , optReferenceLinks = referenceLinks
1065 , optWrapText = wrap
1073 , optWrapText = wrap
1066 , optColumns = columns
1074 , optColumns = columns
@@ -1302,7 +1310,8 @@ main = do
1302 writerTOCDepth = epubTOCDepth,
1310 writerTOCDepth = epubTOCDepth,
1303 writerReferenceODT = referenceODT,
1311 writerReferenceODT = referenceODT,
1304 writerReferenceDocx = referenceDocx,
1312 writerReferenceDocx = referenceDocx,
1305− writerMediaBag = media
1313+ writerMediaBag = media,
1314+ writerVerbose = verbose
1306 }
1315 }
1307
1316
1308
1317
src/Text/Pandoc/Options.hs+2
@@ -323,6 +323,7 @@ data WriterOptions = WriterOptions
323 , writerReferenceODT :: Maybe FilePath -- ^ Path to reference ODT if specified
323 , writerReferenceODT :: Maybe FilePath -- ^ Path to reference ODT if specified
324 , writerReferenceDocx :: Maybe FilePath -- ^ Path to reference DOCX if specified
324 , writerReferenceDocx :: Maybe FilePath -- ^ Path to reference DOCX if specified
325 , writerMediaBag :: MediaBag -- ^ Media collected by docx or epub reader
325 , writerMediaBag :: MediaBag -- ^ Media collected by docx or epub reader
326+ , writerVerbose :: Bool -- ^ Verbose debugging output
326 } deriving Show
327 } deriving Show
327
328
328instance Default WriterOptions where
329instance Default WriterOptions where
@@ -366,6 +367,7 @@ instance Default WriterOptions where
366 , writerReferenceODT = Nothing
367 , writerReferenceODT = Nothing
367 , writerReferenceDocx = Nothing
368 , writerReferenceDocx = Nothing
368 , writerMediaBag = mempty
369 , writerMediaBag = mempty
370+ , writerVerbose = False
369 }
371 }
370
372
371-- | Returns True if the given extension is enabled.
373-- | Returns True if the given extension is enabled.
src/Text/Pandoc/PDF.hs+26−9
@@ -36,10 +36,11 @@ import qualified Data.ByteString.Lazy.Char8 as BC
36import qualified Data.ByteString as BS
36import qualified Data.ByteString as BS
37import System.Exit (ExitCode (..))
37import System.Exit (ExitCode (..))
38import System.FilePath
38import System.FilePath
39+import System.IO (stderr, stdout)
39import System.Directory
40import System.Directory
40import Data.Digest.Pure.SHA (showDigest, sha1)
41import Data.Digest.Pure.SHA (showDigest, sha1)
41import System.Environment
42import System.Environment
42−import Control.Monad (unless, (<=<))
43+import Control.Monad (unless, when, (<=<))
43import qualified Control.Exception as E
44import qualified Control.Exception as E
44import Control.Applicative ((<$))
45import Control.Applicative ((<$))
45import Data.List (isInfixOf)
46import Data.List (isInfixOf)
@@ -70,7 +71,7 @@ makePDF :: String -- ^ pdf creator (pdflatex, lualatex, xelatex)
70makePDF program writer opts doc = withTempDir "tex2pdf." $ \tmpdir -> do
71makePDF program writer opts doc = withTempDir "tex2pdf." $ \tmpdir -> do
71 doc' <- handleImages opts tmpdir doc
72 doc' <- handleImages opts tmpdir doc
72 let source = writer opts doc'
73 let source = writer opts doc'
73− tex2pdf' tmpdir program source
74+ tex2pdf' (writerVerbose opts) tmpdir program source
74
75
75handleImages :: WriterOptions
76handleImages :: WriterOptions
76 -> FilePath -- ^ temp dir to store images
77 -> FilePath -- ^ temp dir to store images
@@ -130,15 +131,16 @@ convertImage tmpdir fname =
130 mime = getMimeType fname
131 mime = getMimeType fname
131 doNothing = return (Right fname)
132 doNothing = return (Right fname)
132
133
134+tex2pdf' :: Bool -- ^ Verbose output
133−tex2pdf' :: FilePath -- ^ temp directory for output
135+ -> FilePath -- ^ temp directory for output
134 -> String -- ^ tex program
136 -> String -- ^ tex program
135 -> String -- ^ tex source
137 -> String -- ^ tex source
136 -> IO (Either ByteString ByteString)
138 -> IO (Either ByteString ByteString)
137−tex2pdf' tmpDir program source = do
139+tex2pdf' verbose tmpDir program source = do
138 let numruns = if "\\tableofcontents" `isInfixOf` source
140 let numruns = if "\\tableofcontents" `isInfixOf` source
139 then 3 -- to get page numbers
141 then 3 -- to get page numbers
140 else 2 -- 1 run won't give you PDF bookmarks
142 else 2 -- 1 run won't give you PDF bookmarks
141− (exit, log', mbPdf) <- runTeXProgram program numruns tmpDir source
143+ (exit, log', mbPdf) <- runTeXProgram verbose program 1 numruns tmpDir source
142 case (exit, mbPdf) of
144 case (exit, mbPdf) of
143 (ExitFailure _, _) -> do
145 (ExitFailure _, _) -> do
144 let logmsg = extractMsg log'
146 let logmsg = extractMsg log'
@@ -170,9 +172,9 @@ extractMsg log' = do
170-- Run a TeX program on an input bytestring and return (exit code,
172-- Run a TeX program on an input bytestring and return (exit code,
171-- contents of stdout, contents of produced PDF if any). Rerun
173-- contents of stdout, contents of produced PDF if any). Rerun
172-- a fixed number of times to resolve references.
174-- a fixed number of times to resolve references.
173−runTeXProgram :: String -> Int -> FilePath -> String
175+runTeXProgram :: Bool -> String -> Int -> Int -> FilePath -> String
174 -> IO (ExitCode, ByteString, Maybe ByteString)
176 -> IO (ExitCode, ByteString, Maybe ByteString)
175−runTeXProgram program runsLeft tmpDir source = do
177+runTeXProgram verbose program runNumber numRuns tmpDir source = do
176 let file = tmpDir </> "input.tex"
178 let file = tmpDir </> "input.tex"
177 exists <- doesFileExist file
179 exists <- doesFileExist file
178 unless exists $ UTF8.writeFile file source
180 unless exists $ UTF8.writeFile file source
@@ -192,9 +194,24 @@ runTeXProgram program runsLeft tmpDir source = do
192 $ lookup "TEXINPUTS" env'
194 $ lookup "TEXINPUTS" env'
193 let env'' = ("TEXINPUTS", texinputs) :
195 let env'' = ("TEXINPUTS", texinputs) :
194 [(k,v) | (k,v) <- env', k /= "TEXINPUTS"]
196 [(k,v) | (k,v) <- env', k /= "TEXINPUTS"]
197+ when (verbose && runNumber == 1) $ do
198+ putStrLn $ "[makePDF] Command line:"
199+ putStrLn $ program ++ " " ++ unwords (map show programArgs)
200+ putStr "\n"
201+ putStrLn $ "[makePDF] Environment:"
202+ mapM_ print env''
203+ putStr "\n"
204+ putStrLn $ "[makePDF] Contents of " ++ file' ++ ":"
205+ B.readFile file' >>= B.putStr
206+ putStr "\n"
195 (exit, out, err) <- pipeProcess (Just env'') program programArgs BL.empty
207 (exit, out, err) <- pipeProcess (Just env'') program programArgs BL.empty
196− if runsLeft > 1
208+ when verbose $ do
209+ putStrLn $ "[makePDF] Run #" ++ show runNumber
210+ B.hPutStr stdout out
211+ B.hPutStr stderr err
212+ putStr "\n"
213+ if runNumber <= numRuns
197− then runTeXProgram program (runsLeft - 1) tmpDir source
214+ then runTeXProgram verbose program (runNumber + 1) numRuns tmpDir source
198 else do
215 else do
199 let pdfFile = replaceDirectory (replaceExtension file ".pdf") tmpDir
216 let pdfFile = replaceDirectory (replaceExtension file ".pdf") tmpDir
200 pdfExists <- doesFileExist pdfFile
217 pdfExists <- doesFileExist pdfFile