@@ -1421,24 +1421,35 @@ citeCommand c p s k = do
14211421 args <- citeArguments p s k
14221422 return $ literal ("\\" <> c) <> args
14231423
1424+type Prefix = [Inline]
1425+type Suffix = [Inline]
1426+type CiteId = Text
1427+data CiteGroup = CiteGroup Prefix Suffix [CiteId]
1428+
1429+citeArgumentsList :: PandocMonad m
1430+ => CiteGroup -> LW m (Doc Text)
1431+citeArgumentsList (CiteGroup _ _ []) = return empty
1432+citeArgumentsList (CiteGroup pfxs sfxs ids) = do
1433+ pdoc <- inlineListToLaTeX pfxs
1434+ sdoc <- inlineListToLaTeX sfxs'
1435+ return $ (optargs pdoc sdoc) <>
1436+ (braces (literal (T.intercalate "," (reverse ids))))
1437+ where sfxs' = stripLocatorBraces $ case sfxs of
1438+ (Str t : r) -> case T.uncons t of
1439+ Just (x, xs)
1440+ | T.null xs
1441+ , isPunctuation x -> dropWhile (== Space) r
1442+ | isPunctuation x -> Str xs : r
1443+ _ -> sfxs
1444+ _ -> sfxs
1445+ optargs pdoc sdoc = case (isEmpty pdoc, isEmpty sdoc) of
1446+ (True, True ) -> empty
1447+ (True, False) -> brackets sdoc
1448+ (_ , _ ) -> brackets pdoc <> brackets sdoc
1449+
14241450citeArguments :: PandocMonad m
14251451 => [Inline] -> [Inline] -> Text -> LW m (Doc Text)
1426−citeArguments p s k = do
1427− let s' = stripLocatorBraces $ case s of
1428− (Str t : r) -> case T.uncons t of
1429− Just (x, xs)
1430− | T.null xs
1431− , isPunctuation x -> dropWhile (== Space) r
1432− | isPunctuation x -> Str xs : r
1433− _ -> s
1434− _ -> s
1435− pdoc <- inlineListToLaTeX p
1436− sdoc <- inlineListToLaTeX s'
1437− let optargs = case (isEmpty pdoc, isEmpty sdoc) of
1438− (True, True ) -> empty
1439− (True, False) -> brackets sdoc
1440− (_ , _ ) -> brackets pdoc <> brackets sdoc
1441− return $ optargs <> braces (literal k)
1452+citeArguments p s k = citeArgumentsList (CiteGroup p s [k])
14421453
14431454-- strip off {} used to define locator in pandoc-citeproc; see #5722
14441455stripLocatorBraces :: [Inline] -> [Inline]
@@ -1470,18 +1481,24 @@ citationsToBiblatex (c:cs)
14701481 NormalCitation -> "\\autocite"
14711482 return $ text cmd <>
14721483 braces (literal (T.intercalate "," (map citationId (c:cs))))
1473− | otherwise = do
1474− let cmd = case citationMode c of
1484+ | otherwise
1485+ = do
1486+ let cmd = case citationMode c of
14751487 SuppressAuthor -> "\\autocites*"
14761488 AuthorInText -> "\\textcites"
14771489 NormalCitation -> "\\autocites"
1478− let convertOne Citation { citationId = k
1479− , citationPrefix = p
1480− , citationSuffix = s
1481− }
1482− = citeArguments p s k
1483− args <- mapM convertOne (c:cs)
1484− return $ text cmd <> foldl' (<>) empty args
1490+
1491+ groups <- mapM citeArgumentsList (reverse (foldl' grouper [] (c:cs)))
1492+
1493+ return $ text cmd <> (mconcat groups)
1494+
1495+ where grouper prev cit = case prev of
1496+ ((CiteGroup oPfx oSfx ids):rest)
1497+ | null oSfx && null pfx -> (CiteGroup oPfx sfx (cid:ids)):rest
1498+ _ -> (CiteGroup pfx sfx [cid]):prev
1499+ where pfx = citationPrefix cit
1500+ sfx = citationSuffix cit
1501+ cid = citationId cit
14851502
14861503citationsToBiblatex _ = return empty
14871504