git.iko.soy/typeable/pandoc
on master help sign in
LaTeX reader: Use new suppressParens option for footnote citations.
7499499John MacFarlane
src/Text/Pandoc/Biblio.hs+3−2
@@ -111,10 +111,10 @@ getCitation i | Cite t _ <- i = [t]
111 | otherwise = []
111 | otherwise = []
112
112
113setHash :: Citation -> State Int Citation
113setHash :: Citation -> State Int Citation
114−setHash (Citation i p s cm nn _) = do
114+setHash c = do
115 ident <- get
115 ident <- get
116 put $ ident + 1
116 put $ ident + 1
117− return $ Citation i p s cm nn ident
117+ return c{ citationHash = ident }
118
118
119toCslCite :: Citation -> CSL.Cite
119toCslCite :: Citation -> CSL.Cite
120toCslCite c
120toCslCite c
@@ -140,6 +140,7 @@ toCslCite c
140 , CSL.citeNoteNumber = show $ citationNoteNum c
140 , CSL.citeNoteNumber = show $ citationNoteNum c
141 , CSL.authorInText = fst citMode
141 , CSL.authorInText = fst citMode
142 , CSL.suppressAuthor = snd citMode
142 , CSL.suppressAuthor = snd citMode
143+ , CSL.suppressParens = citationSuppressParens c
143 , CSL.citeHash = citationHash c
144 , CSL.citeHash = citationHash c
144 }
145 }
145
146
src/Text/Pandoc/Readers/LaTeX.hs+56−55
@@ -426,65 +426,61 @@ inlineCommands = M.fromList $
426 pure (link url "" lab))
426 pure (link url "" lab))
427 , ("includegraphics", skipopts *> (unescapeURL <$> braced) >>=
427 , ("includegraphics", skipopts *> (unescapeURL <$> braced) >>=
428 (\src -> pure (image src "" (str "image"))))
428 (\src -> pure (image src "" (str "image"))))
429− , ("cite", citation "cite" AuthorInText False)
429+ , ("cite", citation "cite" AuthorInText False False)
430− , ("citep", citation "citep" NormalCitation False)
430+ , ("citep", citation "citep" NormalCitation False False)
431− , ("citep*", citation "citep*" NormalCitation False)
431+ , ("citep*", citation "citep*" NormalCitation False False)
432− , ("citeal", citation "citeal" NormalCitation False)
432+ , ("citeal", citation "citeal" NormalCitation False False)
433− , ("citealp", citation "citealp" NormalCitation False)
433+ , ("citealp", citation "citealp" NormalCitation False False)
434− , ("citealp*", citation "citealp*" NormalCitation False)
434+ , ("citealp*", citation "citealp*" NormalCitation False False)
435− , ("autocite", citation "autocite" NormalCitation False)
435+ , ("autocite", citation "autocite" NormalCitation False False)
436− , ("footcite", inNote <$> citation "footcite" NormalCitation False)
436+ , ("footcite", citation "footcite" NormalCitation False True)
437− , ("parencite", citation "parencite" NormalCitation False)
437+ , ("parencite", citation "parencite" NormalCitation False False)
438− , ("supercite", citation "supercite" NormalCitation False)
438+ , ("supercite", citation "supercite" NormalCitation False False)
439− , ("footcitetext", inNote <$> citation "footcitetext" NormalCitation False)
439+ , ("footcitetext", citation "footcitetext" NormalCitation False True)
440− , ("citeyearpar", citation "citeyearpar" SuppressAuthor False)
440+ , ("citeyearpar", citation "citeyearpar" SuppressAuthor False False)
441− , ("citeyear", citation "citeyear" SuppressAuthor False)
441+ , ("citeyear", citation "citeyear" SuppressAuthor False False)
442− , ("autocite*", citation "autocite*" SuppressAuthor False)
442+ , ("autocite*", citation "autocite*" SuppressAuthor False False)
443− , ("cite*", citation "cite*" SuppressAuthor False)
443+ , ("cite*", citation "cite*" SuppressAuthor False False)
444− , ("parencite*", citation "parencite*" SuppressAuthor False)
444+ , ("parencite*", citation "parencite*" SuppressAuthor False False)
445− , ("textcite", citation "textcite" AuthorInText False)
445+ , ("textcite", citation "textcite" AuthorInText False False)
446− , ("citet", citation "citet" AuthorInText False)
446+ , ("citet", citation "citet" AuthorInText False False)
447− , ("citet*", citation "citet*" AuthorInText False)
447+ , ("citet*", citation "citet*" AuthorInText False False)
448− , ("citealt", citation "citealt" AuthorInText False)
448+ , ("citealt", citation "citealt" AuthorInText False False)
449− , ("citealt*", citation "citealt*" AuthorInText False)
449+ , ("citealt*", citation "citealt*" AuthorInText False False)
450− , ("textcites", citation "textcites" AuthorInText True)
450+ , ("textcites", citation "textcites" AuthorInText True False)
451− , ("cites", citation "cites" NormalCitation True)
451+ , ("cites", citation "cites" NormalCitation True False)
452− , ("autocites", citation "autocites" NormalCitation True)
452+ , ("autocites", citation "autocites" NormalCitation True False)
453− , ("footcites", inNote <$> citation "footcites" NormalCitation True)
453+ , ("footcites", citation "footcites" NormalCitation True True)
454− , ("parencites", citation "parencites" NormalCitation True)
454+ , ("parencites", citation "parencites" NormalCitation True False)
455− , ("supercites", citation "supercites" NormalCitation True)
455+ , ("supercites", citation "supercites" NormalCitation True False)
456− , ("footcitetexts", inNote <$> citation "footcitetexts" NormalCitation True)
456+ , ("footcitetexts", citation "footcitetexts" NormalCitation True True)
457− , ("Autocite", citation "Autocite" NormalCitation False)
457+ , ("Autocite", citation "Autocite" NormalCitation False False)
458− , ("Footcite", citation "Footcite" NormalCitation False)
458+ , ("Footcite", citation "Footcite" NormalCitation False False)
459− , ("Parencite", citation "Parencite" NormalCitation False)
459+ , ("Parencite", citation "Parencite" NormalCitation False False)
460− , ("Supercite", citation "Supercite" NormalCitation False)
460+ , ("Supercite", citation "Supercite" NormalCitation False False)
461− , ("Footcitetext", inNote <$> citation "Footcitetext" NormalCitation False)
461+ , ("Footcitetext", citation "Footcitetext" NormalCitation False True)
462− , ("Citeyearpar", citation "Citeyearpar" SuppressAuthor False)
462+ , ("Citeyearpar", citation "Citeyearpar" SuppressAuthor False False)
463− , ("Citeyear", citation "Citeyear" SuppressAuthor False)
463+ , ("Citeyear", citation "Citeyear" SuppressAuthor False False)
464− , ("Autocite*", citation "Autocite*" SuppressAuthor False)
464+ , ("Autocite*", citation "Autocite*" SuppressAuthor False False)
465− , ("Cite*", citation "Cite*" SuppressAuthor False)
465+ , ("Cite*", citation "Cite*" SuppressAuthor False False)
466− , ("Parencite*", citation "Parencite*" SuppressAuthor False)
466+ , ("Parencite*", citation "Parencite*" SuppressAuthor False False)
467− , ("Textcite", citation "Textcite" AuthorInText False)
467+ , ("Textcite", citation "Textcite" AuthorInText False False)
468− , ("Textcites", citation "Textcites" AuthorInText True)
468+ , ("Textcites", citation "Textcites" AuthorInText True False)
469− , ("Cites", citation "Cites" NormalCitation True)
469+ , ("Cites", citation "Cites" NormalCitation True False)
470− , ("Autocites", citation "Autocites" NormalCitation True)
470+ , ("Autocites", citation "Autocites" NormalCitation True False)
471− , ("Footcites", citation "Footcites" NormalCitation True)
471+ , ("Footcites", citation "Footcites" NormalCitation True False)
472− , ("Parencites", citation "Parencites" NormalCitation True)
472+ , ("Parencites", citation "Parencites" NormalCitation True False)
473− , ("Supercites", citation "Supercites" NormalCitation True)
473+ , ("Supercites", citation "Supercites" NormalCitation True False)
474− , ("Footcitetexts", inNote <$> citation "Footcitetexts" NormalCitation True)
474+ , ("Footcitetexts", citation "Footcitetexts" NormalCitation True True)
475 , ("citetext", complexNatbibCitation NormalCitation)
475 , ("citetext", complexNatbibCitation NormalCitation)
476 , ("citeauthor", (try (tok *> optional sp *> controlSeq "citetext") *>
476 , ("citeauthor", (try (tok *> optional sp *> controlSeq "citetext") *>
477 complexNatbibCitation AuthorInText)
477 complexNatbibCitation AuthorInText)
478− <|> citation "citeauthor" AuthorInText False)
478+ <|> citation "citeauthor" AuthorInText False False)
479 ] ++ map ignoreInlines
479 ] ++ map ignoreInlines
480 -- these commands will be ignored unless --parse-raw is specified,
480 -- these commands will be ignored unless --parse-raw is specified,
481 -- in which case they will appear as raw latex blocks:
481 -- in which case they will appear as raw latex blocks:
482 [ "noindent", "index", "nocite" ]
482 [ "noindent", "index", "nocite" ]
483
483
484−inNote :: Inlines -> Inlines
485−inNote ils =
486− note $ para $ ils <> str "."
487−
488unescapeURL :: String -> String
484unescapeURL :: String -> String
489unescapeURL ('\\':x:xs) | isEscapable x = x:unescapeURL xs
485unescapeURL ('\\':x:xs) | isEscapable x = x:unescapeURL xs
490 where isEscapable '%' = True
486 where isEscapable '%' = True
@@ -899,6 +895,7 @@ simpleCiteArgs = try $ do
899 , citationSuffix = []
895 , citationSuffix = []
900 , citationMode = NormalCitation
896 , citationMode = NormalCitation
901 , citationHash = 0
897 , citationHash = 0
898+ , citationSuppressParens = False
902 , citationNoteNum = 0
899 , citationNoteNum = 0
903 }
900 }
904 return $ addPrefix pre $ addSuffix suf $ map conv keys
901 return $ addPrefix pre $ addSuffix suf $ map conv keys
@@ -917,10 +914,14 @@ cites mode multi = try $ do
917 AuthorInText -> c {citationMode = mode} : cs
914 AuthorInText -> c {citationMode = mode} : cs
918 _ -> map (\a -> a {citationMode = mode}) (c:cs)
915 _ -> map (\a -> a {citationMode = mode}) (c:cs)
919
916
920−citation :: String -> CitationMode -> Bool -> LP Inlines
917+citation :: String -> CitationMode -> Bool -> Bool -> LP Inlines
921−citation name mode multi = do
918+citation name mode multi inNote = do
922− (c,raw) <- withRaw $ cites mode multi
919+ (cs,raw) <- withRaw $ cites mode multi
920+ let cs' = if inNote then map (\c -> c{ citationSuppressParens = True }) cs else cs
923− return $ cite c (rawInline "latex" $ "\\" ++ name ++ raw)
921+ let cit = cite cs' (rawInline "latex" $ "\\" ++ name ++ raw)
922+ if inNote
923+ then return $ note $ para $ cit <> str "."
924+ else return cit
924
925
925complexNatbibCitation :: CitationMode -> LP Inlines
926complexNatbibCitation :: CitationMode -> LP Inlines
926complexNatbibCitation mode = try $ do
927complexNatbibCitation mode = try $ do
src/Text/Pandoc/Readers/Markdown.hs+16−14
@@ -1554,12 +1554,13 @@ cite = do
1554textualCite :: Parser [Char] ParserState (F [Citation])
1554textualCite :: Parser [Char] ParserState (F [Citation])
1555textualCite = try $ do
1555textualCite = try $ do
1556 (_, key) <- citeKey
1556 (_, key) <- citeKey
1557− let first = Citation{ citationId = key
1557+ let first = Citation{ citationId = key
1558− , citationPrefix = []
1558+ , citationPrefix = []
1559− , citationSuffix = []
1559+ , citationSuffix = []
1560− , citationMode = AuthorInText
1560+ , citationMode = AuthorInText
1561− , citationNoteNum = 0
1561+ , citationNoteNum = 0
1562+ , citationSuppressParens = False
1562− , citationHash = 0
1563+ , citationHash = 0
1563 }
1564 }
1564 mbrest <- option Nothing $ try $ spnl >> Just <$> normalCite
1565 mbrest <- option Nothing $ try $ spnl >> Just <$> normalCite
1565 case mbrest of
1566 case mbrest of
@@ -1624,14 +1625,15 @@ citation = try $ do
1624 return $ do
1625 return $ do
1625 x <- pref
1626 x <- pref
1626 y <- suff
1627 y <- suff
1627− return $ Citation{ citationId = key
1628+ return $ Citation{ citationId = key
1628− , citationPrefix = B.toList x
1629+ , citationPrefix = B.toList x
1629− , citationSuffix = B.toList y
1630+ , citationSuffix = B.toList y
1630− , citationMode = if suppress_author
1631+ , citationMode = if suppress_author
1631− then SuppressAuthor
1632+ then SuppressAuthor
1632− else NormalCitation
1633+ else NormalCitation
1633− , citationNoteNum = 0
1634+ , citationNoteNum = 0
1635+ , citationSuppressParens = False
1634− , citationHash = 0
1636+ , citationHash = 0
1635 }
1637 }
1636
1638
1637smart :: Parser [Char] ParserState (F Inlines)
1639smart :: Parser [Char] ParserState (F Inlines)
tests/Tests/Readers/LaTeX.hs+7−6
@@ -62,12 +62,13 @@ tests = [ testGroup "basic"
62 ]
62 ]
63
63
64baseCitation :: Citation
64baseCitation :: Citation
65−baseCitation = Citation{ citationId = "item1"
65+baseCitation = Citation{ citationId = "item1"
66− , citationPrefix = []
66+ , citationPrefix = []
67− , citationSuffix = []
67+ , citationSuffix = []
68− , citationMode = AuthorInText
68+ , citationMode = AuthorInText
69− , citationNoteNum = 0
69+ , citationNoteNum = 0
70+ , citationSuppressParens = False
70− , citationHash = 0 }
71+ , citationHash = 0 }
71
72
72rt :: String -> Inlines
73rt :: String -> Inlines
73rt = rawInline "latex"
74rt = rawInline "latex"