diff options
| author | Sean Soon <[email protected]> | 2025-09-01 19:41:14 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-09-01 20:41:14 +0200 |
| commit | 5424d3eca0e127de7a59baea9b11649b1c17e5b2 (patch) | |
| tree | 1413ff56fd3cac29487a8b7c643c8471ae64abf4 /src | |
| parent | c74f2b8588cd58d40932e758aec9cb7fb963a76d (diff) | |
LaTeX writer: control figure placement with attribute (#11094)
If a `latex-pos` attribute is present on a figure, it will be used as the
optional positioning hint in LaTeX (e.g. `ht`).
With implicit figures, `latex-pos` will be added to the figure (and
removed from the image) if it is present on the image.
Closes #10369.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Text/Pandoc/Readers/Markdown.hs | 7 | ||||
| -rw-r--r-- | src/Text/Pandoc/Writers/LaTeX.hs | 7 |
2 files changed, 10 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index b9451f2e1..61e843662 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -1057,8 +1057,11 @@ implicitFigure (ident, classes, attribs) capt url title = let alt = case "alt" `lookup` attribs of Just alt' -> B.text alt' _ -> capt - attribs' = filter ((/= "alt") . fst) attribs - figattr = (ident, mempty, mempty) + attribs' = filter ((/= "latex-pos") . fst) (filter ((/= "alt") . fst) attribs) + figattribs = case lookup "latex-pos" attribs of + Just p -> [("latex-pos", p)] + _ -> mempty + figattr = (ident, mempty, figattribs) caption = B.simpleCaption $ B.plain capt figbody = B.plain $ B.imageWith ("", classes, attribs') url title alt in B.figureWith figattr caption figbody diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs index fe549ad17..e1ae080f6 100644 --- a/src/Text/Pandoc/Writers/LaTeX.hs +++ b/src/Text/Pandoc/Writers/LaTeX.hs @@ -644,11 +644,14 @@ blockToLaTeX (Header level (id',classes,_) lst) = do blockToLaTeX (Table attr blkCapt specs thead tbodies tfoot) = tableToLaTeX inlineListToLaTeX blockListToLaTeX (Ann.toTable attr blkCapt specs thead tbodies tfoot) -blockToLaTeX (Figure (ident, _, _) captnode body) = do +blockToLaTeX (Figure (ident, _, kvs) captnode body) = do opts <- gets stOptions (capt, captForLof, footnotes) <- getCaption inlineListToLaTeX True captnode lab <- labelFor ident let caption = "\\caption" <> captForLof <> braces capt <> lab + placement = case lookup "latex-pos" kvs of + Just p -> brackets (text (T.unpack p)) + _ -> text "" isSubfigure <- gets stInFigure modify $ \st -> st{ stInFigure = True } @@ -680,7 +683,7 @@ blockToLaTeX (Figure (ident, _, _) captnode body) = do cr <> "\\begin{center}" $$ contents $+$ capt $$ "\\end{center}" _ | isSubfigure -> innards - _ -> cr <> "\\begin{figure}" $$ innards $$ "\\end{figure}") + _ -> cr <> "\\begin{figure}" <> placement $$ innards $$ "\\end{figure}") $$ footnotes toSubfigure :: PandocMonad m => Int -> Block -> LW m (Doc Text) |
