git.iko.soy/typeable/pandoc
on master help sign in
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

commitffed5c1cc310c4c377a73294514f5ac0cc682301 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateThu 31 Dec 2009, 01:18 (17 years ago) parentb867109
8 files changed+51−24
README+3 man/man1/markdown2pdf.1.md+3 man/man1/pandoc.1.md+3 markdown2pdf+8−4 src/Text/Pandoc/Shared.hs+2 src/markdown2pdf.hs+17−13 src/pandoc.hs+9 templates/latex.template+6−7
README+3
@@ -380,6 +380,9 @@ For further documentation, see the `pandoc(1)` man page.
380380 default (one item at a time). The normal default is for lists to be
381381 displayed all at once.
382382
383+`--xetex`
384+: creates LaTeX outut suitable for processing by XeTeX.
385+
383386`-N` or `--number-sections`
384387: causes sections to be numbered in LaTeX, ConTeXt, or HTML output.
385388 By default, sections are not numbered.
man/man1/markdown2pdf.1.md+3
@@ -46,6 +46,9 @@ The following options are most relevant:
4646\--strict
4747: Use strict markdown syntax, with no extensions or variants.
4848
49+\--xetex
50+: Use xelatex instead of pdflatex to create the PDF.
51+
4952-N, \--number-sections
5053: Number section headings in LaTeX output. (Default is not to number them.)
5154
man/man1/pandoc.1.md+3
@@ -133,6 +133,9 @@ to Pandoc. Or use `html2markdown`(1), a wrapper around `pandoc`.
133133-i, \--incremental
134134: Make list items in S5 display incrementally (one by one).
135135
136+\--xetex
137+: Create LaTeX outut suitable for processing by XeTeX.
138+
136139-N, \--number-sections
137140: Number section headings in LaTeX, ConTeXt, or HTML output.
138141 (Default is not to number them.)
markdown2pdf+8−4
@@ -1,6 +1,11 @@
11#!/bin/sh -e
22
3−REQUIRED="pdflatex"
3+latexprogram=pdflatex
4+if (echo "$@" | grep -q xetex); then
5+ latexprogram=xelatex
6+fi
7+
8+REQUIRED=$latexprogram
49SYNOPSIS="converts markdown-formatted text to PDF, using pdflatex."
510
611THIS=${0##*/}
@@ -46,7 +51,6 @@ CONF=$(pandoc --dump-args "$@" 2>&1) || {
4651OUTPUT=$(echo "$CONF" | sed -ne '1p')
4752ARGS=$(echo "$CONF" | sed -e '1d')
4853
49−
5054# As a security measure refuse to proceed if mktemp is not available.
5155pathfind mktemp || { err "Couldn't find 'mktemp'; aborting."; exit 1; }
5256
@@ -87,9 +91,9 @@ fi
8791 finished=no
8892 runs=0
8993 while [ $finished = "no" ]; do
90− pdflatex -interaction=batchmode $texname.tex >/dev/null || {
94+ $latexprogram -interaction=batchmode $texname.tex >/dev/null || {
9195 errcode=$?
92− err "${THIS}: pdfLaTeX failed with error code $errcode"
96+ err "${THIS}: $latexprogram failed with error code $errcode"
9397 [ -f $texname.log ] && {
9498 err "${THIS}: error context:"
9599 sed -ne '/^!/,/^[[:space:]]*$/p' \
src/Text/Pandoc/Shared.hs+2
@@ -989,6 +989,7 @@ data WriterOptions = WriterOptions
989989 , writerTabStop :: Int -- ^ Tabstop for conversion btw spaces and tabs
990990 , writerTableOfContents :: Bool -- ^ Include table of contents
991991 , writerS5 :: Bool -- ^ We're writing S5
992+ , writerXeTeX :: Bool -- ^ Create latex suitable for use by xetex
992993 , writerHTMLMathMethod :: HTMLMathMethod -- ^ How to print math in HTML
993994 , writerIgnoreNotes :: Bool -- ^ Ignore footnotes (used in making toc)
994995 , writerIncremental :: Bool -- ^ Incremental S5 lists
@@ -1012,6 +1013,7 @@ defaultWriterOptions =
10121013 , writerTabStop = 4
10131014 , writerTableOfContents = False
10141015 , writerS5 = False
1016+ , writerXeTeX = True
10151017 , writerHTMLMathMethod = PlainMath
10161018 , writerIgnoreNotes = False
10171019 , writerIncremental = False
src/markdown2pdf.hs+17−13
@@ -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
src/pandoc.hs+9
@@ -144,6 +144,7 @@ data Opt = Opt
144144 , optOutputFile :: String -- ^ Name of output file
145145 , optNumberSections :: Bool -- ^ Number sections in LaTeX
146146 , optIncremental :: Bool -- ^ Use incremental lists in S5
147+ , optXeTeX :: Bool -- ^ Format latex for xetex
147148 , optSmart :: Bool -- ^ Use smart typography
148149 , optHTMLMathMethod :: HTMLMathMethod -- ^ Method to print HTML math
149150 , optDumpArgs :: Bool -- ^ Output command-line arguments
@@ -180,6 +181,7 @@ defaultOpts = Opt
180181 , optOutputFile = "-" -- "-" means stdout
181182 , optNumberSections = False
182183 , optIncremental = False
184+ , optXeTeX = False
183185 , optSmart = False
184186 , optHTMLMathMethod = PlainMath
185187 , optDumpArgs = False
@@ -287,6 +289,11 @@ options =
287289 (\opt -> return opt { optIncremental = True }))
288290 "" -- "Make list items display incrementally in S5"
289291
292+ , Option "" ["xetex"]
293+ (NoArg
294+ (\opt -> return opt { optXeTeX = True }))
295+ "" -- "Format latex for processing by XeTeX"
296+
290297 , Option "N" ["number-sections"]
291298 (NoArg
292299 (\opt -> return opt { optNumberSections = True }))
@@ -568,6 +575,7 @@ main = do
568575 , optOutputFile = outputFile
569576 , optNumberSections = numberSections
570577 , optIncremental = incremental
578+ , optXeTeX = xetex
571579 , optSmart = smart
572580 , optHTMLMathMethod = mathMethod
573581 , optDumpArgs = dumpArgs
@@ -665,6 +673,7 @@ main = do
665673 writerName' /= "s5",
666674 writerHTMLMathMethod = mathMethod,
667675 writerS5 = (writerName' == "s5"),
676+ writerXeTeX = xetex,
668677 writerIgnoreNotes = False,
669678 writerIncremental = incremental,
670679 writerNumberSections = numberSections,
templates/latex.template+6−7
@@ -2,14 +2,13 @@ $if(legacy-header)$
22$legacy-header$
33$else$
44\documentclass{article}
5−\usepackage{ifpdf,ifxetex}
6−\ifxetex
7− \usepackage{fontspec,xltxtra,xunicode}
8−\else
9− \usepackage[utf8x]{inputenc}
10− \usepackage[mathletters]{ucs}
11−\fi
125\usepackage{amsmath}
6+$if(xetex)$
7+\usepackage{fontspec,xltxtra,xunicode}
8+$else$
9+\usepackage[mathletters]{ucs}
10+\usepackage[utf8x]{inputenc}
11+$endif$
1312\usepackage{listings}
1413\lstnewenvironment{code}{\lstset{language=Haskell,basicstyle=\small\ttfamily}}{}
1514\setlength{\parindent}{0pt}