git.iko.soy/typeable/pandoc
on master help sign in
PDF: Use string instead of special TeXProgram type.
commitd7b67f48cd1b0b33c8777f9b5bb1b6f5608f308f authorJohn MacFarlane <fiddlosopher@gmail.com> dateFri 20 Jan 2012, 21:36 (15 years ago) parent1d61590
2 files changed+8−18
src/Text/Pandoc/PDF.hs+6−16 src/pandoc.hs+2−2
src/Text/Pandoc/PDF.hs+6−16
@@ -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
src/pandoc.hs+2−2
@@ -30,7 +30,7 @@ writers.
3030-}
3131module Main where
3232import Text.Pandoc
33−import Text.Pandoc.PDF (tex2pdf, TeXProgram(..))
33+import Text.Pandoc.PDF (tex2pdf)
3434import Text.Pandoc.Shared ( tabFilter, ObfuscationMethod (..), readDataFile,
3535 headerShift, findDataFile, normalize )
3636import Text.Pandoc.SelfContained ( makeSelfContained )
@@ -972,7 +972,7 @@ main = do
972972 | writerName' == "docx" ->
973973 writeDocx referenceDocx writerOptions doc2 >>= writeBinary
974974 | writerName' == "pdf" ->
975− do res <- tex2pdf PDFLaTeX $ writeLaTeX writerOptions doc2
975+ do res <- tex2pdf "pdflatex" $ writeLaTeX writerOptions doc2
976976 case res of
977977 Right pdf -> writeBinary pdf
978978 Left err' -> B.hPutStr stderr err'