git.iko.soy/typeable/pandoc
on master help sign in
LaTeX reader: Add ", " to suffix...

if it doesn't start w space or punctuation. Otherwise we get no space between the year and the suffix in author-date styles.

commitf59e33dd1a49e3f3229c4c26d50c9d002343221d authorJohn MacFarlane <fiddlosopher@gmail.com> dateFri 10 Feb 2012, 21:47 (15 years ago) parentfe3d8ea
3 files changed+32−28
src/Tests/Readers/LaTeX.hs+18−18 src/Text/Pandoc/Readers/LaTeX.hs+13−9 tests/latex-reader.native+1−1
src/Tests/Readers/LaTeX.hs+18−18
@@ -78,14 +78,14 @@ natbibCitations = testGroup "natbib"
7878 =?> para (cite [baseCitation] (rt "\\citet{item1}"))
7979 , "suffix" =: "\\citet[p.~30]{item1}"
8080 =?> para
81− (cite [baseCitation{ citationSuffix = toList $ text "p.\160\&30" }] (rt "\\citet[p.~30]{item1}"))
81+ (cite [baseCitation{ citationSuffix = toList $ text ", p.\160\&30" }] (rt "\\citet[p.~30]{item1}"))
8282 , "suffix long" =: "\\citet[p.~30, with suffix]{item1}"
8383 =?> para (cite [baseCitation{ citationSuffix =
84− toList $ text "p.\160\&30, with suffix" }] (rt "\\citet[p.~30, with suffix]{item1}"))
84+ toList $ text ", p.\160\&30, with suffix" }] (rt "\\citet[p.~30, with suffix]{item1}"))
8585 , "multiple" =: "\\citeauthor{item1} \\citetext{\\citeyear{item1}; \\citeyear[p.~30]{item2}; \\citealp[see also][]{item3}}"
8686 =?> para (cite [baseCitation{ citationMode = AuthorInText }
8787 ,baseCitation{ citationMode = SuppressAuthor
88− , citationSuffix = [Str "p.\160\&30"]
88+ , citationSuffix = [Str ",",Space,Str "p.\160\&30"]
8989 , citationId = "item2" }
9090 ,baseCitation{ citationId = "item3"
9191 , citationPrefix = [Str "see",Space,Str "also"]
@@ -94,28 +94,28 @@ natbibCitations = testGroup "natbib"
9494 , "group" =: "\\citetext{\\citealp[see][p.~34--35]{item1}; \\citealp[also][chap. 3]{item3}}"
9595 =?> para (cite [baseCitation{ citationMode = NormalCitation
9696 , citationPrefix = [Str "see"]
97− , citationSuffix = [Str "p.\160\&34\8211\&35"] }
97+ , citationSuffix = [Str ",",Space,Str "p.\160\&34\8211\&35"] }
9898 ,baseCitation{ citationMode = NormalCitation
9999 , citationId = "item3"
100100 , citationPrefix = [Str "also"]
101− , citationSuffix = [Str "chap.",Space,Str "3"] }
101+ , citationSuffix = [Str ",",Space,Str "chap.",Space,Str "3"] }
102102 ] (rt "\\citetext{\\citealp[see][p.~34--35]{item1}; \\citealp[also][chap. 3]{item3}}"))
103103 , "suffix and locator" =: "\\citep[pp.~33, 35--37, and nowhere else]{item1}"
104104 =?> para (cite [baseCitation{ citationMode = NormalCitation
105− , citationSuffix = [Str "pp.\160\&33,",Space,Str "35\8211\&37,",Space,Str "and",Space,Str "nowhere",Space, Str "else"] }] (rt "\\citep[pp.~33, 35--37, and nowhere else]{item1}"))
105+ , citationSuffix = [Str ",",Space,Str "pp.\160\&33,",Space,Str "35\8211\&37,",Space,Str "and",Space,Str "nowhere",Space, Str "else"] }] (rt "\\citep[pp.~33, 35--37, and nowhere else]{item1}"))
106106 , "suffix only" =: "\\citep[and nowhere else]{item1}"
107107 =?> para (cite [baseCitation{ citationMode = NormalCitation
108− , citationSuffix = toList $ text "and nowhere else" }] (rt "\\citep[and nowhere else]{item1}"))
108+ , citationSuffix = toList $ text ", and nowhere else" }] (rt "\\citep[and nowhere else]{item1}"))
109109 , "no author" =: "\\citeyearpar{item1}, and now Doe with a locator \\citeyearpar[p.~44]{item2}"
110110 =?> para (cite [baseCitation{ citationMode = SuppressAuthor }] (rt "\\citeyearpar{item1}") <>
111111 text ", and now Doe with a locator " <>
112112 cite [baseCitation{ citationMode = SuppressAuthor
113− , citationSuffix = [Str "p.\160\&44"]
113+ , citationSuffix = [Str ",",Space,Str "p.\160\&44"]
114114 , citationId = "item2" }] (rt "\\citeyearpar[p.~44]{item2}"))
115115 , "markup" =: "\\citep[\\emph{see}][p. \\textbf{32}]{item1}"
116116 =?> para (cite [baseCitation{ citationMode = NormalCitation
117117 , citationPrefix = [Emph [Str "see"]]
118− , citationSuffix = [Str "p.",Space,
118+ , citationSuffix = [Str ",",Space,Str "p.",Space,
119119 Strong [Str "32"]] }] (rt "\\citep[\\emph{see}][p. \\textbf{32}]{item1}"))
120120 ]
121121
@@ -125,14 +125,14 @@ biblatexCitations = testGroup "biblatex"
125125 =?> para (cite [baseCitation] (rt "\\textcite{item1}"))
126126 , "suffix" =: "\\textcite[p.~30]{item1}"
127127 =?> para
128− (cite [baseCitation{ citationSuffix = toList $ text "p.\160\&30" }] (rt "\\textcite[p.~30]{item1}"))
128+ (cite [baseCitation{ citationSuffix = toList $ text ", p.\160\&30" }] (rt "\\textcite[p.~30]{item1}"))
129129 , "suffix long" =: "\\textcite[p.~30, with suffix]{item1}"
130130 =?> para (cite [baseCitation{ citationSuffix =
131− toList $ text "p.\160\&30, with suffix" }] (rt "\\textcite[p.~30, with suffix]{item1}"))
131+ toList $ text ", p.\160\&30, with suffix" }] (rt "\\textcite[p.~30, with suffix]{item1}"))
132132 , "multiple" =: "\\textcites{item1}[p.~30]{item2}[see also][]{item3}"
133133 =?> para (cite [baseCitation{ citationMode = AuthorInText }
134134 ,baseCitation{ citationMode = NormalCitation
135− , citationSuffix = [Str "p.\160\&30"]
135+ , citationSuffix = [Str ",",Space,Str "p.\160\&30"]
136136 , citationId = "item2" }
137137 ,baseCitation{ citationId = "item3"
138138 , citationPrefix = [Str "see",Space,Str "also"]
@@ -141,28 +141,28 @@ biblatexCitations = testGroup "biblatex"
141141 , "group" =: "\\autocites[see][p.~34--35]{item1}[also][chap. 3]{item3}"
142142 =?> para (cite [baseCitation{ citationMode = NormalCitation
143143 , citationPrefix = [Str "see"]
144− , citationSuffix = [Str "p.\160\&34\8211\&35"] }
144+ , citationSuffix = [Str ",",Space,Str "p.\160\&34\8211\&35"] }
145145 ,baseCitation{ citationMode = NormalCitation
146146 , citationId = "item3"
147147 , citationPrefix = [Str "also"]
148− , citationSuffix = [Str "chap.",Space,Str "3"] }
148+ , citationSuffix = [Str ",",Space,Str "chap.",Space,Str "3"] }
149149 ] (rt "\\autocites[see][p.~34--35]{item1}[also][chap. 3]{item3}"))
150150 , "suffix and locator" =: "\\autocite[pp.~33, 35--37, and nowhere else]{item1}"
151151 =?> para (cite [baseCitation{ citationMode = NormalCitation
152− , citationSuffix = [Str "pp.\160\&33,",Space,Str "35\8211\&37,",Space,Str "and",Space,Str "nowhere",Space, Str "else"] }] (rt "\\autocite[pp.~33, 35--37, and nowhere else]{item1}"))
152+ , citationSuffix = [Str ",",Space,Str "pp.\160\&33,",Space,Str "35\8211\&37,",Space,Str "and",Space,Str "nowhere",Space, Str "else"] }] (rt "\\autocite[pp.~33, 35--37, and nowhere else]{item1}"))
153153 , "suffix only" =: "\\autocite[and nowhere else]{item1}"
154154 =?> para (cite [baseCitation{ citationMode = NormalCitation
155− , citationSuffix = toList $ text "and nowhere else" }] (rt "\\autocite[and nowhere else]{item1}"))
155+ , citationSuffix = toList $ text ", and nowhere else" }] (rt "\\autocite[and nowhere else]{item1}"))
156156 , "no author" =: "\\autocite*{item1}, and now Doe with a locator \\autocite*[p.~44]{item2}"
157157 =?> para (cite [baseCitation{ citationMode = SuppressAuthor }] (rt "\\autocite*{item1}") <>
158158 text ", and now Doe with a locator " <>
159159 cite [baseCitation{ citationMode = SuppressAuthor
160− , citationSuffix = [Str "p.\160\&44"]
160+ , citationSuffix = [Str ",",Space,Str "p.\160\&44"]
161161 , citationId = "item2" }] (rt "\\autocite*[p.~44]{item2}"))
162162 , "markup" =: "\\autocite[\\emph{see}][p. \\textbf{32}]{item1}"
163163 =?> para (cite [baseCitation{ citationMode = NormalCitation
164164 , citationPrefix = [Emph [Str "see"]]
165− , citationSuffix = [Str "p.",Space,
165+ , citationSuffix = [Str ",",Space,Str "p.",Space,
166166 Strong [Str "32"]] }] (rt "\\autocite[\\emph{see}][p. \\textbf{32}]{item1}"))
167167 , "parencite" =: "\\parencite{item1}"
168168 =?> para (cite [baseCitation{ citationMode = NormalCitation }] (rt "\\parencite{item1}"))
src/Text/Pandoc/Readers/LaTeX.hs+13−9
@@ -41,7 +41,7 @@ import qualified Text.Pandoc.UTF8 as UTF8
4141import Data.Char ( chr, ord )
4242import Control.Monad
4343import Text.Pandoc.Builder
44−import Data.Char (isLetter)
44+import Data.Char (isLetter, isPunctuation, isSpace)
4545import Control.Applicative
4646import Data.Monoid
4747import System.FilePath (replaceExtension)
@@ -800,20 +800,24 @@ preamble = mempty <$> manyTill preambleBlock beginDoc
800800
801801-- citations
802802
803−addPrefix :: Inlines -> [Citation] -> [Citation]
804−addPrefix p (k:ks) = k {citationPrefix = toList p ++ citationPrefix k} : ks
803+addPrefix :: [Inline] -> [Citation] -> [Citation]
804+addPrefix p (k:ks) = k {citationPrefix = p ++ citationPrefix k} : ks
805805addPrefix _ _ = []
806806
807−addSuffix :: Inlines -> [Citation] -> [Citation]
807+addSuffix :: [Inline] -> [Citation] -> [Citation]
808808addSuffix s ks@(_:_) =
809− let k = last ks
810− in init ks ++ [k {citationSuffix = citationSuffix k ++ toList s}]
809+ let k = last ks
810+ s' = case s of
811+ (Str (c:_):_)
812+ | not (isPunctuation c || isSpace c) -> Str "," : Space : s
813+ _ -> s
814+ in init ks ++ [k {citationSuffix = citationSuffix k ++ s'}]
811815addSuffix _ _ = []
812816
813817simpleCiteArgs :: LP [Citation]
814818simpleCiteArgs = try $ do
815− first <- optionMaybe opt
816− second <- optionMaybe opt
819+ first <- optionMaybe $ toList <$> opt
820+ second <- optionMaybe $ toList <$> opt
817821 char '{'
818822 keys <- manyTill citationLabel (char '}')
819823 let (pre, suf) = case (first , second ) of
@@ -850,7 +854,7 @@ citation name mode multi = do
850854
851855complexNatbibCitation :: CitationMode -> LP Inlines
852856complexNatbibCitation mode = try $ do
853− let ils = (trimInlines . mconcat) <$>
857+ let ils = (toList . trimInlines . mconcat) <$>
854858 many (notFollowedBy (oneOf "\\};") >> inline)
855859 let parseOne = try $ do
856860 skipSpaces
tests/latex-reader.native+1−1
@@ -259,7 +259,7 @@ Pandoc (Meta {docTitle = [Str "Pandoc",Space,Str "Test",Space,Str "Suite"], docA
259259,HorizontalRule
260260,Header 1 [Str "LaTeX"]
261261,BulletList
262− [[Para [Cite [Citation {citationId = "smith.1899", citationPrefix = [], citationSuffix = [Str "22-23"], citationMode = NormalCitation, citationNoteNum = 0, citationHash = 0}] [RawInline "latex" "\\cite[22-23]{smith.1899}"]]]
262+ [[Para [Cite [Citation {citationId = "smith.1899", citationPrefix = [], citationSuffix = [Str ",",Space,Str "22-23"], citationMode = NormalCitation, citationNoteNum = 0, citationHash = 0}] [RawInline "latex" "\\cite[22-23]{smith.1899}"]]]
263263 ,[Para [RawInline "latex" "\\doublespacing"]]
264264 ,[Para [Math InlineMath "2+2=4"]]
265265 ,[Para [Math InlineMath "x \\in y"]]