@@ -30,23 +30,17 @@ Conversion of LaTeX documents to PDF.
31module Text.Pandoc.PDF ( tex2pdf ) where
31module Text.Pandoc.PDF ( tex2pdf ) where
33−import Data.Char (isDigit)
34import System.IO.Temp
33import System.IO.Temp
35−import Data.Maybe (catMaybes)
36import Data.Char (toLower)
34import Data.Char (toLower)
37import Data.ByteString.Lazy (ByteString)
35import Data.ByteString.Lazy (ByteString)
38import qualified Data.ByteString.Lazy as B
36import qualified Data.ByteString.Lazy as B
39import qualified Data.ByteString.Lazy.Char8 as BC
37import qualified Data.ByteString.Lazy.Char8 as BC
40−import qualified Data.ByteString as BS
41−import System.Exit (ExitCode (..), exitWith)
38+import System.Exit (ExitCode (..))
42import System.FilePath
39import System.FilePath
43import System.Directory
40import System.Directory
44import System.Process
41import System.Process
45−import Control.Exception (tryJust, evaluate)
42+import Control.Exception (evaluate)
46−import Control.Monad.Trans (liftIO)
47−import Control.Monad (guard)
48−import System.IO.Error (isAlreadyExistsError)
49−import System.IO (hClose, stderr, stdout)
43+import System.IO (hClose)
50import Control.Concurrent (putMVar, takeMVar, newEmptyMVar, forkIO)
44import Control.Concurrent (putMVar, takeMVar, newEmptyMVar, forkIO)
51import Text.Pandoc.UTF8 as UTF8
45import Text.Pandoc.UTF8 as UTF8
@@ -54,17 +48,16 @@ tex2pdf :: TeXProgram
54 -> String -- ^ latex source
48 -> String -- ^ latex source
55 -> IO (Either TeXError ByteString)
49 -> IO (Either TeXError ByteString)
56tex2pdf program source = withSystemTempDirectory "tex2pdf" $ \tmpdir ->
50tex2pdf program source = withSystemTempDirectory "tex2pdf" $ \tmpdir ->
57− tex2pdf' 1 tmpdir program source
51+ tex2pdf' tmpdir program source
59−tex2pdf' :: Int -- ^ number of run
60− -> FilePath -- ^ temp directory for output
53+tex2pdf' :: FilePath -- ^ temp directory for output
61 -> TeXProgram
54 -> TeXProgram
62 -> String -- ^ tex source
55 -> String -- ^ tex source
63 -> IO (Either TeXError ByteString)
56 -> IO (Either TeXError ByteString)
64−tex2pdf' run tmpDir program source = do
57+tex2pdf' tmpDir program source = do
65− (exit, log, mbPdf) <- runTeXProgram program 3 tmpDir source
58+ (exit, log', mbPdf) <- runTeXProgram program 3 tmpDir source
66 case (exit, mbPdf) of
59 case (exit, mbPdf) of
67− (ExitFailure ec, _) -> return $ Left $ extractTeXError ec log
60+ (ExitFailure ec, _) -> return $ Left $ extractTeXError ec log'
68 (ExitSuccess, Nothing) -> error "tex2pdf: ExitSuccess but no PDF created!"
61 (ExitSuccess, Nothing) -> error "tex2pdf: ExitSuccess but no PDF created!"
69 (ExitSuccess, Just pdf) -> return $ Right pdf
62 (ExitSuccess, Just pdf) -> return $ Right pdf
@@ -84,13 +77,13 @@ data TeXError = TeXError { exitCode :: Int
84-- parsing output
77-- parsing output
86extractTeXError :: Int -> ByteString -> TeXError
79extractTeXError :: Int -> ByteString -> TeXError
87−extractTeXError ec log = TeXError { exitCode = ec
80+extractTeXError ec log' = TeXError { exitCode = ec
88− , message = extractMsg log
81+ , message = extractMsg log'
89− , fullLog = log }
82+ , fullLog = log' }
91extractMsg :: ByteString -> ByteString
84extractMsg :: ByteString -> ByteString
92−extractMsg log = do
85+extractMsg log' = do
93− let msg' = dropWhile (not . ("!" `BC.isPrefixOf`)) $ BC.lines log
86+ let msg' = dropWhile (not . ("!" `BC.isPrefixOf`)) $ BC.lines log'
94 let (msg'',rest) = break ("l." `BC.isPrefixOf`) msg'
87 let (msg'',rest) = break ("l." `BC.isPrefixOf`) msg'
95 let lineno = take 1 rest
88 let lineno = take 1 rest
96 if not (null msg')
89 if not (null msg')