git.iko.soy/typeable/pandoc
on master help sign in
LaTeX reader: Add ", " to suffix...
f59e33dJohn MacFarlane
src/Tests/Readers/LaTeX.hs+18−18
@@ -78,14 +78,14 @@ natbibCitations = testGroup "natbib"
78 =?> para (cite [baseCitation] (rt "\\citet{item1}"))
78 =?> para (cite [baseCitation] (rt "\\citet{item1}"))
79 , "suffix" =: "\\citet[p.~30]{item1}"
79 , "suffix" =: "\\citet[p.~30]{item1}"
80 =?> para
80 =?> 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}"))
82 , "suffix long" =: "\\citet[p.~30, with suffix]{item1}"
82 , "suffix long" =: "\\citet[p.~30, with suffix]{item1}"
83 =?> para (cite [baseCitation{ citationSuffix =
83 =?> 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}"))
85 , "multiple" =: "\\citeauthor{item1} \\citetext{\\citeyear{item1}; \\citeyear[p.~30]{item2}; \\citealp[see also][]{item3}}"
85 , "multiple" =: "\\citeauthor{item1} \\citetext{\\citeyear{item1}; \\citeyear[p.~30]{item2}; \\citealp[see also][]{item3}}"
86 =?> para (cite [baseCitation{ citationMode = AuthorInText }
86 =?> para (cite [baseCitation{ citationMode = AuthorInText }
87 ,baseCitation{ citationMode = SuppressAuthor
87 ,baseCitation{ citationMode = SuppressAuthor
88− , citationSuffix = [Str "p.\160\&30"]
88+ , citationSuffix = [Str ",",Space,Str "p.\160\&30"]
89 , citationId = "item2" }
89 , citationId = "item2" }
90 ,baseCitation{ citationId = "item3"
90 ,baseCitation{ citationId = "item3"
91 , citationPrefix = [Str "see",Space,Str "also"]
91 , citationPrefix = [Str "see",Space,Str "also"]
@@ -94,28 +94,28 @@ natbibCitations = testGroup "natbib"
94 , "group" =: "\\citetext{\\citealp[see][p.~34--35]{item1}; \\citealp[also][chap. 3]{item3}}"
94 , "group" =: "\\citetext{\\citealp[see][p.~34--35]{item1}; \\citealp[also][chap. 3]{item3}}"
95 =?> para (cite [baseCitation{ citationMode = NormalCitation
95 =?> para (cite [baseCitation{ citationMode = NormalCitation
96 , citationPrefix = [Str "see"]
96 , citationPrefix = [Str "see"]
97− , citationSuffix = [Str "p.\160\&34\8211\&35"] }
97+ , citationSuffix = [Str ",",Space,Str "p.\160\&34\8211\&35"] }
98 ,baseCitation{ citationMode = NormalCitation
98 ,baseCitation{ citationMode = NormalCitation
99 , citationId = "item3"
99 , citationId = "item3"
100 , citationPrefix = [Str "also"]
100 , citationPrefix = [Str "also"]
101− , citationSuffix = [Str "chap.",Space,Str "3"] }
101+ , citationSuffix = [Str ",",Space,Str "chap.",Space,Str "3"] }
102 ] (rt "\\citetext{\\citealp[see][p.~34--35]{item1}; \\citealp[also][chap. 3]{item3}}"))
102 ] (rt "\\citetext{\\citealp[see][p.~34--35]{item1}; \\citealp[also][chap. 3]{item3}}"))
103 , "suffix and locator" =: "\\citep[pp.~33, 35--37, and nowhere else]{item1}"
103 , "suffix and locator" =: "\\citep[pp.~33, 35--37, and nowhere else]{item1}"
104 =?> para (cite [baseCitation{ citationMode = NormalCitation
104 =?> 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}"))
106 , "suffix only" =: "\\citep[and nowhere else]{item1}"
106 , "suffix only" =: "\\citep[and nowhere else]{item1}"
107 =?> para (cite [baseCitation{ citationMode = NormalCitation
107 =?> 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}"))
109 , "no author" =: "\\citeyearpar{item1}, and now Doe with a locator \\citeyearpar[p.~44]{item2}"
109 , "no author" =: "\\citeyearpar{item1}, and now Doe with a locator \\citeyearpar[p.~44]{item2}"
110 =?> para (cite [baseCitation{ citationMode = SuppressAuthor }] (rt "\\citeyearpar{item1}") <>
110 =?> para (cite [baseCitation{ citationMode = SuppressAuthor }] (rt "\\citeyearpar{item1}") <>
111 text ", and now Doe with a locator " <>
111 text ", and now Doe with a locator " <>
112 cite [baseCitation{ citationMode = SuppressAuthor
112 cite [baseCitation{ citationMode = SuppressAuthor
113− , citationSuffix = [Str "p.\160\&44"]
113+ , citationSuffix = [Str ",",Space,Str "p.\160\&44"]
114 , citationId = "item2" }] (rt "\\citeyearpar[p.~44]{item2}"))
114 , citationId = "item2" }] (rt "\\citeyearpar[p.~44]{item2}"))
115 , "markup" =: "\\citep[\\emph{see}][p. \\textbf{32}]{item1}"
115 , "markup" =: "\\citep[\\emph{see}][p. \\textbf{32}]{item1}"
116 =?> para (cite [baseCitation{ citationMode = NormalCitation
116 =?> para (cite [baseCitation{ citationMode = NormalCitation
117 , citationPrefix = [Emph [Str "see"]]
117 , citationPrefix = [Emph [Str "see"]]
118− , citationSuffix = [Str "p.",Space,
118+ , citationSuffix = [Str ",",Space,Str "p.",Space,
119 Strong [Str "32"]] }] (rt "\\citep[\\emph{see}][p. \\textbf{32}]{item1}"))
119 Strong [Str "32"]] }] (rt "\\citep[\\emph{see}][p. \\textbf{32}]{item1}"))
120 ]
120 ]
121
121
@@ -125,14 +125,14 @@ biblatexCitations = testGroup "biblatex"
125 =?> para (cite [baseCitation] (rt "\\textcite{item1}"))
125 =?> para (cite [baseCitation] (rt "\\textcite{item1}"))
126 , "suffix" =: "\\textcite[p.~30]{item1}"
126 , "suffix" =: "\\textcite[p.~30]{item1}"
127 =?> para
127 =?> 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}"))
129 , "suffix long" =: "\\textcite[p.~30, with suffix]{item1}"
129 , "suffix long" =: "\\textcite[p.~30, with suffix]{item1}"
130 =?> para (cite [baseCitation{ citationSuffix =
130 =?> 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}"))
132 , "multiple" =: "\\textcites{item1}[p.~30]{item2}[see also][]{item3}"
132 , "multiple" =: "\\textcites{item1}[p.~30]{item2}[see also][]{item3}"
133 =?> para (cite [baseCitation{ citationMode = AuthorInText }
133 =?> para (cite [baseCitation{ citationMode = AuthorInText }
134 ,baseCitation{ citationMode = NormalCitation
134 ,baseCitation{ citationMode = NormalCitation
135− , citationSuffix = [Str "p.\160\&30"]
135+ , citationSuffix = [Str ",",Space,Str "p.\160\&30"]
136 , citationId = "item2" }
136 , citationId = "item2" }
137 ,baseCitation{ citationId = "item3"
137 ,baseCitation{ citationId = "item3"
138 , citationPrefix = [Str "see",Space,Str "also"]
138 , citationPrefix = [Str "see",Space,Str "also"]
@@ -141,28 +141,28 @@ biblatexCitations = testGroup "biblatex"
141 , "group" =: "\\autocites[see][p.~34--35]{item1}[also][chap. 3]{item3}"
141 , "group" =: "\\autocites[see][p.~34--35]{item1}[also][chap. 3]{item3}"
142 =?> para (cite [baseCitation{ citationMode = NormalCitation
142 =?> para (cite [baseCitation{ citationMode = NormalCitation
143 , citationPrefix = [Str "see"]
143 , citationPrefix = [Str "see"]
144− , citationSuffix = [Str "p.\160\&34\8211\&35"] }
144+ , citationSuffix = [Str ",",Space,Str "p.\160\&34\8211\&35"] }
145 ,baseCitation{ citationMode = NormalCitation
145 ,baseCitation{ citationMode = NormalCitation
146 , citationId = "item3"
146 , citationId = "item3"
147 , citationPrefix = [Str "also"]
147 , citationPrefix = [Str "also"]
148− , citationSuffix = [Str "chap.",Space,Str "3"] }
148+ , citationSuffix = [Str ",",Space,Str "chap.",Space,Str "3"] }
149 ] (rt "\\autocites[see][p.~34--35]{item1}[also][chap. 3]{item3}"))
149 ] (rt "\\autocites[see][p.~34--35]{item1}[also][chap. 3]{item3}"))
150 , "suffix and locator" =: "\\autocite[pp.~33, 35--37, and nowhere else]{item1}"
150 , "suffix and locator" =: "\\autocite[pp.~33, 35--37, and nowhere else]{item1}"
151 =?> para (cite [baseCitation{ citationMode = NormalCitation
151 =?> 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}"))
153 , "suffix only" =: "\\autocite[and nowhere else]{item1}"
153 , "suffix only" =: "\\autocite[and nowhere else]{item1}"
154 =?> para (cite [baseCitation{ citationMode = NormalCitation
154 =?> 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}"))
156 , "no author" =: "\\autocite*{item1}, and now Doe with a locator \\autocite*[p.~44]{item2}"
156 , "no author" =: "\\autocite*{item1}, and now Doe with a locator \\autocite*[p.~44]{item2}"
157 =?> para (cite [baseCitation{ citationMode = SuppressAuthor }] (rt "\\autocite*{item1}") <>
157 =?> para (cite [baseCitation{ citationMode = SuppressAuthor }] (rt "\\autocite*{item1}") <>
158 text ", and now Doe with a locator " <>
158 text ", and now Doe with a locator " <>
159 cite [baseCitation{ citationMode = SuppressAuthor
159 cite [baseCitation{ citationMode = SuppressAuthor
160− , citationSuffix = [Str "p.\160\&44"]
160+ , citationSuffix = [Str ",",Space,Str "p.\160\&44"]
161 , citationId = "item2" }] (rt "\\autocite*[p.~44]{item2}"))
161 , citationId = "item2" }] (rt "\\autocite*[p.~44]{item2}"))
162 , "markup" =: "\\autocite[\\emph{see}][p. \\textbf{32}]{item1}"
162 , "markup" =: "\\autocite[\\emph{see}][p. \\textbf{32}]{item1}"
163 =?> para (cite [baseCitation{ citationMode = NormalCitation
163 =?> para (cite [baseCitation{ citationMode = NormalCitation
164 , citationPrefix = [Emph [Str "see"]]
164 , citationPrefix = [Emph [Str "see"]]
165− , citationSuffix = [Str "p.",Space,
165+ , citationSuffix = [Str ",",Space,Str "p.",Space,
166 Strong [Str "32"]] }] (rt "\\autocite[\\emph{see}][p. \\textbf{32}]{item1}"))
166 Strong [Str "32"]] }] (rt "\\autocite[\\emph{see}][p. \\textbf{32}]{item1}"))
167 , "parencite" =: "\\parencite{item1}"
167 , "parencite" =: "\\parencite{item1}"
168 =?> para (cite [baseCitation{ citationMode = NormalCitation }] (rt "\\parencite{item1}"))
168 =?> 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
41import Data.Char ( chr, ord )
41import Data.Char ( chr, ord )
42import Control.Monad
42import Control.Monad
43import Text.Pandoc.Builder
43import Text.Pandoc.Builder
44−import Data.Char (isLetter)
44+import Data.Char (isLetter, isPunctuation, isSpace)
45import Control.Applicative
45import Control.Applicative
46import Data.Monoid
46import Data.Monoid
47import System.FilePath (replaceExtension)
47import System.FilePath (replaceExtension)
@@ -800,20 +800,24 @@ preamble = mempty <$> manyTill preambleBlock beginDoc
800
800
801-- citations
801-- citations
802
802
803−addPrefix :: Inlines -> [Citation] -> [Citation]
803+addPrefix :: [Inline] -> [Citation] -> [Citation]
804−addPrefix p (k:ks) = k {citationPrefix = toList p ++ citationPrefix k} : ks
804+addPrefix p (k:ks) = k {citationPrefix = p ++ citationPrefix k} : ks
805addPrefix _ _ = []
805addPrefix _ _ = []
806
806
807−addSuffix :: Inlines -> [Citation] -> [Citation]
807+addSuffix :: [Inline] -> [Citation] -> [Citation]
808addSuffix s ks@(_:_) =
808addSuffix s ks@(_:_) =
809− let k = last ks
809+ let k = last ks
810+ s' = case s of
811+ (Str (c:_):_)
812+ | not (isPunctuation c || isSpace c) -> Str "," : Space : s
813+ _ -> s
810− in init ks ++ [k {citationSuffix = citationSuffix k ++ toList s}]
814+ in init ks ++ [k {citationSuffix = citationSuffix k ++ s'}]
811addSuffix _ _ = []
815addSuffix _ _ = []
812
816
813simpleCiteArgs :: LP [Citation]
817simpleCiteArgs :: LP [Citation]
814simpleCiteArgs = try $ do
818simpleCiteArgs = try $ do
815− first <- optionMaybe opt
819+ first <- optionMaybe $ toList <$> opt
816− second <- optionMaybe opt
820+ second <- optionMaybe $ toList <$> opt
817 char '{'
821 char '{'
818 keys <- manyTill citationLabel (char '}')
822 keys <- manyTill citationLabel (char '}')
819 let (pre, suf) = case (first , second ) of
823 let (pre, suf) = case (first , second ) of
@@ -850,7 +854,7 @@ citation name mode multi = do
850
854
851complexNatbibCitation :: CitationMode -> LP Inlines
855complexNatbibCitation :: CitationMode -> LP Inlines
852complexNatbibCitation mode = try $ do
856complexNatbibCitation mode = try $ do
853− let ils = (trimInlines . mconcat) <$>
857+ let ils = (toList . trimInlines . mconcat) <$>
854 many (notFollowedBy (oneOf "\\};") >> inline)
858 many (notFollowedBy (oneOf "\\};") >> inline)
855 let parseOne = try $ do
859 let parseOne = try $ do
856 skipSpaces
860 skipSpaces
tests/latex-reader.native+1−1
@@ -259,7 +259,7 @@ Pandoc (Meta {docTitle = [Str "Pandoc",Space,Str "Test",Space,Str "Suite"], docA
259,HorizontalRule
259,HorizontalRule
260,Header 1 [Str "LaTeX"]
260,Header 1 [Str "LaTeX"]
261,BulletList
261,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}"]]]
263 ,[Para [RawInline "latex" "\\doublespacing"]]
263 ,[Para [RawInline "latex" "\\doublespacing"]]
264 ,[Para [Math InlineMath "2+2=4"]]
264 ,[Para [Math InlineMath "2+2=4"]]
265 ,[Para [Math InlineMath "x \\in y"]]
265 ,[Para [Math InlineMath "x \\in y"]]