@@ -44,10 +44,10 @@ runPandoc inputs output = do
44 ++ inputs ++ ["-o", texFile]
44 ++ inputs ++ ["-o", texFile]
45 return $ either Left (const $ Right texFile) result
45 return $ either Left (const $ Right texFile) result
47−runLatexRaw :: FilePath -> IO (Either (Either String String) FilePath)
47+runLatexRaw :: String -> FilePath -> IO (Either (Either String String) FilePath)
48−runLatexRaw file = do
48+runLatexRaw latexProgram file = do
49 -- we ignore the ExitCode because pdflatex always fails the first time
49 -- we ignore the ExitCode because pdflatex always fails the first time
50− run "pdflatex" ["-interaction=batchmode", "-output-directory",
50+ run latexProgram ["-interaction=batchmode", "-output-directory",
51 takeDirectory file, dropExtension file] >> return ()
51 takeDirectory file, dropExtension file] >> return ()
52 let pdfFile = replaceExtension file "pdf"
52 let pdfFile = replaceExtension file "pdf"
53 let logFile = replaceExtension file "log"
53 let logFile = replaceExtension file "log"
@@ -61,11 +61,11 @@ runLatexRaw file = do
61 (False, _ , True, msg) -> return $ Left $ Right msg -- references
61 (False, _ , True, msg) -> return $ Left $ Right msg -- references
62 (False, False, False, _ ) -> return $ Right pdfFile -- success
62 (False, False, False, _ ) -> return $ Right pdfFile -- success
64−runLatex :: FilePath -> IO (Either String FilePath)
64+runLatex :: String -> FilePath -> IO (Either String FilePath)
65−runLatex file = step 3
65+runLatex latexProgram file = step 3
67 step n = do
67 step n = do
68− result <- runLatexRaw file
68+ result <- runLatexRaw latexProgram file
69 case result of
69 case result of
70 Left (Left err) -> return $ Left err
70 Left (Left err) -> return $ Left err
71 Left (Right _) | n > 1 -> step (n-1 :: Int)
71 Left (Right _) | n > 1 -> step (n-1 :: Int)
@@ -145,17 +145,12 @@ main = bracket
146 -- run computation
146 -- run computation
147 $ \tmp -> do
147 $ \tmp -> do
148− -- check for executable files
149− let execs = ["pandoc", "pdflatex", "bibtex"]
150− paths <- mapM findExecutable execs
151− let miss = map snd $ filter (isNothing . fst) $ zip paths execs
152− unless (null miss) $ exit $! "Could not find " ++ intercalate ", " miss
153 args <- getArgs
148 args <- getArgs
154 -- check for invalid arguments and print help message if needed
149 -- check for invalid arguments and print help message if needed
155 let goodopts = ["-f","-r","-N", "-p","-R","-H","-B","-A", "-C","-o","-V"]
150 let goodopts = ["-f","-r","-N", "-p","-R","-H","-B","-A", "-C","-o","-V"]
156 let goodoptslong = ["--from","--read","--strict",
151 let goodoptslong = ["--from","--read","--strict",
157 "--preserve-tabs","--tab-stop","--parse-raw",
152 "--preserve-tabs","--tab-stop","--parse-raw",
158− "--toc","--table-of-contents",
153+ "--toc","--table-of-contents", "--xetex",
159 "--number-sections","--include-in-header",
154 "--number-sections","--include-in-header",
160 "--include-before-body","--include-after-body",
155 "--include-before-body","--include-after-body",
161 "--custom-header","--output",
156 "--custom-header","--output",
@@ -173,6 +168,15 @@ main = bracket
173 filter (\l -> any (`isInfixOf` l) goodoptslong) $ lines out
168 filter (\l -> any (`isInfixOf` l) goodoptslong) $ lines out
174 exitWith code
169 exitWith code
171+ -- check for executable files
172+ let latexProgram = if "--xetex" `elem` opts
175+ let execs = ["pandoc", latexProgram, "bibtex"]
176+ paths <- mapM findExecutable execs
177+ let miss = map snd $ filter (isNothing . fst) $ zip paths execs
178+ unless (null miss) $ exit $! "Could not find " ++ intercalate ", " miss
176 -- parse arguments
180 -- parse arguments
177 -- if no input given, use 'stdin'
181 -- if no input given, use 'stdin'
178 pandocArgs <- parsePandocArgs args
182 pandocArgs <- parsePandocArgs args
@@ -191,7 +195,7 @@ main = bracket
191 Left err -> exit err
195 Left err -> exit err
192 Right texFile -> do
196 Right texFile -> do
193 -- run pdflatex
197 -- run pdflatex
194− latexRes <- runLatex texFile
198+ latexRes <- runLatex latexProgram texFile
195 case latexRes of
199 case latexRes of
196 Left err -> exit err
200 Left err -> exit err
197 Right pdfFile -> do
201 Right pdfFile -> do