aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers/LaTeX.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2020-02-11 22:23:22 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2020-02-11 22:28:06 -0800
commit3fbee8c6edb2caf76530f834f0001950b44c5b17 (patch)
tree62e9ba9071c30f3a7fa122c0e837320f3ec7edc1 /src/Text/Pandoc/Readers/LaTeX.hs
parent4bd8a35e8ffbf3e17584dc46cb647e0f1ea14b91 (diff)
downloadpandoc-3fbee8c6edb2caf76530f834f0001950b44c5b17.tar.gz
LaTeX reader: resolve `\ref` to table numbers.
Closes #6137.
Diffstat (limited to 'src/Text/Pandoc/Readers/LaTeX.hs')
-rw-r--r--src/Text/Pandoc/Readers/LaTeX.hs66
1 files changed, 41 insertions, 25 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs
index 0bafa0d19..cae7a23b7 100644
--- a/src/Text/Pandoc/Readers/LaTeX.hs
+++ b/src/Text/Pandoc/Readers/LaTeX.hs
@@ -2078,33 +2078,40 @@ addImageCaption = walkM go
case attr' of
("", _, _) -> return ()
(ident, _, _) -> do
- st <- getState
- let chapnum =
- case (sHasChapters st, sLastHeaderNum st) of
- (True, DottedNum (n:_)) -> Just n
- _ -> Nothing
- let num = case sLastFigureNum st of
- DottedNum [m,n] ->
- case chapnum of
- Just m' | m' == m -> DottedNum [m, n+1]
- | otherwise -> DottedNum [m', 1]
- Nothing -> DottedNum [1]
- -- shouldn't happen
- DottedNum [n] ->
- case chapnum of
- Just m -> DottedNum [m, 1]
- Nothing -> DottedNum [n + 1]
- _ ->
- case chapnum of
- Just n -> DottedNum [n, 1]
- Nothing -> DottedNum [1]
- setState $
+ num <- getNextNumber sLastFigureNum
+ updateState $ \st ->
st{ sLastFigureNum = num
, sLabels = M.insert ident
[Str (renderDottedNum num)] (sLabels st) }
return $ Image attr' alt' (src, tit')
go x = return x
+getNextNumber :: Monad m
+ => (LaTeXState -> DottedNum) -> LP m DottedNum
+getNextNumber getCurrentNum = do
+ st <- getState
+ let chapnum =
+ case (sHasChapters st, sLastHeaderNum st) of
+ (True, DottedNum (n:_)) -> Just n
+ _ -> Nothing
+ return $
+ case getCurrentNum st of
+ DottedNum [m,n] ->
+ case chapnum of
+ Just m' | m' == m -> DottedNum [m, n+1]
+ | otherwise -> DottedNum [m', 1]
+ Nothing -> DottedNum [1]
+ -- shouldn't happen
+ DottedNum [n] ->
+ case chapnum of
+ Just m -> DottedNum [m, 1]
+ Nothing -> DottedNum [n + 1]
+ _ ->
+ case chapnum of
+ Just n -> DottedNum [n, 1]
+ Nothing -> DottedNum [1]
+
+
coloredBlock :: PandocMonad m => Text -> LP m Blocks
coloredBlock stylename = try $ do
skipopts
@@ -2379,10 +2386,19 @@ simpTable envname hasWidthParameter = try $ do
addTableCaption :: PandocMonad m => Blocks -> LP m Blocks
addTableCaption = walkM go
where go (Table c als ws hs rs) = do
- (mbcapt, _) <- sCaption <$> getState
- return $ case mbcapt of
- Just ils -> Table (toList ils) als ws hs rs
- Nothing -> Table c als ws hs rs
+ (mbcapt, mblabel) <- sCaption <$> getState
+ capt <- case (mbcapt, mblabel) of
+ (Just ils, Nothing) -> return $ toList ils
+ (Just ils, Just lab) -> do
+ num <- getNextNumber sLastTableNum
+ updateState $ \st ->
+ st{ sLastTableNum = num
+ , sLabels = M.insert lab
+ [Str (renderDottedNum num)]
+ (sLabels st) }
+ return $ toList ils -- add number??
+ (Nothing, _) -> return c
+ return $ Table capt als ws hs rs
go x = return x