From a125b56ba1610954f31c8d933e5dd7e03eb25ed4 Mon Sep 17 00:00:00 2001 From: Laurent Rene de Cotret Date: Fri, 27 Sep 2024 13:17:07 -0400 Subject: [PATCH] Fixed an issue where TeX output contained a figure even if the caption was empty --- CHANGELOG.md | 4 ++++ pandoc-plot.cabal | 2 +- src/Text/Pandoc/Filter/Plot/Embed.hs | 14 +++++++++----- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52a1051..4342212 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ pandoc-plot uses [Semantic Versioning](http://semver.org/spec/v2.0.0.html) +## Release 1.9.2 + +* Fixed an issue where TeX output contained a figure even if the caption was empty (#37). + ## Release 1.9.1 * Fixed an issue where extra parameters were not passed down to `pandoc`, depending on the output format (#38). diff --git a/pandoc-plot.cabal b/pandoc-plot.cabal index 3ba91f4..12d7862 100644 --- a/pandoc-plot.cabal +++ b/pandoc-plot.cabal @@ -1,6 +1,6 @@ cabal-version: 2.2 name: pandoc-plot -version: 1.9.1 +version: 1.9.2 synopsis: A Pandoc filter to include figures generated from code blocks using your plotting toolkit of choice. description: A Pandoc filter to include figures generated from code blocks. Keep the document and code in the same location. Output is diff --git a/src/Text/Pandoc/Filter/Plot/Embed.hs b/src/Text/Pandoc/Filter/Plot/Embed.hs index de3a931..cc7f343 100644 --- a/src/Text/Pandoc/Filter/Plot/Embed.hs +++ b/src/Text/Pandoc/Filter/Plot/Embed.hs @@ -82,11 +82,15 @@ figure :: PlotM Block figure as fp caption' = return . head . toList $ - -- We want the attributes both on the Figure element and the contained Image element - -- so that pandoc-plot plays nice with pandoc-crossref and other filters - figureWith as (simpleCaption (plain caption')) $ - plain $ - imageWith as (pack fp) mempty caption' + if null caption' + -- If there is no caption, a LaTeX figure may look strange. See #37 + then plain $ imageWith as (pack fp) mempty caption' + else + -- We want the attributes both on the Figure element and the contained Image element + -- so that pandoc-plot plays nice with pandoc-crossref and other filters + figureWith as (simpleCaption (plain caption')) $ + plain $ + imageWith as (pack fp) mempty caption' -- TODO: also add the case where SVG plots can be -- embedded in HTML output