git.iko.soy/typeable/pandoc
on master help sign in
Added --xetex option to pandoc and markdown2pdf.
ffed5c1fiddlosopher
@@ -380,6 +380,9 @@ For further documentation, see the `pandoc(1)` man page.
380 default (one item at a time). The normal default is for lists to be
380 default (one item at a time). The normal default is for lists to be
381 displayed all at once.
381 displayed all at once.
382
382
383+`--xetex`
384+: creates LaTeX outut suitable for processing by XeTeX.
385+
383`-N` or `--number-sections`
386`-N` or `--number-sections`
384: causes sections to be numbered in LaTeX, ConTeXt, or HTML output.
387: causes sections to be numbered in LaTeX, ConTeXt, or HTML output.
385 By default, sections are not numbered.
388 By default, sections are not numbered.
man/man1/markdown2pdf.1.md+3
@@ -46,6 +46,9 @@ The following options are most relevant:
46\--strict
46\--strict
47: Use strict markdown syntax, with no extensions or variants.
47: Use strict markdown syntax, with no extensions or variants.
48
48
49+\--xetex
50+: Use xelatex instead of pdflatex to create the PDF.
51+
49-N, \--number-sections
52-N, \--number-sections
50: Number section headings in LaTeX output. (Default is not to number them.)
53: Number section headings in LaTeX output. (Default is not to number them.)
51
54
man/man1/pandoc.1.md+3
@@ -133,6 +133,9 @@ to Pandoc. Or use `html2markdown`(1), a wrapper around `pandoc`.
133-i, \--incremental
133-i, \--incremental
134: Make list items in S5 display incrementally (one by one).
134: Make list items in S5 display incrementally (one by one).
135
135
136+\--xetex
137+: Create LaTeX outut suitable for processing by XeTeX.
138+
136-N, \--number-sections
139-N, \--number-sections
137: Number section headings in LaTeX, ConTeXt, or HTML output.
140: Number section headings in LaTeX, ConTeXt, or HTML output.
138 (Default is not to number them.)
141 (Default is not to number them.)
markdown2pdf+8−4
@@ -1,6 +1,11 @@
1#!/bin/sh -e
1#!/bin/sh -e
2
2
3+latexprogram=pdflatex
4+if (echo "$@" | grep -q xetex); then
5+ latexprogram=xelatex
6+fi
7+
3−REQUIRED="pdflatex"
8+REQUIRED=$latexprogram
4SYNOPSIS="converts markdown-formatted text to PDF, using pdflatex."
9SYNOPSIS="converts markdown-formatted text to PDF, using pdflatex."
5
10
6THIS=${0##*/}
11THIS=${0##*/}
@@ -46,7 +51,6 @@ CONF=$(pandoc --dump-args "$@" 2>&1) || {
46OUTPUT=$(echo "$CONF" | sed -ne '1p')
51OUTPUT=$(echo "$CONF" | sed -ne '1p')
47ARGS=$(echo "$CONF" | sed -e '1d')
52ARGS=$(echo "$CONF" | sed -e '1d')
48
53
49−
50# As a security measure refuse to proceed if mktemp is not available.
54# As a security measure refuse to proceed if mktemp is not available.
51pathfind mktemp || { err "Couldn't find 'mktemp'; aborting."; exit 1; }
55pathfind mktemp || { err "Couldn't find 'mktemp'; aborting."; exit 1; }
52
56
@@ -87,9 +91,9 @@ fi
87 finished=no
91 finished=no
88 runs=0
92 runs=0
89 while [ $finished = "no" ]; do
93 while [ $finished = "no" ]; do
90− pdflatex -interaction=batchmode $texname.tex >/dev/null || {
94+ $latexprogram -interaction=batchmode $texname.tex >/dev/null || {
91 errcode=$?
95 errcode=$?
92− err "${THIS}: pdfLaTeX failed with error code $errcode"
96+ err "${THIS}: $latexprogram failed with error code $errcode"
93 [ -f $texname.log ] && {
97 [ -f $texname.log ] && {
94 err "${THIS}: error context:"
98 err "${THIS}: error context:"
95 sed -ne '/^!/,/^[[:space:]]*$/p' \
99 sed -ne '/^!/,/^[[:space:]]*$/p' \
src/Text/Pandoc/Shared.hs+2
@@ -989,6 +989,7 @@ data WriterOptions = WriterOptions
989 , writerTabStop :: Int -- ^ Tabstop for conversion btw spaces and tabs
989 , writerTabStop :: Int -- ^ Tabstop for conversion btw spaces and tabs
990 , writerTableOfContents :: Bool -- ^ Include table of contents
990 , writerTableOfContents :: Bool -- ^ Include table of contents
991 , writerS5 :: Bool -- ^ We're writing S5
991 , writerS5 :: Bool -- ^ We're writing S5
992+ , writerXeTeX :: Bool -- ^ Create latex suitable for use by xetex
992 , writerHTMLMathMethod :: HTMLMathMethod -- ^ How to print math in HTML
993 , writerHTMLMathMethod :: HTMLMathMethod -- ^ How to print math in HTML
993 , writerIgnoreNotes :: Bool -- ^ Ignore footnotes (used in making toc)
994 , writerIgnoreNotes :: Bool -- ^ Ignore footnotes (used in making toc)
994 , writerIncremental :: Bool -- ^ Incremental S5 lists
995 , writerIncremental :: Bool -- ^ Incremental S5 lists
@@ -1012,6 +1013,7 @@ defaultWriterOptions =
1012 , writerTabStop = 4
1013 , writerTabStop = 4
1013 , writerTableOfContents = False
1014 , writerTableOfContents = False
1014 , writerS5 = False
1015 , writerS5 = False
1016+ , writerXeTeX = True
1015 , writerHTMLMathMethod = PlainMath
1017 , writerHTMLMathMethod = PlainMath
1016 , writerIgnoreNotes = False
1018 , writerIgnoreNotes = False
1017 , writerIncremental = False
1019 , writerIncremental = False
src/markdown2pdf.hs+17−13
@@ -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
46
46
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
63
63
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
66 where
66 where
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
145
145
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
175
170
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+
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
src/pandoc.hs+9
@@ -144,6 +144,7 @@ data Opt = Opt
144 , optOutputFile :: String -- ^ Name of output file
144 , optOutputFile :: String -- ^ Name of output file
145 , optNumberSections :: Bool -- ^ Number sections in LaTeX
145 , optNumberSections :: Bool -- ^ Number sections in LaTeX
146 , optIncremental :: Bool -- ^ Use incremental lists in S5
146 , optIncremental :: Bool -- ^ Use incremental lists in S5
147+ , optXeTeX :: Bool -- ^ Format latex for xetex
147 , optSmart :: Bool -- ^ Use smart typography
148 , optSmart :: Bool -- ^ Use smart typography
148 , optHTMLMathMethod :: HTMLMathMethod -- ^ Method to print HTML math
149 , optHTMLMathMethod :: HTMLMathMethod -- ^ Method to print HTML math
149 , optDumpArgs :: Bool -- ^ Output command-line arguments
150 , optDumpArgs :: Bool -- ^ Output command-line arguments
@@ -180,6 +181,7 @@ defaultOpts = Opt
180 , optOutputFile = "-" -- "-" means stdout
181 , optOutputFile = "-" -- "-" means stdout
181 , optNumberSections = False
182 , optNumberSections = False
182 , optIncremental = False
183 , optIncremental = False
184+ , optXeTeX = False
183 , optSmart = False
185 , optSmart = False
184 , optHTMLMathMethod = PlainMath
186 , optHTMLMathMethod = PlainMath
185 , optDumpArgs = False
187 , optDumpArgs = False
@@ -287,6 +289,11 @@ options =
287 (\opt -> return opt { optIncremental = True }))
289 (\opt -> return opt { optIncremental = True }))
288 "" -- "Make list items display incrementally in S5"
290 "" -- "Make list items display incrementally in S5"
289
291
292+ , Option "" ["xetex"]
293+ (NoArg
294+ (\opt -> return opt { optXeTeX = True }))
295+ "" -- "Format latex for processing by XeTeX"
296+
290 , Option "N" ["number-sections"]
297 , Option "N" ["number-sections"]
291 (NoArg
298 (NoArg
292 (\opt -> return opt { optNumberSections = True }))
299 (\opt -> return opt { optNumberSections = True }))
@@ -568,6 +575,7 @@ main = do
568 , optOutputFile = outputFile
575 , optOutputFile = outputFile
569 , optNumberSections = numberSections
576 , optNumberSections = numberSections
570 , optIncremental = incremental
577 , optIncremental = incremental
578+ , optXeTeX = xetex
571 , optSmart = smart
579 , optSmart = smart
572 , optHTMLMathMethod = mathMethod
580 , optHTMLMathMethod = mathMethod
573 , optDumpArgs = dumpArgs
581 , optDumpArgs = dumpArgs
@@ -665,6 +673,7 @@ main = do
665 writerName' /= "s5",
673 writerName' /= "s5",
666 writerHTMLMathMethod = mathMethod,
674 writerHTMLMathMethod = mathMethod,
667 writerS5 = (writerName' == "s5"),
675 writerS5 = (writerName' == "s5"),
676+ writerXeTeX = xetex,
668 writerIgnoreNotes = False,
677 writerIgnoreNotes = False,
669 writerIncremental = incremental,
678 writerIncremental = incremental,
670 writerNumberSections = numberSections,
679 writerNumberSections = numberSections,
templates/latex.template+6−7
@@ -2,14 +2,13 @@ $if(legacy-header)$
2$legacy-header$
2$legacy-header$
3$else$
3$else$
4\documentclass{article}
4\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
12\usepackage{amsmath}
5\usepackage{amsmath}
6+$if(xetex)$
7+\usepackage{fontspec,xltxtra,xunicode}
8+$else$
9+\usepackage[mathletters]{ucs}
10+\usepackage[utf8x]{inputenc}
11+$endif$
13\usepackage{listings}
12\usepackage{listings}
14\lstnewenvironment{code}{\lstset{language=Haskell,basicstyle=\small\ttfamily}}{}
13\lstnewenvironment{code}{\lstset{language=Haskell,basicstyle=\small\ttfamily}}{}
15\setlength{\parindent}{0pt}
14\setlength{\parindent}{0pt}