aboutsummaryrefslogtreecommitdiff
path: root/src/pandoc.hs
diff options
context:
space:
mode:
authorNathan Gass <gass@search.ch>2010-12-13 21:18:01 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2010-12-13 20:41:37 -0800
commit48600fd5473d1a3c596c6ac8c29f1d7b17f1dc92 (patch)
tree71119dae7eb1673f818891ce9a6f415faf527999 /src/pandoc.hs
parent1a4a0d0283ef915d0e10fcb24027ff8bc93154e5 (diff)
downloadpandoc-48600fd5473d1a3c596c6ac8c29f1d7b17f1dc92.tar.gz
Added support to write natbib or biblatex citations in latex output.
Diffstat (limited to 'src/pandoc.hs')
-rw-r--r--src/pandoc.hs37
1 files changed, 24 insertions, 13 deletions
diff --git a/src/pandoc.hs b/src/pandoc.hs
index 13f285f15..87e72298a 100644
--- a/src/pandoc.hs
+++ b/src/pandoc.hs
@@ -116,7 +116,8 @@ data Opt = Opt
, optIdentifierPrefix :: String
, optIndentedCodeClasses :: [String] -- ^ Default classes for indented code blocks
, optDataDir :: Maybe FilePath
- , optBibliography :: [Reference]
+ , optCiteMethod :: CiteMethod -- ^ Method to output cites
+ , optBibliography :: [String]
, optCslFile :: FilePath
}
@@ -154,6 +155,7 @@ defaultOpts = Opt
, optIdentifierPrefix = ""
, optIndentedCodeClasses = []
, optDataDir = Nothing
+ , optCiteMethod = Citeproc
, optBibliography = []
, optCslFile = ""
}
@@ -453,14 +455,7 @@ options =
"" -- "Print default template for FORMAT"
, Option "" ["bibliography"]
(ReqArg
- (\arg opt -> do
- refs <- catch (readBiblioFile arg) $ \e -> do
- UTF8.hPutStrLn stderr $
- "Error reading bibliography `" ++ arg ++ "'"
- UTF8.hPutStrLn stderr $ show e
- exitWith (ExitFailure 23)
- return opt { optBibliography =
- optBibliography opt ++ refs } )
+ (\arg opt -> return opt { optBibliography = (optBibliography opt) ++ [arg] })
"FILENAME")
""
, Option "" ["csl"]
@@ -468,6 +463,14 @@ options =
(\arg opt -> return opt { optCslFile = arg })
"FILENAME")
""
+ , Option "" ["natbib"]
+ (NoArg
+ (\opt -> return opt { optCiteMethod = Natbib }))
+ "" -- "Use natbib cite commands in LaTeX output"
+ , Option "" ["biblatex"]
+ (NoArg
+ (\opt -> return opt { optCiteMethod = Biblatex }))
+ "" -- "Use biblatex cite commands in LaTeX output"
, Option "" ["data-dir"]
(ReqArg
(\arg opt -> return opt { optDataDir = Just arg })
@@ -618,8 +621,9 @@ main = do
, optIdentifierPrefix = idPrefix
, optIndentedCodeClasses = codeBlockClasses
, optDataDir = mbDataDir
- , optBibliography = refs
+ , optBibliography = reffiles
, optCslFile = cslfile
+ , optCiteMethod = citeMethod
} = opts
when dumpArgs $
@@ -693,6 +697,11 @@ main = do
return $ ("mathml-script", s) : variables'
_ -> return variables'
+ refs <- mapM (\f -> catch (readBiblioFile f) $ \e -> do
+ UTF8.hPutStrLn stderr $ "Error reading bibliography `" ++ f ++ "'"
+ UTF8.hPutStrLn stderr $ show e
+ exitWith (ExitFailure 23)) reffiles >>= \rs -> return $ concat rs
+
let sourceDir = if null sources
then "."
else takeDirectory (head sources)
@@ -729,6 +738,8 @@ main = do
writerSlideVariant = slideVariant,
writerIncremental = incremental,
writerXeTeX = xetex,
+ writerCiteMethod = citeMethod,
+ writerBiblioFile = head reffiles,
writerIgnoreNotes = False,
writerNumberSections = numberSections,
writerSectionDivs = sectionDivs,
@@ -766,9 +777,8 @@ main = do
let doc' = foldr ($) doc transforms
doc'' <- do
- if null refs
- then return doc'
- else do
+ if citeMethod == Citeproc && not (null refs)
+ then do
csldir <- getAppUserDataDirectory "csl"
cslfile' <- if null cslfile
then findDataFile datadir "default.csl"
@@ -781,6 +791,7 @@ main = do
(replaceExtension cslfile "csl")
csldir
processBiblio cslfile' refs doc'
+ else return doc'
writerOutput <- writer writerOptions doc''