aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2013-07-18 21:51:23 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2013-07-18 21:53:34 -0700
commitfd0f8c1a8a03cedf868ea2b26e40bfe00852d0b2 (patch)
treee234d7cc72ce44894d2eeb900a8b88d146a82d76 /src
parent93e096fe1d23bf60a7ca7fa39fa6e730336338eb (diff)
downloadpandoc-fd0f8c1a8a03cedf868ea2b26e40bfe00852d0b2.tar.gz
Text.Pandoc.PDF: put temporary output directory in TEXINPUTS.
This will help later when we try to download external resources. We can put them in the temp directory. See #917.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/PDF.hs16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/Text/Pandoc/PDF.hs b/src/Text/Pandoc/PDF.hs
index 3227fd0bd..b36f2a0af 100644
--- a/src/Text/Pandoc/PDF.hs
+++ b/src/Text/Pandoc/PDF.hs
@@ -38,6 +38,7 @@ import System.Exit (ExitCode (..))
import System.FilePath
import System.Directory
import System.Process
+import System.Environment
import Control.Exception (evaluate)
import System.IO (hClose)
import Control.Concurrent (putMVar, takeMVar, newEmptyMVar, forkIO)
@@ -102,7 +103,12 @@ runTeXProgram program runsLeft tmpDir source = do
unless exists $ UTF8.writeFile file source
let programArgs = ["-halt-on-error", "-interaction", "nonstopmode",
"-output-directory", tmpDir, file]
- (exit, out, err) <- readCommand program programArgs
+ env' <- getEnvironment
+ let texinputs = maybe (tmpDir ++ ":") ((tmpDir ++ ":") ++)
+ $ lookup "TEXINPUTS" env'
+ let env'' = ("TEXINPUTS", texinputs) :
+ [(k,v) | (k,v) <- env', k /= "TEXINPUTS"]
+ (exit, out, err) <- readCommand (Just env'') program programArgs
if runsLeft > 1
then runTeXProgram program (runsLeft - 1) tmpDir source
else do
@@ -118,12 +124,14 @@ runTeXProgram program runsLeft tmpDir source = do
-- Run a command and return exitcode, contents of stdout, and
-- contents of stderr. (Based on
-- 'readProcessWithExitCode' from 'System.Process'.)
-readCommand :: FilePath -- ^ command to run
+readCommand :: Maybe [(String, String)] -- ^ environment variables
+ -> FilePath -- ^ command to run
-> [String] -- ^ any arguments
-> IO (ExitCode,ByteString,ByteString) -- ^ exit, stdout, stderr
-readCommand cmd args = do
+readCommand mbenv cmd args = do
(Just inh, Just outh, Just errh, pid) <-
- createProcess (proc cmd args){ std_in = CreatePipe,
+ createProcess (proc cmd args){ env = mbenv,
+ std_in = CreatePipe,
std_out = CreatePipe,
std_err = CreatePipe }
outMVar <- newEmptyMVar