git.iko.soy/typeable/pandoc
on master help sign in
PDF: Use string instead of special TeXProgram type.
d7b67f4John MacFarlane
src/Text/Pandoc/PDF.hs+6−16
@@ -28,10 +28,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28
28
29Conversion of LaTeX documents to PDF.
29Conversion of LaTeX documents to PDF.
30-}
30-}
31−module Text.Pandoc.PDF ( TeXProgram(..), tex2pdf ) where
31+module Text.Pandoc.PDF ( tex2pdf ) where
32
32
33import System.IO.Temp
33import System.IO.Temp
34−import Data.Char (toLower)
35import Data.ByteString.Lazy (ByteString)
34import Data.ByteString.Lazy (ByteString)
36import qualified Data.ByteString.Lazy as B
35import qualified Data.ByteString.Lazy as B
37import qualified Data.ByteString.Lazy.Char8 as BC
36import qualified Data.ByteString.Lazy.Char8 as BC
@@ -44,14 +43,14 @@ import System.IO (hClose)
44import Control.Concurrent (putMVar, takeMVar, newEmptyMVar, forkIO)
43import Control.Concurrent (putMVar, takeMVar, newEmptyMVar, forkIO)
45import Text.Pandoc.UTF8 as UTF8
44import Text.Pandoc.UTF8 as UTF8
46
45
47−tex2pdf :: TeXProgram
46+tex2pdf :: String -- ^ tex program (pdflatex, lualatex, xelatex)
48− -> String -- ^ latex source
47+ -> String -- ^ latex source
49 -> IO (Either ByteString ByteString)
48 -> IO (Either ByteString ByteString)
50tex2pdf program source = withSystemTempDirectory "tex2pdf" $ \tmpdir ->
49tex2pdf program source = withSystemTempDirectory "tex2pdf" $ \tmpdir ->
51 tex2pdf' tmpdir program source
50 tex2pdf' tmpdir program source
52
51
53tex2pdf' :: FilePath -- ^ temp directory for output
52tex2pdf' :: FilePath -- ^ temp directory for output
54− -> TeXProgram
53+ -> String -- ^ tex program
55 -> String -- ^ tex source
54 -> String -- ^ tex source
56 -> IO (Either ByteString ByteString)
55 -> IO (Either ByteString ByteString)
57tex2pdf' tmpDir program source = do
56tex2pdf' tmpDir program source = do
@@ -63,14 +62,6 @@ tex2pdf' tmpDir program source = do
63 (ExitSuccess, Nothing) -> return $ Left msg
62 (ExitSuccess, Nothing) -> return $ Left msg
64 (ExitSuccess, Just pdf) -> return $ Right pdf
63 (ExitSuccess, Just pdf) -> return $ Right pdf
65
64
66−data TeXProgram = PDFLaTeX
67− | XeLaTeX
68− | LuaLaTeX
69− | XeTeX
70− | LuaTeX
71− | PDFTeX
72− deriving (Show, Read)
73−
74(<>) :: ByteString -> ByteString -> ByteString
65(<>) :: ByteString -> ByteString -> ByteString
75(<>) = B.append
66(<>) = B.append
76
67
@@ -102,16 +93,15 @@ hasUndefinedRefs = or . map parseLine . BC.lines
102-- Run a TeX program on an input bytestring and return (exit code,
93-- Run a TeX program on an input bytestring and return (exit code,
103-- contents of stdout, contents of produced PDF if any). Rerun
94-- contents of stdout, contents of produced PDF if any). Rerun
104-- latex as needed to resolve references, but don't run bibtex/biber.
95-- latex as needed to resolve references, but don't run bibtex/biber.
105−runTeXProgram :: TeXProgram -> Int -> FilePath -> String
96+runTeXProgram :: String -> Int -> FilePath -> String
106 -> IO (ExitCode, ByteString, Maybe ByteString)
97 -> IO (ExitCode, ByteString, Maybe ByteString)
107runTeXProgram program runsLeft tmpDir source = do
98runTeXProgram program runsLeft tmpDir source = do
108− let programName = map toLower (show program)
109 withTempFile tmpDir "tex2pdf" $ \file h -> do
99 withTempFile tmpDir "tex2pdf" $ \file h -> do
110 UTF8.hPutStr h source
100 UTF8.hPutStr h source
111 hClose h
101 hClose h
112 let programArgs = ["-halt-on-error", "-interaction", "nonstopmode",
102 let programArgs = ["-halt-on-error", "-interaction", "nonstopmode",
113 "-output-directory", tmpDir, file]
103 "-output-directory", tmpDir, file]
114− (exit, out, _err) <- readCommand programName programArgs
104+ (exit, out, _err) <- readCommand program programArgs
115 removeFile file
105 removeFile file
116 let pdfFile = replaceDirectory (replaceExtension file ".pdf") tmpDir
106 let pdfFile = replaceDirectory (replaceExtension file ".pdf") tmpDir
117 pdfExists <- doesFileExist pdfFile
107 pdfExists <- doesFileExist pdfFile
src/pandoc.hs+2−2
@@ -30,7 +30,7 @@ writers.
30-}
30-}
31module Main where
31module Main where
32import Text.Pandoc
32import Text.Pandoc
33−import Text.Pandoc.PDF (tex2pdf, TeXProgram(..))
33+import Text.Pandoc.PDF (tex2pdf)
34import Text.Pandoc.Shared ( tabFilter, ObfuscationMethod (..), readDataFile,
34import Text.Pandoc.Shared ( tabFilter, ObfuscationMethod (..), readDataFile,
35 headerShift, findDataFile, normalize )
35 headerShift, findDataFile, normalize )
36import Text.Pandoc.SelfContained ( makeSelfContained )
36import Text.Pandoc.SelfContained ( makeSelfContained )
@@ -972,7 +972,7 @@ main = do
972 | writerName' == "docx" ->
972 | writerName' == "docx" ->
973 writeDocx referenceDocx writerOptions doc2 >>= writeBinary
973 writeDocx referenceDocx writerOptions doc2 >>= writeBinary
974 | writerName' == "pdf" ->
974 | writerName' == "pdf" ->
975− do res <- tex2pdf PDFLaTeX $ writeLaTeX writerOptions doc2
975+ do res <- tex2pdf "pdflatex" $ writeLaTeX writerOptions doc2
976 case res of
976 case res of
977 Right pdf -> writeBinary pdf
977 Right pdf -> writeBinary pdf
978 Left err' -> B.hPutStr stderr err'
978 Left err' -> B.hPutStr stderr err'