@@ -44,10 +44,10 @@ runPandoc inputs output = do
4444 ++ inputs ++ ["-o", texFile]
4545 return $ either Left (const $ Right texFile) result
4646
47−runLatexRaw :: FilePath -> IO (Either (Either String String) FilePath)
48−runLatexRaw file = do
47+runLatexRaw :: String -> FilePath -> IO (Either (Either String String) FilePath)
48+runLatexRaw latexProgram file = do
4949 -- 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",
5151 takeDirectory file, dropExtension file] >> return ()
5252 let pdfFile = replaceExtension file "pdf"
5353 let logFile = replaceExtension file "log"
@@ -61,11 +61,11 @@ runLatexRaw file = do
6161 (False, _ , True, msg) -> return $ Left $ Right msg -- references
6262 (False, False, False, _ ) -> return $ Right pdfFile -- success
6363
64−runLatex :: FilePath -> IO (Either String FilePath)
65−runLatex file = step 3
64+runLatex :: String -> FilePath -> IO (Either String FilePath)
65+runLatex latexProgram file = step 3
6666 where
6767 step n = do
68− result <- runLatexRaw file
68+ result <- runLatexRaw latexProgram file
6969 case result of
7070 Left (Left err) -> return $ Left err
7171 Left (Right _) | n > 1 -> step (n-1 :: Int)
@@ -145,17 +145,12 @@ main = bracket
145145
146146 -- run computation
147147 $ \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
153148 args <- getArgs
154149 -- check for invalid arguments and print help message if needed
155150 let goodopts = ["-f","-r","-N", "-p","-R","-H","-B","-A", "-C","-o","-V"]
156151 let goodoptslong = ["--from","--read","--strict",
157152 "--preserve-tabs","--tab-stop","--parse-raw",
158− "--toc","--table-of-contents",
153+ "--toc","--table-of-contents", "--xetex",
159154 "--number-sections","--include-in-header",
160155 "--include-before-body","--include-after-body",
161156 "--custom-header","--output",
@@ -173,6 +168,15 @@ main = bracket
173168 filter (\l -> any (`isInfixOf` l) goodoptslong) $ lines out
174169 exitWith code
175170
171+ -- check for executable files
172+ let latexProgram = if "--xetex" `elem` opts
173+ then "xelatex"
174+ else "pdflatex"
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
179+
176180 -- parse arguments
177181 -- if no input given, use 'stdin'
178182 pandocArgs <- parsePandocArgs args
@@ -191,7 +195,7 @@ main = bracket
191195 Left err -> exit err
192196 Right texFile -> do
193197 -- run pdflatex
194− latexRes <- runLatex texFile
198+ latexRes <- runLatex latexProgram texFile
195199 case latexRes of
196200 Left err -> exit err
197201 Right pdfFile -> do