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
This commit is contained in:
parent
b867109830
commit
ffed5c1cc3
8 changed files with 51 additions and 24 deletions
3
README
3
README
|
@ -380,6 +380,9 @@ For further documentation, see the `pandoc(1)` man page.
|
||||||
default (one item at a time). The normal default is for lists to be
|
default (one item at a time). The normal default is for lists to be
|
||||||
displayed all at once.
|
displayed all at once.
|
||||||
|
|
||||||
|
`--xetex`
|
||||||
|
: creates LaTeX outut suitable for processing by XeTeX.
|
||||||
|
|
||||||
`-N` or `--number-sections`
|
`-N` or `--number-sections`
|
||||||
: causes sections to be numbered in LaTeX, ConTeXt, or HTML output.
|
: causes sections to be numbered in LaTeX, ConTeXt, or HTML output.
|
||||||
By default, sections are not numbered.
|
By default, sections are not numbered.
|
||||||
|
|
|
@ -46,6 +46,9 @@ The following options are most relevant:
|
||||||
\--strict
|
\--strict
|
||||||
: Use strict markdown syntax, with no extensions or variants.
|
: Use strict markdown syntax, with no extensions or variants.
|
||||||
|
|
||||||
|
\--xetex
|
||||||
|
: Use xelatex instead of pdflatex to create the PDF.
|
||||||
|
|
||||||
-N, \--number-sections
|
-N, \--number-sections
|
||||||
: Number section headings in LaTeX output. (Default is not to number them.)
|
: Number section headings in LaTeX output. (Default is not to number them.)
|
||||||
|
|
||||||
|
|
|
@ -133,6 +133,9 @@ to Pandoc. Or use `html2markdown`(1), a wrapper around `pandoc`.
|
||||||
-i, \--incremental
|
-i, \--incremental
|
||||||
: Make list items in S5 display incrementally (one by one).
|
: Make list items in S5 display incrementally (one by one).
|
||||||
|
|
||||||
|
\--xetex
|
||||||
|
: Create LaTeX outut suitable for processing by XeTeX.
|
||||||
|
|
||||||
-N, \--number-sections
|
-N, \--number-sections
|
||||||
: Number section headings in LaTeX, ConTeXt, or HTML output.
|
: Number section headings in LaTeX, ConTeXt, or HTML output.
|
||||||
(Default is not to number them.)
|
(Default is not to number them.)
|
||||||
|
|
12
markdown2pdf
12
markdown2pdf
|
@ -1,6 +1,11 @@
|
||||||
#!/bin/sh -e
|
#!/bin/sh -e
|
||||||
|
|
||||||
REQUIRED="pdflatex"
|
latexprogram=pdflatex
|
||||||
|
if (echo "$@" | grep -q xetex); then
|
||||||
|
latexprogram=xelatex
|
||||||
|
fi
|
||||||
|
|
||||||
|
REQUIRED=$latexprogram
|
||||||
SYNOPSIS="converts markdown-formatted text to PDF, using pdflatex."
|
SYNOPSIS="converts markdown-formatted text to PDF, using pdflatex."
|
||||||
|
|
||||||
THIS=${0##*/}
|
THIS=${0##*/}
|
||||||
|
@ -46,7 +51,6 @@ CONF=$(pandoc --dump-args "$@" 2>&1) || {
|
||||||
OUTPUT=$(echo "$CONF" | sed -ne '1p')
|
OUTPUT=$(echo "$CONF" | sed -ne '1p')
|
||||||
ARGS=$(echo "$CONF" | sed -e '1d')
|
ARGS=$(echo "$CONF" | sed -e '1d')
|
||||||
|
|
||||||
|
|
||||||
# As a security measure refuse to proceed if mktemp is not available.
|
# As a security measure refuse to proceed if mktemp is not available.
|
||||||
pathfind mktemp || { err "Couldn't find 'mktemp'; aborting."; exit 1; }
|
pathfind mktemp || { err "Couldn't find 'mktemp'; aborting."; exit 1; }
|
||||||
|
|
||||||
|
@ -87,9 +91,9 @@ fi
|
||||||
finished=no
|
finished=no
|
||||||
runs=0
|
runs=0
|
||||||
while [ $finished = "no" ]; do
|
while [ $finished = "no" ]; do
|
||||||
pdflatex -interaction=batchmode $texname.tex >/dev/null || {
|
$latexprogram -interaction=batchmode $texname.tex >/dev/null || {
|
||||||
errcode=$?
|
errcode=$?
|
||||||
err "${THIS}: pdfLaTeX failed with error code $errcode"
|
err "${THIS}: $latexprogram failed with error code $errcode"
|
||||||
[ -f $texname.log ] && {
|
[ -f $texname.log ] && {
|
||||||
err "${THIS}: error context:"
|
err "${THIS}: error context:"
|
||||||
sed -ne '/^!/,/^[[:space:]]*$/p' \
|
sed -ne '/^!/,/^[[:space:]]*$/p' \
|
||||||
|
|
|
@ -989,6 +989,7 @@ data WriterOptions = WriterOptions
|
||||||
, writerTabStop :: Int -- ^ Tabstop for conversion btw spaces and tabs
|
, writerTabStop :: Int -- ^ Tabstop for conversion btw spaces and tabs
|
||||||
, writerTableOfContents :: Bool -- ^ Include table of contents
|
, writerTableOfContents :: Bool -- ^ Include table of contents
|
||||||
, writerS5 :: Bool -- ^ We're writing S5
|
, writerS5 :: Bool -- ^ We're writing S5
|
||||||
|
, writerXeTeX :: Bool -- ^ Create latex suitable for use by xetex
|
||||||
, writerHTMLMathMethod :: HTMLMathMethod -- ^ How to print math in HTML
|
, writerHTMLMathMethod :: HTMLMathMethod -- ^ How to print math in HTML
|
||||||
, writerIgnoreNotes :: Bool -- ^ Ignore footnotes (used in making toc)
|
, writerIgnoreNotes :: Bool -- ^ Ignore footnotes (used in making toc)
|
||||||
, writerIncremental :: Bool -- ^ Incremental S5 lists
|
, writerIncremental :: Bool -- ^ Incremental S5 lists
|
||||||
|
@ -1012,6 +1013,7 @@ defaultWriterOptions =
|
||||||
, writerTabStop = 4
|
, writerTabStop = 4
|
||||||
, writerTableOfContents = False
|
, writerTableOfContents = False
|
||||||
, writerS5 = False
|
, writerS5 = False
|
||||||
|
, writerXeTeX = True
|
||||||
, writerHTMLMathMethod = PlainMath
|
, writerHTMLMathMethod = PlainMath
|
||||||
, writerIgnoreNotes = False
|
, writerIgnoreNotes = False
|
||||||
, writerIncremental = False
|
, writerIncremental = False
|
||||||
|
|
|
@ -44,10 +44,10 @@ runPandoc inputs output = do
|
||||||
++ inputs ++ ["-o", texFile]
|
++ inputs ++ ["-o", texFile]
|
||||||
return $ either Left (const $ Right texFile) result
|
return $ either Left (const $ Right texFile) result
|
||||||
|
|
||||||
runLatexRaw :: FilePath -> IO (Either (Either String String) FilePath)
|
runLatexRaw :: String -> FilePath -> IO (Either (Either String String) FilePath)
|
||||||
runLatexRaw file = do
|
runLatexRaw latexProgram file = do
|
||||||
-- we ignore the ExitCode because pdflatex always fails the first time
|
-- 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 ()
|
takeDirectory file, dropExtension file] >> return ()
|
||||||
let pdfFile = replaceExtension file "pdf"
|
let pdfFile = replaceExtension file "pdf"
|
||||||
let logFile = replaceExtension file "log"
|
let logFile = replaceExtension file "log"
|
||||||
|
@ -61,11 +61,11 @@ runLatexRaw file = do
|
||||||
(False, _ , True, msg) -> return $ Left $ Right msg -- references
|
(False, _ , True, msg) -> return $ Left $ Right msg -- references
|
||||||
(False, False, False, _ ) -> return $ Right pdfFile -- success
|
(False, False, False, _ ) -> return $ Right pdfFile -- success
|
||||||
|
|
||||||
runLatex :: FilePath -> IO (Either String FilePath)
|
runLatex :: String -> FilePath -> IO (Either String FilePath)
|
||||||
runLatex file = step 3
|
runLatex latexProgram file = step 3
|
||||||
where
|
where
|
||||||
step n = do
|
step n = do
|
||||||
result <- runLatexRaw file
|
result <- runLatexRaw latexProgram file
|
||||||
case result of
|
case result of
|
||||||
Left (Left err) -> return $ Left err
|
Left (Left err) -> return $ Left err
|
||||||
Left (Right _) | n > 1 -> step (n-1 :: Int)
|
Left (Right _) | n > 1 -> step (n-1 :: Int)
|
||||||
|
@ -145,17 +145,12 @@ main = bracket
|
||||||
|
|
||||||
-- run computation
|
-- run computation
|
||||||
$ \tmp -> do
|
$ \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
|
args <- getArgs
|
||||||
-- check for invalid arguments and print help message if needed
|
-- check for invalid arguments and print help message if needed
|
||||||
let goodopts = ["-f","-r","-N", "-p","-R","-H","-B","-A", "-C","-o","-V"]
|
let goodopts = ["-f","-r","-N", "-p","-R","-H","-B","-A", "-C","-o","-V"]
|
||||||
let goodoptslong = ["--from","--read","--strict",
|
let goodoptslong = ["--from","--read","--strict",
|
||||||
"--preserve-tabs","--tab-stop","--parse-raw",
|
"--preserve-tabs","--tab-stop","--parse-raw",
|
||||||
"--toc","--table-of-contents",
|
"--toc","--table-of-contents", "--xetex",
|
||||||
"--number-sections","--include-in-header",
|
"--number-sections","--include-in-header",
|
||||||
"--include-before-body","--include-after-body",
|
"--include-before-body","--include-after-body",
|
||||||
"--custom-header","--output",
|
"--custom-header","--output",
|
||||||
|
@ -173,6 +168,15 @@ main = bracket
|
||||||
filter (\l -> any (`isInfixOf` l) goodoptslong) $ lines out
|
filter (\l -> any (`isInfixOf` l) goodoptslong) $ lines out
|
||||||
exitWith code
|
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
|
-- parse arguments
|
||||||
-- if no input given, use 'stdin'
|
-- if no input given, use 'stdin'
|
||||||
pandocArgs <- parsePandocArgs args
|
pandocArgs <- parsePandocArgs args
|
||||||
|
@ -191,7 +195,7 @@ main = bracket
|
||||||
Left err -> exit err
|
Left err -> exit err
|
||||||
Right texFile -> do
|
Right texFile -> do
|
||||||
-- run pdflatex
|
-- run pdflatex
|
||||||
latexRes <- runLatex texFile
|
latexRes <- runLatex latexProgram texFile
|
||||||
case latexRes of
|
case latexRes of
|
||||||
Left err -> exit err
|
Left err -> exit err
|
||||||
Right pdfFile -> do
|
Right pdfFile -> do
|
||||||
|
|
|
@ -144,6 +144,7 @@ data Opt = Opt
|
||||||
, optOutputFile :: String -- ^ Name of output file
|
, optOutputFile :: String -- ^ Name of output file
|
||||||
, optNumberSections :: Bool -- ^ Number sections in LaTeX
|
, optNumberSections :: Bool -- ^ Number sections in LaTeX
|
||||||
, optIncremental :: Bool -- ^ Use incremental lists in S5
|
, optIncremental :: Bool -- ^ Use incremental lists in S5
|
||||||
|
, optXeTeX :: Bool -- ^ Format latex for xetex
|
||||||
, optSmart :: Bool -- ^ Use smart typography
|
, optSmart :: Bool -- ^ Use smart typography
|
||||||
, optHTMLMathMethod :: HTMLMathMethod -- ^ Method to print HTML math
|
, optHTMLMathMethod :: HTMLMathMethod -- ^ Method to print HTML math
|
||||||
, optDumpArgs :: Bool -- ^ Output command-line arguments
|
, optDumpArgs :: Bool -- ^ Output command-line arguments
|
||||||
|
@ -180,6 +181,7 @@ defaultOpts = Opt
|
||||||
, optOutputFile = "-" -- "-" means stdout
|
, optOutputFile = "-" -- "-" means stdout
|
||||||
, optNumberSections = False
|
, optNumberSections = False
|
||||||
, optIncremental = False
|
, optIncremental = False
|
||||||
|
, optXeTeX = False
|
||||||
, optSmart = False
|
, optSmart = False
|
||||||
, optHTMLMathMethod = PlainMath
|
, optHTMLMathMethod = PlainMath
|
||||||
, optDumpArgs = False
|
, optDumpArgs = False
|
||||||
|
@ -287,6 +289,11 @@ options =
|
||||||
(\opt -> return opt { optIncremental = True }))
|
(\opt -> return opt { optIncremental = True }))
|
||||||
"" -- "Make list items display incrementally in S5"
|
"" -- "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"]
|
, Option "N" ["number-sections"]
|
||||||
(NoArg
|
(NoArg
|
||||||
(\opt -> return opt { optNumberSections = True }))
|
(\opt -> return opt { optNumberSections = True }))
|
||||||
|
@ -568,6 +575,7 @@ main = do
|
||||||
, optOutputFile = outputFile
|
, optOutputFile = outputFile
|
||||||
, optNumberSections = numberSections
|
, optNumberSections = numberSections
|
||||||
, optIncremental = incremental
|
, optIncremental = incremental
|
||||||
|
, optXeTeX = xetex
|
||||||
, optSmart = smart
|
, optSmart = smart
|
||||||
, optHTMLMathMethod = mathMethod
|
, optHTMLMathMethod = mathMethod
|
||||||
, optDumpArgs = dumpArgs
|
, optDumpArgs = dumpArgs
|
||||||
|
@ -665,6 +673,7 @@ main = do
|
||||||
writerName' /= "s5",
|
writerName' /= "s5",
|
||||||
writerHTMLMathMethod = mathMethod,
|
writerHTMLMathMethod = mathMethod,
|
||||||
writerS5 = (writerName' == "s5"),
|
writerS5 = (writerName' == "s5"),
|
||||||
|
writerXeTeX = xetex,
|
||||||
writerIgnoreNotes = False,
|
writerIgnoreNotes = False,
|
||||||
writerIncremental = incremental,
|
writerIncremental = incremental,
|
||||||
writerNumberSections = numberSections,
|
writerNumberSections = numberSections,
|
||||||
|
|
|
@ -2,14 +2,13 @@ $if(legacy-header)$
|
||||||
$legacy-header$
|
$legacy-header$
|
||||||
$else$
|
$else$
|
||||||
\documentclass{article}
|
\documentclass{article}
|
||||||
\usepackage{ifpdf,ifxetex}
|
|
||||||
\ifxetex
|
|
||||||
\usepackage{fontspec,xltxtra,xunicode}
|
|
||||||
\else
|
|
||||||
\usepackage[utf8x]{inputenc}
|
|
||||||
\usepackage[mathletters]{ucs}
|
|
||||||
\fi
|
|
||||||
\usepackage{amsmath}
|
\usepackage{amsmath}
|
||||||
|
$if(xetex)$
|
||||||
|
\usepackage{fontspec,xltxtra,xunicode}
|
||||||
|
$else$
|
||||||
|
\usepackage[mathletters]{ucs}
|
||||||
|
\usepackage[utf8x]{inputenc}
|
||||||
|
$endif$
|
||||||
\usepackage{listings}
|
\usepackage{listings}
|
||||||
\lstnewenvironment{code}{\lstset{language=Haskell,basicstyle=\small\ttfamily}}{}
|
\lstnewenvironment{code}{\lstset{language=Haskell,basicstyle=\small\ttfamily}}{}
|
||||||
\setlength{\parindent}{0pt}
|
\setlength{\parindent}{0pt}
|
||||||
|
|
Loading…
Add table
Reference in a new issue