@@ -28,10 +28,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2828
2929Conversion of LaTeX documents to PDF.
3030-}
31−module Text.Pandoc.PDF ( TeXProgram(..), tex2pdf ) where
31+module Text.Pandoc.PDF ( tex2pdf ) where
3232
3333import System.IO.Temp
34−import Data.Char (toLower)
3534import Data.ByteString.Lazy (ByteString)
3635import qualified Data.ByteString.Lazy as B
3736import qualified Data.ByteString.Lazy.Char8 as BC
@@ -44,14 +43,14 @@ import System.IO (hClose)
4443import Control.Concurrent (putMVar, takeMVar, newEmptyMVar, forkIO)
4544import Text.Pandoc.UTF8 as UTF8
4645
47−tex2pdf :: TeXProgram
48− -> String -- ^ latex source
46+tex2pdf :: String -- ^ tex program (pdflatex, lualatex, xelatex)
47+ -> String -- ^ latex source
4948 -> IO (Either ByteString ByteString)
5049tex2pdf program source = withSystemTempDirectory "tex2pdf" $ \tmpdir ->
5150 tex2pdf' tmpdir program source
5251
5352tex2pdf' :: FilePath -- ^ temp directory for output
54− -> TeXProgram
53+ -> String -- ^ tex program
5554 -> String -- ^ tex source
5655 -> IO (Either ByteString ByteString)
5756tex2pdf' tmpDir program source = do
@@ -63,14 +62,6 @@ tex2pdf' tmpDir program source = do
6362 (ExitSuccess, Nothing) -> return $ Left msg
6463 (ExitSuccess, Just pdf) -> return $ Right pdf
6564
66−data TeXProgram = PDFLaTeX
67− | XeLaTeX
68− | LuaLaTeX
69− | XeTeX
70− | LuaTeX
71− | PDFTeX
72− deriving (Show, Read)
73−
7465(<>) :: ByteString -> ByteString -> ByteString
7566(<>) = B.append
7667
@@ -102,16 +93,15 @@ hasUndefinedRefs = or . map parseLine . BC.lines
10293-- Run a TeX program on an input bytestring and return (exit code,
10394-- contents of stdout, contents of produced PDF if any). Rerun
10495-- latex as needed to resolve references, but don't run bibtex/biber.
105−runTeXProgram :: TeXProgram -> Int -> FilePath -> String
96+runTeXProgram :: String -> Int -> FilePath -> String
10697 -> IO (ExitCode, ByteString, Maybe ByteString)
10798runTeXProgram program runsLeft tmpDir source = do
108− let programName = map toLower (show program)
10999 withTempFile tmpDir "tex2pdf" $ \file h -> do
110100 UTF8.hPutStr h source
111101 hClose h
112102 let programArgs = ["-halt-on-error", "-interaction", "nonstopmode",
113103 "-output-directory", tmpDir, file]
114− (exit, out, _err) <- readCommand programName programArgs
104+ (exit, out, _err) <- readCommand program programArgs
115105 removeFile file
116106 let pdfFile = replaceDirectory (replaceExtension file ".pdf") tmpDir
117107 pdfExists <- doesFileExist pdfFile