diff --git a/CHANGELOG.md b/CHANGELOG.md index aaf815c..52a1051 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.1 + +* Fixed an issue where extra parameters were not passed down to `pandoc`, depending on the output format (#38). + ## Release 1.9.0 * Added support for [Mermaid](https://mermaid.js.org/), thanks to a contribution by Sanchayan Maity (#74). diff --git a/docs/manual-content.md b/docs/manual-content.md index e5dc6dc..8176bf0 100644 --- a/docs/manual-content.md +++ b/docs/manual-content.md @@ -195,7 +195,8 @@ There are parameters that affect the figure that will be included in your docume dependencies=[...] file=(path) executable=(path) - caption_format=(text) + caption_format=(text), + ... } # script content ``` @@ -219,6 +220,36 @@ All following parameters are optional, with their default values controlled by t * `executable` is a path to the executable to use (e.g. `C:\\python3.exe`) or the name of the executable (e.g. `python3`). * `caption_format` is the text format of the caption. Possible values are exactly the same as `pandoc`'s format specification, usually `FORMAT+EXTENSION-EXTENSION`. For example, captions in Markdown with raw LaTeX would be parsed correctly provided that `caption_format=markdown+raw_tex`. See Pandoc's guide on [Specifying formats](https://pandoc.org/MANUAL.html#specifying-formats). +**All parameters not understood by `pandoc-plot` will be forwarded to pandoc**. For example, the following script: + +````markdown + Paragraph + + ```{.graphviz width=50mm height=60mm} + digraph D { + + A [shape=diamond] + B [shape=box] + C [shape=circle] + + A -> B [style=dashed, color=grey] + A -> C [color="black:invis:black"] + A -> D [penwidth=5, arrowhead=none] + + } + ``` +```` + +contains two extra parameters, `width=50mm` and `height=60mm`. When rendered with `pandoc --filter pandoc-plot -i example.md -o example.tex`, the output will be: + +````latex +\begin{figure} +\centering +\includegraphics[width=50mm,height=60mm]{plots/11623886912816197297.png} +\caption{} +\end{figure} +```` + #### Code highlighting diff --git a/pandoc-plot.cabal b/pandoc-plot.cabal index c1863e4..3ba91f4 100644 --- a/pandoc-plot.cabal +++ b/pandoc-plot.cabal @@ -1,6 +1,6 @@ cabal-version: 2.2 name: pandoc-plot -version: 1.9.0 +version: 1.9.1 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 c73db3b..de3a931 100644 --- a/src/Text/Pandoc/Filter/Plot/Embed.hs +++ b/src/Text/Pandoc/Filter/Plot/Embed.hs @@ -86,7 +86,7 @@ figure as fp caption' = -- so that pandoc-plot plays nice with pandoc-crossref and other filters figureWith as (simpleCaption (plain caption')) $ plain $ - imageWith mempty (pack fp) mempty caption' + imageWith as (pack fp) mempty caption' -- TODO: also add the case where SVG plots can be -- embedded in HTML output @@ -111,19 +111,22 @@ figure as fp caption' = -- |] latexInput :: Attr -> FilePath -> Inlines -> PlotM Block -latexInput _ fp caption' = do +latexInput (_, _, attrs) fp caption' = do renderedCaption' <- writeLatex caption' let renderedCaption = if renderedCaption' /= "" then [st|\caption{#{renderedCaption'}}|] else "" + -- We need to propagate extra attributes, for example, to control + -- figure sizes. See #38 + let renderedExtraAttributes = mconcat $ [key <> "=" <> value | (key, value) <- attrs] return $ RawBlock "latex" [st| \begin{figure} \centering - \input{#{pack $ normalizePath $ fp}} + \includegraphics[#{renderedExtraAttributes}]{#{pack $ normalizePath $ fp}} #{renderedCaption} \end{figure} |] diff --git a/src/Text/Pandoc/Filter/Plot/Parse.hs b/src/Text/Pandoc/Filter/Plot/Parse.hs index d440239..f043ca2 100644 --- a/src/Text/Pandoc/Filter/Plot/Parse.hs +++ b/src/Text/Pandoc/Filter/Plot/Parse.hs @@ -117,6 +117,8 @@ parseFigureSpec block@(CodeBlock (id', classes, attrs) _) = do extraAttrs = Map.toList extraAttrs' blockAttrs = (id', filter (/= cls toolkit) classes, filteredAttrs) + debug $ "Propagating attributes unrelated to pandoc-plot: " <> tshow blockAttrs + let blockDependencies = parseFileDependencies $ fromMaybe mempty $ Map.lookup (tshow DependenciesK) attrs' dependencies = defaultDependencies conf <> blockDependencies