git.iko.soy/typeable/pandoc
on master help sign in
PDF: use system temp dir and set TEXMFOUTPUT.

Previously the temp directory was created inside the working directory, so that programs like epstopdf.pl would be allowed to run in restricted mode. However, setting TEXMFOUTPUT allows these programs to run in the tmpdir inside the system temp directory. This is a better solution than cd51983. Using the system temp dir prevents problems when pandoc is run inside a synced directory (e.g. dropbox). Partially addresses #1192.

commit737c0a684eaa03774b862ddcaf8c1ad7ef147571 authorJohn MacFarlane <jgm@berkeley.edu> dateSat 2 Feb 2019, 11:31 (8 years ago) parent9225583
1 file changed+5−8
src/Text/Pandoc/PDF.hs+5−8
src/Text/Pandoc/PDF.hs+5−8
@@ -50,7 +50,7 @@ import System.Environment
5050import System.Exit (ExitCode (..))
5151import System.FilePath
5252import System.IO (stdout)
53−import System.IO.Temp (withTempDirectory, withTempFile)
53+import System.IO.Temp (withSystemTempDirectory, withTempFile)
5454#if MIN_VERSION_base(4,8,3)
5555import System.IO.Error (IOError, isDoesNotExistError)
5656#else
@@ -100,14 +100,9 @@ makePDF program pdfargs writer opts doc = do
100100 verbosity <- getVerbosity
101101 liftIO $ ms2pdf verbosity program args source
102102 baseProg -> do
103− -- With context and latex, we create a temp directory within
104− -- the working directory, since pdflatex sometimes tries to
105− -- use tools like epstopdf.pl, which are restricted if run
106− -- on files outside the working directory.
107− let withTemp = withTempDirectory "."
108103 commonState <- getCommonState
109104 verbosity <- getVerbosity
110− liftIO $ withTemp "tex2pdf." $ \tmpdir -> do
105+ liftIO $ withSystemTempDirectory "tex2pdf." $ \tmpdir -> do
111106 source <- runIOorExplode $ do
112107 putCommonState commonState
113108 doc' <- handleImages tmpdir doc
@@ -291,7 +286,9 @@ runTeXProgram verbosity program args runNumber numRuns tmpDir source = do
291286 let texinputs = maybe (tmpDir' ++ sep) ((tmpDir' ++ sep) ++)
292287 $ lookup "TEXINPUTS" env'
293288 let env'' = ("TEXINPUTS", texinputs) :
294− [(k,v) | (k,v) <- env', k /= "TEXINPUTS"]
289+ ("TEXMFOUTPUT", tmpDir') :
290+ [(k,v) | (k,v) <- env'
291+ , k /= "TEXINPUTS" && k /= "TEXMFOUTPUT"]
295292 when (verbosity >= INFO && runNumber == 1) $ do
296293 putStrLn "[makePDF] temp dir:"
297294 putStrLn tmpDir'