@@ -159,7 +159,7 @@ data LaTeXState = LaTeXState{ sOptions :: ReaderOptions
159159 , sLogMessages :: [LogMessage]
160160 , sIdentifiers :: Set.Set String
161161 , sVerbatimMode :: Bool
162− , sCaption :: Maybe Inlines
162+ , sCaption :: (Maybe Inlines, Maybe String)
163163 , sInListItem :: Bool
164164 , sInTableCell :: Bool
165165 , sLastHeaderNum :: HeaderNum
@@ -179,7 +179,7 @@ defaultLaTeXState = LaTeXState{ sOptions = def
179179 , sLogMessages = []
180180 , sIdentifiers = Set.empty
181181 , sVerbatimMode = False
182− , sCaption = Nothing
182+ , sCaption = (Nothing, Nothing)
183183 , sInListItem = False
184184 , sInTableCell = False
185185 , sLastHeaderNum = HeaderNum []
@@ -2100,11 +2100,13 @@ setCaption = do
21002100 ils <- tok
21012101 mblabel <- option Nothing $
21022102 try $ spaces >> controlSeq "label" >> (Just <$> tok)
2103− let ils' = case mblabel of
2104− Just lab -> ils <> spanWith
2105− ("",[],[("label", stringify lab)]) mempty
2106− Nothing -> ils
2107− updateState $ \st -> st{ sCaption = Just ils' }
2103+ let capt = case mblabel of
2104+ Just lab -> let slab = stringify lab
2105+ ils' = ils <> spanWith
2106+ ("",[],[("label", slab)]) mempty
2107+ in (Just ils', Just slab)
2108+ Nothing -> (Just ils, Nothing)
2109+ updateState $ \st -> st{ sCaption = capt }
21082110 return mempty
21092111
21102112looseItem :: PandocMonad m => LP m Blocks
@@ -2115,7 +2117,7 @@ looseItem = do
21152117 return mempty
21162118
21172119resetCaption :: PandocMonad m => LP m ()
2118−resetCaption = updateState $ \st -> st{ sCaption = Nothing }
2120+resetCaption = updateState $ \st -> st{ sCaption = (Nothing, Nothing) }
21192121
21202122section :: PandocMonad m => Bool -> Attr -> Int -> LP m Blocks
21212123section starred (ident, classes, kvs) lvl = do
@@ -2405,12 +2407,16 @@ figure = try $ do
24052407
24062408addImageCaption :: PandocMonad m => Blocks -> LP m Blocks
24072409addImageCaption = walkM go
2408− where go (Image attr alt (src,tit))
2410+ where go (Image attr@(_, cls, kvs) alt (src,tit))
24092411 | not ("fig:" `isPrefixOf` tit) = do
2410− mbcapt <- sCaption <$> getState
2411− return $ case mbcapt of
2412− Just ils -> Image attr (toList ils) (src, "fig:" ++ tit)
2413− Nothing -> Image attr alt (src,tit)
2412+ (mbcapt, mblab) <- sCaption <$> getState
2413+ let (alt', tit') = case mbcapt of
2414+ Just ils -> (toList ils, "fig:" ++ tit)
2415+ Nothing -> (alt, tit)
2416+ attr' = case mblab of
2417+ Just lab -> (lab, cls, kvs)
2418+ Nothing -> attr
2419+ return $ Image attr' alt' (src, tit')
24142420 go x = return x
24152421
24162422coloredBlock :: PandocMonad m => String -> LP m Blocks
@@ -2682,7 +2688,7 @@ simpTable envname hasWidthParameter = try $ do
26822688addTableCaption :: PandocMonad m => Blocks -> LP m Blocks
26832689addTableCaption = walkM go
26842690 where go (Table c als ws hs rs) = do
2685− mbcapt <- sCaption <$> getState
2691+ (mbcapt, _) <- sCaption <$> getState
26862692 return $ case mbcapt of
26872693 Just ils -> Table (toList ils) als ws hs rs
26882694 Nothing -> Table c als ws hs rs