@@ -302,6 +302,7 @@ blockCommands = M.fromList $
302 , ("item", skipopts *> loose_item)
302 , ("item", skipopts *> loose_item)
303 , ("documentclass", skipopts *> braced *> preamble)
303 , ("documentclass", skipopts *> braced *> preamble)
304 , ("centerline", (para . trimInlines) <$> (skipopts *> tok))
304 , ("centerline", (para . trimInlines) <$> (skipopts *> tok))
305+ , ("caption", tok >>= setCaption)
305 ] ++ map ignoreBlocks
306 ] ++ map ignoreBlocks
306 -- these commands will be ignored unless --parse-raw is specified,
307 -- these commands will be ignored unless --parse-raw is specified,
307 -- in which case they will appear as raw latex blocks
308 -- in which case they will appear as raw latex blocks
@@ -323,6 +324,14 @@ blockCommands = M.fromList $
323addMeta :: ToMetaValue a => String -> a -> LP ()
324addMeta :: ToMetaValue a => String -> a -> LP ()
324addMeta field val = updateState $ setMeta field val
325addMeta field val = updateState $ setMeta field val
327+setCaption :: Inlines -> LP Blocks
329+ updateState $ \st -> st{ stateCaption = Just ils }
332+resetCaption :: LP ()
333+resetCaption = updateState $ \st -> st{ stateCaption = Nothing }
326authors :: LP ()
335authors :: LP ()
327authors = try $ do
336authors = try $ do
@@ -523,18 +532,12 @@ inlineCommands = M.fromList $
524mkImage :: String -> LP Inlines
533mkImage :: String -> LP Inlines
525mkImage src = do
534mkImage src = do
526− -- try for a caption
527− (alt, tit) <- option (str "image", "") $ try $ do
535+ let alt = str "image"
529− controlSeq "caption"
531− ils <- grouped inline
532− return (ils, "fig:")
533 case takeExtension src of
536 case takeExtension src of
535 defaultExt <- getOption readerDefaultImageExtension
538 defaultExt <- getOption readerDefaultImageExtension
536− return $ image (addExtension src defaultExt) tit alt
539+ return $ image (addExtension src defaultExt) "" alt
537− _ -> return $ image src tit alt
540+ _ -> return $ image src "" alt
539inNote :: Inlines -> Inlines
542inNote :: Inlines -> Inlines
540inNote ils =
543inNote ils =
@@ -888,13 +891,33 @@ rawLaTeXInline = do
888 raw <- (snd <$> withRaw inlineCommand) <|> (snd <$> withRaw blockCommand)
891 raw <- (snd <$> withRaw inlineCommand) <|> (snd <$> withRaw blockCommand)
889 RawInline "latex" <$> applyMacros' raw
892 RawInline "latex" <$> applyMacros' raw
894+addImageCaption :: Blocks -> LP Blocks
895+addImageCaption = walkM go
896+ where go (Image alt (src,tit)) = do
897+ mbcapt <- stateCaption <$> getState
899+ Just ils -> return (Image (toList ils) (src, "fig:"))
900+ Nothing -> return (Image alt (src,tit))
903+addTableCaption :: Blocks -> LP Blocks
904+addTableCaption = walkM go
905+ where go (Table c als ws hs rs) = do
906+ mbcapt <- stateCaption <$> getState
908+ Just ils -> return (Table (toList ils) als ws hs rs)
909+ Nothing -> return (Table c als ws hs rs)
891environments :: M.Map String (LP Blocks)
912environments :: M.Map String (LP Blocks)
892environments = M.fromList
913environments = M.fromList
893 [ ("document", env "document" blocks <* skipMany anyChar)
914 [ ("document", env "document" blocks <* skipMany anyChar)
894 , ("letter", env "letter" letter_contents)
915 , ("letter", env "letter" letter_contents)
895− , ("figure", env "figure" $ skipopts *> blocks)
916+ , ("figure", env "figure" $
917+ resetCaption *> skipopts *> blocks >>= addImageCaption)
896 , ("center", env "center" blocks)
918 , ("center", env "center" blocks)
897− , ("table", env "table" $ skipopts *> blocks)
919+ , ("table", env "table" $
920+ resetCaption *> skipopts *> blocks >>= addTableCaption)
898 , ("tabular", env "tabular" simpTable)
921 , ("tabular", env "tabular" simpTable)
899 , ("quote", blockQuote <$> env "quote" blocks)
922 , ("quote", blockQuote <$> env "quote" blocks)
900 , ("quotation", blockQuote <$> env "quotation" blocks)
923 , ("quotation", blockQuote <$> env "quotation" blocks)