From 26fefa040a7046bbe00e3caf2597f33e65af5986 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 26 Apr 2013 20:33:15 -0700 Subject: [PATCH] PDF: On Windows, create temdir in working directory. Reason: the path to the system temp directory may contain tildes, which causes problems in LaTeX when the username is more than eight characters. Closes #777. --- pandoc.cabal | 2 ++ src/Text/Pandoc/PDF.hs | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/pandoc.cabal b/pandoc.cabal index a4af94321..25461e55f 100644 --- a/pandoc.cabal +++ b/pandoc.cabal @@ -358,6 +358,8 @@ Executable pandoc Ghc-Prof-Options: -auto-all -caf-all -rtsopts else Ghc-Prof-Options: -auto-all -caf-all + if os(windows) + Cpp-options: -D_WINDOWS Default-Language: Haskell98 Default-Extensions: CPP Other-Extensions: PatternGuards, OverloadedStrings, diff --git a/src/Text/Pandoc/PDF.hs b/src/Text/Pandoc/PDF.hs index 4f3f38a14..3227fd0bd 100644 --- a/src/Text/Pandoc/PDF.hs +++ b/src/Text/Pandoc/PDF.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE OverloadedStrings, CPP #-} {- Copyright (C) 2012 John MacFarlane @@ -45,10 +45,18 @@ import Text.Pandoc.UTF8 as UTF8 import Control.Monad (unless) import Data.List (isInfixOf) +withTempDir :: String -> (FilePath -> IO a) -> IO a +withTempDir = +#ifdef _WINDOWS + withTempDirectory "." +#else + withSystemTempDirectory +#endif + tex2pdf :: String -- ^ tex program (pdflatex, lualatex, xelatex) -> String -- ^ latex source -> IO (Either ByteString ByteString) -tex2pdf program source = withSystemTempDirectory "tex2pdf" $ \tmpdir -> +tex2pdf program source = withTempDir "tex2pdf." $ \tmpdir -> tex2pdf' tmpdir program source tex2pdf' :: FilePath -- ^ temp directory for output