From ffed5c1cc310c4c377a73294514f5ac0cc682301 Mon Sep 17 00:00:00 2001 From: fiddlosopher Date: Thu, 31 Dec 2009 01:18:06 +0000 Subject: Added --xetex option to pandoc and markdown2pdf. If --xetex is specified, pandoc produces latex suitable for processing by xelatex, and markdown2pdf uses xelatex to create the PDF. Resolves Issue #185. This seems better than using latex packages to detect xetex, since not all latex installations will have these. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1737 788f1e2b-df1e-0410-8736-df70ead52e1b --- src/Text/Pandoc/Shared.hs | 2 ++ src/markdown2pdf.hs | 30 +++++++++++++++++------------- src/pandoc.hs | 9 +++++++++ 3 files changed, 28 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index dbb5d94a4..241de4399 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -989,6 +989,7 @@ data WriterOptions = WriterOptions , writerTabStop :: Int -- ^ Tabstop for conversion btw spaces and tabs , writerTableOfContents :: Bool -- ^ Include table of contents , writerS5 :: Bool -- ^ We're writing S5 + , writerXeTeX :: Bool -- ^ Create latex suitable for use by xetex , writerHTMLMathMethod :: HTMLMathMethod -- ^ How to print math in HTML , writerIgnoreNotes :: Bool -- ^ Ignore footnotes (used in making toc) , writerIncremental :: Bool -- ^ Incremental S5 lists @@ -1012,6 +1013,7 @@ defaultWriterOptions = , writerTabStop = 4 , writerTableOfContents = False , writerS5 = False + , writerXeTeX = True , writerHTMLMathMethod = PlainMath , writerIgnoreNotes = False , writerIncremental = False diff --git a/src/markdown2pdf.hs b/src/markdown2pdf.hs index ea580da98..5b56194cd 100644 --- a/src/markdown2pdf.hs +++ b/src/markdown2pdf.hs @@ -44,10 +44,10 @@ runPandoc inputs output = do ++ inputs ++ ["-o", texFile] return $ either Left (const $ Right texFile) result -runLatexRaw :: FilePath -> IO (Either (Either String String) FilePath) -runLatexRaw file = do +runLatexRaw :: String -> FilePath -> IO (Either (Either String String) FilePath) +runLatexRaw latexProgram file = do -- we ignore the ExitCode because pdflatex always fails the first time - run "pdflatex" ["-interaction=batchmode", "-output-directory", + run latexProgram ["-interaction=batchmode", "-output-directory", takeDirectory file, dropExtension file] >> return () let pdfFile = replaceExtension file "pdf" let logFile = replaceExtension file "log" @@ -61,11 +61,11 @@ runLatexRaw file = do (False, _ , True, msg) -> return $ Left $ Right msg -- references (False, False, False, _ ) -> return $ Right pdfFile -- success -runLatex :: FilePath -> IO (Either String FilePath) -runLatex file = step 3 +runLatex :: String -> FilePath -> IO (Either String FilePath) +runLatex latexProgram file = step 3 where step n = do - result <- runLatexRaw file + result <- runLatexRaw latexProgram file case result of Left (Left err) -> return $ Left err Left (Right _) | n > 1 -> step (n-1 :: Int) @@ -145,17 +145,12 @@ main = bracket -- run computation $ \tmp -> do - -- check for executable files - let execs = ["pandoc", "pdflatex", "bibtex"] - paths <- mapM findExecutable execs - let miss = map snd $ filter (isNothing . fst) $ zip paths execs - unless (null miss) $ exit $! "Could not find " ++ intercalate ", " miss args <- getArgs -- check for invalid arguments and print help message if needed let goodopts = ["-f","-r","-N", "-p","-R","-H","-B","-A", "-C","-o","-V"] let goodoptslong = ["--from","--read","--strict", "--preserve-tabs","--tab-stop","--parse-raw", - "--toc","--table-of-contents", + "--toc","--table-of-contents", "--xetex", "--number-sections","--include-in-header", "--include-before-body","--include-after-body", "--custom-header","--output", @@ -173,6 +168,15 @@ main = bracket filter (\l -> any (`isInfixOf` l) goodoptslong) $ lines out exitWith code + -- check for executable files + let latexProgram = if "--xetex" `elem` opts + then "xelatex" + else "pdflatex" + let execs = ["pandoc", latexProgram, "bibtex"] + paths <- mapM findExecutable execs + let miss = map snd $ filter (isNothing . fst) $ zip paths execs + unless (null miss) $ exit $! "Could not find " ++ intercalate ", " miss + -- parse arguments -- if no input given, use 'stdin' pandocArgs <- parsePandocArgs args @@ -191,7 +195,7 @@ main = bracket Left err -> exit err Right texFile -> do -- run pdflatex - latexRes <- runLatex texFile + latexRes <- runLatex latexProgram texFile case latexRes of Left err -> exit err Right pdfFile -> do diff --git a/src/pandoc.hs b/src/pandoc.hs index 7ddb41b00..b73527462 100644 --- a/src/pandoc.hs +++ b/src/pandoc.hs @@ -144,6 +144,7 @@ data Opt = Opt , optOutputFile :: String -- ^ Name of output file , optNumberSections :: Bool -- ^ Number sections in LaTeX , optIncremental :: Bool -- ^ Use incremental lists in S5 + , optXeTeX :: Bool -- ^ Format latex for xetex , optSmart :: Bool -- ^ Use smart typography , optHTMLMathMethod :: HTMLMathMethod -- ^ Method to print HTML math , optDumpArgs :: Bool -- ^ Output command-line arguments @@ -180,6 +181,7 @@ defaultOpts = Opt , optOutputFile = "-" -- "-" means stdout , optNumberSections = False , optIncremental = False + , optXeTeX = False , optSmart = False , optHTMLMathMethod = PlainMath , optDumpArgs = False @@ -287,6 +289,11 @@ options = (\opt -> return opt { optIncremental = True })) "" -- "Make list items display incrementally in S5" + , Option "" ["xetex"] + (NoArg + (\opt -> return opt { optXeTeX = True })) + "" -- "Format latex for processing by XeTeX" + , Option "N" ["number-sections"] (NoArg (\opt -> return opt { optNumberSections = True })) @@ -568,6 +575,7 @@ main = do , optOutputFile = outputFile , optNumberSections = numberSections , optIncremental = incremental + , optXeTeX = xetex , optSmart = smart , optHTMLMathMethod = mathMethod , optDumpArgs = dumpArgs @@ -665,6 +673,7 @@ main = do writerName' /= "s5", writerHTMLMathMethod = mathMethod, writerS5 = (writerName' == "s5"), + writerXeTeX = xetex, writerIgnoreNotes = False, writerIncremental = incremental, writerNumberSections = numberSections, -- cgit v1.2.3