diff options
| author | Albert Krewinkel <[email protected]> | 2022-08-17 12:21:47 +0200 |
|---|---|---|
| committer | Albert Krewinkel <[email protected]> | 2022-08-17 12:39:07 +0200 |
| commit | 81e31ee637935ce7ba076bdd5a648c2489698d2d (patch) | |
| tree | eec767a3dd83a014c65f39e23c7703cd17edac2e /src | |
| parent | c5f8a38f38aa20da77042b0a6c984e8f74db855a (diff) | |
LaTeX writer: add label to tables that have an identifier
Tables with an identifier are marked with a `\label`. A caption is
always included in this case, even if the caption is empty.
Closes: #8219
Diffstat (limited to 'src')
| -rw-r--r-- | src/Text/Pandoc/Writers/LaTeX/Table.hs | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/Text/Pandoc/Writers/LaTeX/Table.hs b/src/Text/Pandoc/Writers/LaTeX/Table.hs index 38ba60764..4fbebd1be 100644 --- a/src/Text/Pandoc/Writers/LaTeX/Table.hs +++ b/src/Text/Pandoc/Writers/LaTeX/Table.hs @@ -33,6 +33,7 @@ import Text.Pandoc.Writers.LaTeX.Notes (notesToLaTeX) import Text.Pandoc.Writers.LaTeX.Types ( LW, WriterState (stBeamer, stExternalNotes, stInMinipage, stMultiRow , stNotes, stTable) ) +import Text.Pandoc.Writers.LaTeX.Util (labelFor) import Text.Printf (printf) import qualified Text.Pandoc.Builder as B import qualified Text.Pandoc.Writers.AnnotatedTable as Ann @@ -43,8 +44,8 @@ tableToLaTeX :: PandocMonad m -> Ann.Table -> LW m (Doc Text) tableToLaTeX inlnsToLaTeX blksToLaTeX tbl = do - let (Ann.Table _attr caption specs thead tbodies tfoot) = tbl - CaptionDocs capt captNotes <- captionToLaTeX inlnsToLaTeX caption + let (Ann.Table (ident, _, _) caption specs thead tbodies tfoot) = tbl + CaptionDocs capt captNotes <- captionToLaTeX inlnsToLaTeX caption ident let removeNote (Note _) = Span ("", [], []) [] removeNote x = x let colCount = ColumnCount $ length specs @@ -144,16 +145,20 @@ data CaptionDocs = captionToLaTeX :: PandocMonad m => ([Inline] -> LW m (Doc Text)) -> Caption + -> Text -- ^ table identifier (label) -> LW m CaptionDocs -captionToLaTeX inlnsToLaTeX (Caption _maybeShort longCaption) = do +captionToLaTeX inlnsToLaTeX (Caption _maybeShort longCaption) ident = do let caption = blocksToInlines longCaption - (captionText, captForLof, captNotes) <- getCaption inlnsToLaTeX False caption + (captionText, captForLot, captNotes) <- getCaption inlnsToLaTeX False caption + label <- labelFor ident return $ CaptionDocs { captionNotes = captNotes - , captionCommand = if isEmpty captionText + , captionCommand = if isEmpty captionText && isEmpty label then empty - else "\\caption" <> captForLof <> - braces captionText <> "\\tabularnewline" + else "\\caption" <> captForLot <> + braces captionText + <> label + <> "\\tabularnewline" } type BlocksWriter m = [Block] -> LW m (Doc Text) |
