Implemented --citation-abbreviations option.

Mostly due to Andrea Rossato.
This commit is contained in:
John MacFarlane 2011-11-11 17:36:57 -08:00
parent 14620579c0
commit 9a46d75506
3 changed files with 36 additions and 6 deletions

16
README
View file

@ -439,6 +439,22 @@ Options
user data directory (see `--data-dir`), or, if that is user data directory (see `--data-dir`), or, if that is
not present, the Chicago author-date style. not present, the Chicago author-date style.
`--citation-abbreviations=`*FILE*
: Specify a file containing abbreviations for journal titles and
other bibliographic fields (indicated by setting `form="short"`
in the CSL node for the field). The format is described at
<http://citationstylist.org/2011/10/19/abbreviations-for-zotero-test-release/>.
Here is a short example:
{ "default": {
"container-title": {
"Lloyd's Law Reports": "Lloyd's Rep",
"Estates Gazette": "EG",
"Scots Law Times": "SLT"
}
}
}
`--natbib` `--natbib`
: Use natbib for citations in LaTeX output. : Use natbib for citations in LaTeX output.

View file

@ -43,11 +43,15 @@ import Control.Monad
-- | Process a 'Pandoc' document by adding citations formatted -- | Process a 'Pandoc' document by adding citations formatted
-- according to a CSL style, using 'citeproc' from citeproc-hs. -- according to a CSL style, using 'citeproc' from citeproc-hs.
processBiblio :: FilePath -> [Reference] -> Pandoc -> IO Pandoc processBiblio :: FilePath -> Maybe FilePath -> [Reference] -> Pandoc
processBiblio cslfile r p -> IO Pandoc
processBiblio cslfile abrfile r p
= if null r then return p = if null r then return p
else do else do
csl <- readCSLFile cslfile csl <- readCSLFile cslfile
abbrevs <- case abrfile of
Just f -> readJsonAbbrevFile f
Nothing -> return []
p' <- bottomUpM setHash p p' <- bottomUpM setHash p
let (nts,grps) = if styleClass csl == "note" let (nts,grps) = if styleClass csl == "note"
then let cits = queryWith getCite p' then let cits = queryWith getCite p'
@ -55,11 +59,12 @@ processBiblio cslfile r p
needNt = cits \\ concat ncits needNt = cits \\ concat ncits
in (,) needNt $ getNoteCitations needNt p' in (,) needNt $ getNoteCitations needNt p'
else (,) [] $ queryWith getCitation p' else (,) [] $ queryWith getCitation p'
result = citeproc procOpts csl r (setNearNote csl $ style = csl { styleAbbrevs = abbrevs }
result = citeproc procOpts style r (setNearNote style $
map (map toCslCite) grps) map (map toCslCite) grps)
cits_map = M.fromList $ zip grps (citations result) cits_map = M.fromList $ zip grps (citations result)
biblioList = map (renderPandoc' csl) (bibliography result) biblioList = map (renderPandoc' style) (bibliography result)
Pandoc m b = bottomUp (procInlines $ processCite csl cits_map) p' Pandoc m b = bottomUp (procInlines $ processCite style cits_map) p'
return . generateNotes nts . Pandoc m $ b ++ biblioList return . generateNotes nts . Pandoc m $ b ++ biblioList
-- | Substitute 'Cite' elements with formatted citations. -- | Substitute 'Cite' elements with formatted citations.

View file

@ -124,6 +124,7 @@ data Opt = Opt
, optCiteMethod :: CiteMethod -- ^ Method to output cites , optCiteMethod :: CiteMethod -- ^ Method to output cites
, optBibliography :: [String] , optBibliography :: [String]
, optCslFile :: FilePath , optCslFile :: FilePath
, optAbbrevsFile :: Maybe FilePath
, optListings :: Bool -- ^ Use listings package for code blocks , optListings :: Bool -- ^ Use listings package for code blocks
, optAscii :: Bool -- ^ Avoid using nonascii characters , optAscii :: Bool -- ^ Avoid using nonascii characters
} }
@ -168,6 +169,7 @@ defaultOpts = Opt
, optCiteMethod = Citeproc , optCiteMethod = Citeproc
, optBibliography = [] , optBibliography = []
, optCslFile = "" , optCslFile = ""
, optAbbrevsFile = Nothing
, optListings = False , optListings = False
, optAscii = False , optAscii = False
} }
@ -537,6 +539,12 @@ options =
"FILENAME") "FILENAME")
"" ""
, Option "" ["citation-abbreviations"]
(ReqArg
(\arg opt -> return opt { optAbbrevsFile = Just arg })
"FILENAME")
""
, Option "" ["natbib"] , Option "" ["natbib"]
(NoArg (NoArg
(\opt -> return opt { optCiteMethod = Natbib })) (\opt -> return opt { optCiteMethod = Natbib }))
@ -702,6 +710,7 @@ main = do
, optDataDir = mbDataDir , optDataDir = mbDataDir
, optBibliography = reffiles , optBibliography = reffiles
, optCslFile = cslfile , optCslFile = cslfile
, optAbbrevsFile = cslabbrevs
, optCiteMethod = citeMethod , optCiteMethod = citeMethod
, optListings = listings , optListings = listings
, optAscii = ascii , optAscii = ascii
@ -883,7 +892,7 @@ main = do
replaceDirectory replaceDirectory
(replaceExtension cslfile "csl") (replaceExtension cslfile "csl")
csldir csldir
processBiblio cslfile' refs doc1 processBiblio cslfile' cslabbrevs refs doc1
else return doc1 else return doc1
case lookup writerName' writers of case lookup writerName' writers of