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
|
||||
displayed all at once.
|
||||
|
||||
`--xetex`
|
||||
: creates LaTeX outut suitable for processing by XeTeX.
|
||||
|
||||
`-N` or `--number-sections`
|
||||
: causes sections to be numbered in LaTeX, ConTeXt, or HTML output.
|
||||
By default, sections are not numbered.
|
||||
|
|
|
@ -46,6 +46,9 @@ The following options are most relevant:
|
|||
\--strict
|
||||
: Use strict markdown syntax, with no extensions or variants.
|
||||
|
||||
\--xetex
|
||||
: Use xelatex instead of pdflatex to create the PDF.
|
||||
|
||||
-N, \--number-sections
|
||||
: 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
|
||||
: Make list items in S5 display incrementally (one by one).
|
||||
|
||||
\--xetex
|
||||
: Create LaTeX outut suitable for processing by XeTeX.
|
||||
|
||||
-N, \--number-sections
|
||||
: Number section headings in LaTeX, ConTeXt, or HTML output.
|
||||
(Default is not to number them.)
|
||||
|
|
12
markdown2pdf
12
markdown2pdf
|
@ -1,6 +1,11 @@
|
|||
#!/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."
|
||||
|
||||
THIS=${0##*/}
|
||||
|
@ -46,7 +51,6 @@ CONF=$(pandoc --dump-args "$@" 2>&1) || {
|
|||
OUTPUT=$(echo "$CONF" | sed -ne '1p')
|
||||
ARGS=$(echo "$CONF" | sed -e '1d')
|
||||
|
||||
|
||||
# As a security measure refuse to proceed if mktemp is not available.
|
||||
pathfind mktemp || { err "Couldn't find 'mktemp'; aborting."; exit 1; }
|
||||
|
||||
|
@ -87,9 +91,9 @@ fi
|
|||
finished=no
|
||||
runs=0
|
||||
while [ $finished = "no" ]; do
|
||||
pdflatex -interaction=batchmode $texname.tex >/dev/null || {
|
||||
$latexprogram -interaction=batchmode $texname.tex >/dev/null || {
|
||||
errcode=$?
|
||||
err "${THIS}: pdfLaTeX failed with error code $errcode"
|
||||
err "${THIS}: $latexprogram failed with error code $errcode"
|
||||
[ -f $texname.log ] && {
|
||||
err "${THIS}: error context:"
|
||||
sed -ne '/^!/,/^[[:space:]]*$/p' \
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -2,14 +2,13 @@ $if(legacy-header)$
|
|||
$legacy-header$
|
||||
$else$
|
||||
\documentclass{article}
|
||||
\usepackage{ifpdf,ifxetex}
|
||||
\ifxetex
|
||||
\usepackage{fontspec,xltxtra,xunicode}
|
||||
\else
|
||||
\usepackage[utf8x]{inputenc}
|
||||
\usepackage[mathletters]{ucs}
|
||||
\fi
|
||||
\usepackage{amsmath}
|
||||
$if(xetex)$
|
||||
\usepackage{fontspec,xltxtra,xunicode}
|
||||
$else$
|
||||
\usepackage[mathletters]{ucs}
|
||||
\usepackage[utf8x]{inputenc}
|
||||
$endif$
|
||||
\usepackage{listings}
|
||||
\lstnewenvironment{code}{\lstset{language=Haskell,basicstyle=\small\ttfamily}}{}
|
||||
\setlength{\parindent}{0pt}
|
||||
|
|
Loading…
Reference in a new issue