Skip to content

Commit 7e49525

Browse files
committed
Propagate extra attributes at the figure AND image level
1 parent 2562d7e commit 7e49525

File tree

5 files changed

+45
-5
lines changed

5 files changed

+45
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
pandoc-plot uses [Semantic Versioning](http://semver.org/spec/v2.0.0.html)
44

5+
## Release 1.9.1
6+
7+
* Fixed an issue where extra parameters were not passed down to `pandoc`, depending on the output format (#38).
8+
59
## Release 1.9.0
610

711
* Added support for [Mermaid](https://mermaid.js.org/), thanks to a contribution by Sanchayan Maity (#74).

docs/manual-content.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ There are parameters that affect the figure that will be included in your docume
195195
dependencies=[...]
196196
file=(path)
197197
executable=(path)
198-
caption_format=(text)
198+
caption_format=(text),
199+
...
199200
}
200201
# script content
201202
```
@@ -219,6 +220,36 @@ All following parameters are optional, with their default values controlled by t
219220
* `executable` is a path to the executable to use (e.g. `C:\\python3.exe`) or the name of the executable (e.g. `python3`).
220221
* `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).
221222

223+
**All parameters not understood by `pandoc-plot` will be forwarded to pandoc**. For example, the following script:
224+
225+
````markdown
226+
Paragraph
227+
228+
```{.graphviz width=50mm height=60mm}
229+
digraph D {
230+
231+
A [shape=diamond]
232+
B [shape=box]
233+
C [shape=circle]
234+
235+
A -> B [style=dashed, color=grey]
236+
A -> C [color="black:invis:black"]
237+
A -> D [penwidth=5, arrowhead=none]
238+
239+
}
240+
```
241+
````
242+
243+
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:
244+
245+
````latex
246+
\begin{figure}
247+
\centering
248+
\includegraphics[width=50mm,height=60mm]{plots/11623886912816197297.png}
249+
\caption{}
250+
\end{figure}
251+
````
252+
222253

223254
#### Code highlighting
224255

pandoc-plot.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 2.2
22
name: pandoc-plot
3-
version: 1.9.0
3+
version: 1.9.1
44
synopsis: A Pandoc filter to include figures generated from code blocks using your plotting toolkit of choice.
55
description: A Pandoc filter to include figures generated from code blocks.
66
Keep the document and code in the same location. Output is

src/Text/Pandoc/Filter/Plot/Embed.hs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ figure as fp caption' =
8686
-- so that pandoc-plot plays nice with pandoc-crossref and other filters
8787
figureWith as (simpleCaption (plain caption')) $
8888
plain $
89-
imageWith mempty (pack fp) mempty caption'
89+
imageWith as (pack fp) mempty caption'
9090

9191
-- TODO: also add the case where SVG plots can be
9292
-- embedded in HTML output
@@ -111,19 +111,22 @@ figure as fp caption' =
111111
-- |]
112112

113113
latexInput :: Attr -> FilePath -> Inlines -> PlotM Block
114-
latexInput _ fp caption' = do
114+
latexInput (_, _, attrs) fp caption' = do
115115
renderedCaption' <- writeLatex caption'
116116
let renderedCaption =
117117
if renderedCaption' /= ""
118118
then [st|\caption{#{renderedCaption'}}|]
119119
else ""
120+
-- We need to propagate extra attributes, for example, to control
121+
-- figure sizes. See #38
122+
let renderedExtraAttributes = mconcat $ [key <> "=" <> value | (key, value) <- attrs]
120123
return $
121124
RawBlock
122125
"latex"
123126
[st|
124127
\begin{figure}
125128
\centering
126-
\input{#{pack $ normalizePath $ fp}}
129+
\includegraphics[#{renderedExtraAttributes}]{#{pack $ normalizePath $ fp}}
127130
#{renderedCaption}
128131
\end{figure}
129132
|]

src/Text/Pandoc/Filter/Plot/Parse.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ parseFigureSpec block@(CodeBlock (id', classes, attrs) _) = do
117117
extraAttrs = Map.toList extraAttrs'
118118
blockAttrs = (id', filter (/= cls toolkit) classes, filteredAttrs)
119119

120+
debug $ "Propagating attributes unrelated to pandoc-plot: " <> tshow blockAttrs
121+
120122
let blockDependencies = parseFileDependencies $ fromMaybe mempty $ Map.lookup (tshow DependenciesK) attrs'
121123
dependencies = defaultDependencies conf <> blockDependencies
122124

0 commit comments

Comments
 (0)