git.iko.soy/typeable/pandoc
on master help sign in
LaTeX reader: Don't add spurious ", " to citation suffixes.
800c549John MacFarlane
src/Text/Pandoc/Readers/LaTeX.hs+3−7
@@ -44,7 +44,7 @@ import qualified Text.Pandoc.UTF8 as UTF8
44import Data.Char ( chr, ord )
44import Data.Char ( chr, ord )
45import Control.Monad
45import Control.Monad
46import Text.Pandoc.Builder
46import Text.Pandoc.Builder
47−import Data.Char (isLetter, isPunctuation, isSpace)
47+import Data.Char (isLetter)
48import Control.Applicative
48import Control.Applicative
49import Data.Monoid
49import Data.Monoid
50import System.Environment (getEnv)
50import System.Environment (getEnv)
@@ -986,12 +986,8 @@ addPrefix _ _ = []
986
986
987addSuffix :: [Inline] -> [Citation] -> [Citation]
987addSuffix :: [Inline] -> [Citation] -> [Citation]
988addSuffix s ks@(_:_) =
988addSuffix s ks@(_:_) =
989− let k = last ks
989+ let k = last ks
990− s' = case s of
991− (Str (c:_):_)
992− | not (isPunctuation c || isSpace c) -> Str "," : Space : s
993− _ -> s
994− in init ks ++ [k {citationSuffix = citationSuffix k ++ s'}]
990+ in init ks ++ [k {citationSuffix = citationSuffix k ++ s}]
995addSuffix _ _ = []
991addSuffix _ _ = []
996
992
997simpleCiteArgs :: LP [Citation]
993simpleCiteArgs :: LP [Citation]
tests/Tests/Readers/LaTeX.hs+18−18
@@ -79,14 +79,14 @@ natbibCitations = testGroup "natbib"
79 =?> para (cite [baseCitation] (rt "\\citet{item1}"))
79 =?> para (cite [baseCitation] (rt "\\citet{item1}"))
80 , "suffix" =: "\\citet[p.~30]{item1}"
80 , "suffix" =: "\\citet[p.~30]{item1}"
81 =?> para
81 =?> para
82− (cite [baseCitation{ citationSuffix = toList $ text ", p.\160\&30" }] (rt "\\citet[p.~30]{item1}"))
82+ (cite [baseCitation{ citationSuffix = toList $ text "p.\160\&30" }] (rt "\\citet[p.~30]{item1}"))
83 , "suffix long" =: "\\citet[p.~30, with suffix]{item1}"
83 , "suffix long" =: "\\citet[p.~30, with suffix]{item1}"
84 =?> para (cite [baseCitation{ citationSuffix =
84 =?> para (cite [baseCitation{ citationSuffix =
85− toList $ text ", p.\160\&30, with suffix" }] (rt "\\citet[p.~30, with suffix]{item1}"))
85+ toList $ text "p.\160\&30, with suffix" }] (rt "\\citet[p.~30, with suffix]{item1}"))
86 , "multiple" =: "\\citeauthor{item1} \\citetext{\\citeyear{item1}; \\citeyear[p.~30]{item2}; \\citealp[see also][]{item3}}"
86 , "multiple" =: "\\citeauthor{item1} \\citetext{\\citeyear{item1}; \\citeyear[p.~30]{item2}; \\citealp[see also][]{item3}}"
87 =?> para (cite [baseCitation{ citationMode = AuthorInText }
87 =?> para (cite [baseCitation{ citationMode = AuthorInText }
88 ,baseCitation{ citationMode = SuppressAuthor
88 ,baseCitation{ citationMode = SuppressAuthor
89− , citationSuffix = [Str ",",Space,Str "p.\160\&30"]
89+ , citationSuffix = [Str "p.\160\&30"]
90 , citationId = "item2" }
90 , citationId = "item2" }
91 ,baseCitation{ citationId = "item3"
91 ,baseCitation{ citationId = "item3"
92 , citationPrefix = [Str "see",Space,Str "also"]
92 , citationPrefix = [Str "see",Space,Str "also"]
@@ -95,28 +95,28 @@ natbibCitations = testGroup "natbib"
95 , "group" =: "\\citetext{\\citealp[see][p.~34--35]{item1}; \\citealp[also][chap. 3]{item3}}"
95 , "group" =: "\\citetext{\\citealp[see][p.~34--35]{item1}; \\citealp[also][chap. 3]{item3}}"
96 =?> para (cite [baseCitation{ citationMode = NormalCitation
96 =?> para (cite [baseCitation{ citationMode = NormalCitation
97 , citationPrefix = [Str "see"]
97 , citationPrefix = [Str "see"]
98− , citationSuffix = [Str ",",Space,Str "p.\160\&34\8211\&35"] }
98+ , citationSuffix = [Str "p.\160\&34\8211\&35"] }
99 ,baseCitation{ citationMode = NormalCitation
99 ,baseCitation{ citationMode = NormalCitation
100 , citationId = "item3"
100 , citationId = "item3"
101 , citationPrefix = [Str "also"]
101 , citationPrefix = [Str "also"]
102− , citationSuffix = [Str ",",Space,Str "chap.",Space,Str "3"] }
102+ , citationSuffix = [Str "chap.",Space,Str "3"] }
103 ] (rt "\\citetext{\\citealp[see][p.~34--35]{item1}; \\citealp[also][chap. 3]{item3}}"))
103 ] (rt "\\citetext{\\citealp[see][p.~34--35]{item1}; \\citealp[also][chap. 3]{item3}}"))
104 , "suffix and locator" =: "\\citep[pp.~33, 35--37, and nowhere else]{item1}"
104 , "suffix and locator" =: "\\citep[pp.~33, 35--37, and nowhere else]{item1}"
105 =?> para (cite [baseCitation{ citationMode = NormalCitation
105 =?> para (cite [baseCitation{ citationMode = NormalCitation
106− , 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}"))
106+ , 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}"))
107 , "suffix only" =: "\\citep[and nowhere else]{item1}"
107 , "suffix only" =: "\\citep[and nowhere else]{item1}"
108 =?> para (cite [baseCitation{ citationMode = NormalCitation
108 =?> para (cite [baseCitation{ citationMode = NormalCitation
109− , citationSuffix = toList $ text ", and nowhere else" }] (rt "\\citep[and nowhere else]{item1}"))
109+ , citationSuffix = toList $ text "and nowhere else" }] (rt "\\citep[and nowhere else]{item1}"))
110 , "no author" =: "\\citeyearpar{item1}, and now Doe with a locator \\citeyearpar[p.~44]{item2}"
110 , "no author" =: "\\citeyearpar{item1}, and now Doe with a locator \\citeyearpar[p.~44]{item2}"
111 =?> para (cite [baseCitation{ citationMode = SuppressAuthor }] (rt "\\citeyearpar{item1}") <>
111 =?> para (cite [baseCitation{ citationMode = SuppressAuthor }] (rt "\\citeyearpar{item1}") <>
112 text ", and now Doe with a locator " <>
112 text ", and now Doe with a locator " <>
113 cite [baseCitation{ citationMode = SuppressAuthor
113 cite [baseCitation{ citationMode = SuppressAuthor
114− , citationSuffix = [Str ",",Space,Str "p.\160\&44"]
114+ , citationSuffix = [Str "p.\160\&44"]
115 , citationId = "item2" }] (rt "\\citeyearpar[p.~44]{item2}"))
115 , citationId = "item2" }] (rt "\\citeyearpar[p.~44]{item2}"))
116 , "markup" =: "\\citep[\\emph{see}][p. \\textbf{32}]{item1}"
116 , "markup" =: "\\citep[\\emph{see}][p. \\textbf{32}]{item1}"
117 =?> para (cite [baseCitation{ citationMode = NormalCitation
117 =?> para (cite [baseCitation{ citationMode = NormalCitation
118 , citationPrefix = [Emph [Str "see"]]
118 , citationPrefix = [Emph [Str "see"]]
119− , citationSuffix = [Str ",",Space,Str "p.",Space,
119+ , citationSuffix = [Str "p.",Space,
120 Strong [Str "32"]] }] (rt "\\citep[\\emph{see}][p. \\textbf{32}]{item1}"))
120 Strong [Str "32"]] }] (rt "\\citep[\\emph{see}][p. \\textbf{32}]{item1}"))
121 ]
121 ]
122
122
@@ -126,14 +126,14 @@ biblatexCitations = testGroup "biblatex"
126 =?> para (cite [baseCitation] (rt "\\textcite{item1}"))
126 =?> para (cite [baseCitation] (rt "\\textcite{item1}"))
127 , "suffix" =: "\\textcite[p.~30]{item1}"
127 , "suffix" =: "\\textcite[p.~30]{item1}"
128 =?> para
128 =?> para
129− (cite [baseCitation{ citationSuffix = toList $ text ", p.\160\&30" }] (rt "\\textcite[p.~30]{item1}"))
129+ (cite [baseCitation{ citationSuffix = toList $ text "p.\160\&30" }] (rt "\\textcite[p.~30]{item1}"))
130 , "suffix long" =: "\\textcite[p.~30, with suffix]{item1}"
130 , "suffix long" =: "\\textcite[p.~30, with suffix]{item1}"
131 =?> para (cite [baseCitation{ citationSuffix =
131 =?> para (cite [baseCitation{ citationSuffix =
132− toList $ text ", p.\160\&30, with suffix" }] (rt "\\textcite[p.~30, with suffix]{item1}"))
132+ toList $ text "p.\160\&30, with suffix" }] (rt "\\textcite[p.~30, with suffix]{item1}"))
133 , "multiple" =: "\\textcites{item1}[p.~30]{item2}[see also][]{item3}"
133 , "multiple" =: "\\textcites{item1}[p.~30]{item2}[see also][]{item3}"
134 =?> para (cite [baseCitation{ citationMode = AuthorInText }
134 =?> para (cite [baseCitation{ citationMode = AuthorInText }
135 ,baseCitation{ citationMode = NormalCitation
135 ,baseCitation{ citationMode = NormalCitation
136− , citationSuffix = [Str ",",Space,Str "p.\160\&30"]
136+ , citationSuffix = [Str "p.\160\&30"]
137 , citationId = "item2" }
137 , citationId = "item2" }
138 ,baseCitation{ citationId = "item3"
138 ,baseCitation{ citationId = "item3"
139 , citationPrefix = [Str "see",Space,Str "also"]
139 , citationPrefix = [Str "see",Space,Str "also"]
@@ -142,28 +142,28 @@ biblatexCitations = testGroup "biblatex"
142 , "group" =: "\\autocites[see][p.~34--35]{item1}[also][chap. 3]{item3}"
142 , "group" =: "\\autocites[see][p.~34--35]{item1}[also][chap. 3]{item3}"
143 =?> para (cite [baseCitation{ citationMode = NormalCitation
143 =?> para (cite [baseCitation{ citationMode = NormalCitation
144 , citationPrefix = [Str "see"]
144 , citationPrefix = [Str "see"]
145− , citationSuffix = [Str ",",Space,Str "p.\160\&34\8211\&35"] }
145+ , citationSuffix = [Str "p.\160\&34\8211\&35"] }
146 ,baseCitation{ citationMode = NormalCitation
146 ,baseCitation{ citationMode = NormalCitation
147 , citationId = "item3"
147 , citationId = "item3"
148 , citationPrefix = [Str "also"]
148 , citationPrefix = [Str "also"]
149− , citationSuffix = [Str ",",Space,Str "chap.",Space,Str "3"] }
149+ , citationSuffix = [Str "chap.",Space,Str "3"] }
150 ] (rt "\\autocites[see][p.~34--35]{item1}[also][chap. 3]{item3}"))
150 ] (rt "\\autocites[see][p.~34--35]{item1}[also][chap. 3]{item3}"))
151 , "suffix and locator" =: "\\autocite[pp.~33, 35--37, and nowhere else]{item1}"
151 , "suffix and locator" =: "\\autocite[pp.~33, 35--37, and nowhere else]{item1}"
152 =?> para (cite [baseCitation{ citationMode = NormalCitation
152 =?> para (cite [baseCitation{ citationMode = NormalCitation
153− , 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}"))
153+ , 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}"))
154 , "suffix only" =: "\\autocite[and nowhere else]{item1}"
154 , "suffix only" =: "\\autocite[and nowhere else]{item1}"
155 =?> para (cite [baseCitation{ citationMode = NormalCitation
155 =?> para (cite [baseCitation{ citationMode = NormalCitation
156− , citationSuffix = toList $ text ", and nowhere else" }] (rt "\\autocite[and nowhere else]{item1}"))
156+ , citationSuffix = toList $ text "and nowhere else" }] (rt "\\autocite[and nowhere else]{item1}"))
157 , "no author" =: "\\autocite*{item1}, and now Doe with a locator \\autocite*[p.~44]{item2}"
157 , "no author" =: "\\autocite*{item1}, and now Doe with a locator \\autocite*[p.~44]{item2}"
158 =?> para (cite [baseCitation{ citationMode = SuppressAuthor }] (rt "\\autocite*{item1}") <>
158 =?> para (cite [baseCitation{ citationMode = SuppressAuthor }] (rt "\\autocite*{item1}") <>
159 text ", and now Doe with a locator " <>
159 text ", and now Doe with a locator " <>
160 cite [baseCitation{ citationMode = SuppressAuthor
160 cite [baseCitation{ citationMode = SuppressAuthor
161− , citationSuffix = [Str ",",Space,Str "p.\160\&44"]
161+ , citationSuffix = [Str "p.\160\&44"]
162 , citationId = "item2" }] (rt "\\autocite*[p.~44]{item2}"))
162 , citationId = "item2" }] (rt "\\autocite*[p.~44]{item2}"))
163 , "markup" =: "\\autocite[\\emph{see}][p. \\textbf{32}]{item1}"
163 , "markup" =: "\\autocite[\\emph{see}][p. \\textbf{32}]{item1}"
164 =?> para (cite [baseCitation{ citationMode = NormalCitation
164 =?> para (cite [baseCitation{ citationMode = NormalCitation
165 , citationPrefix = [Emph [Str "see"]]
165 , citationPrefix = [Emph [Str "see"]]
166− , citationSuffix = [Str ",",Space,Str "p.",Space,
166+ , citationSuffix = [Str "p.",Space,
167 Strong [Str "32"]] }] (rt "\\autocite[\\emph{see}][p. \\textbf{32}]{item1}"))
167 Strong [Str "32"]] }] (rt "\\autocite[\\emph{see}][p. \\textbf{32}]{item1}"))
168 , "parencite" =: "\\parencite{item1}"
168 , "parencite" =: "\\parencite{item1}"
169 =?> para (cite [baseCitation{ citationMode = NormalCitation }] (rt "\\parencite{item1}"))
169 =?> para (cite [baseCitation{ citationMode = NormalCitation }] (rt "\\parencite{item1}"))
tests/latex-reader.native+1−1
@@ -260,7 +260,7 @@ Pandoc (Meta {unMeta = fromList [("authors",MetaList [MetaInlines [Str "John",Sp
260,HorizontalRule
260,HorizontalRule
261,Header 1 ("",[],[]) [Str "LaTeX"]
261,Header 1 ("",[],[]) [Str "LaTeX"]
262,BulletList
262,BulletList
263− [[Para [Cite [Citation {citationId = "smith.1899", citationPrefix = [], citationSuffix = [Str ",",Space,Str "22-23"], citationMode = AuthorInText, citationNoteNum = 0, citationHash = 0}] [RawInline "latex" "\\cite[22-23]{smith.1899}"]]]
263+ [[Para [Cite [Citation {citationId = "smith.1899", citationPrefix = [], citationSuffix = [Str "22-23"], citationMode = AuthorInText, citationNoteNum = 0, citationHash = 0}] [RawInline "latex" "\\cite[22-23]{smith.1899}"]]]
264 ,[Para [RawInline "latex" "\\doublespacing"]]
264 ,[Para [RawInline "latex" "\\doublespacing"]]
265 ,[Para [Math InlineMath "2+2=4"]]
265 ,[Para [Math InlineMath "2+2=4"]]
266 ,[Para [Math InlineMath "x \\in y"]]
266 ,[Para [Math InlineMath "x \\in y"]]