Skip to content

Commit

Permalink
Add filter to center all images, even non-figure images (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisfenner authored Jul 21, 2024
1 parent a9971bc commit 5d5da71
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ if [ -n "${pdf_output}" -o -n "${latex_output}" ]; then
--filter=mermaid-filter
--lua-filter=informative-sections.lua
--lua-filter=convert-images.lua
--lua-filter=center-images.lua
--lua-filter=parse-html.lua
--lua-filter=apply-classes-to-tables.lua
--lua-filter=landscape-pages.lua
Expand Down
11 changes: 11 additions & 0 deletions filter/center-images.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function Image (img)
-- Center images even if they aren't captioned.
if FORMAT:match 'latex' then
return {
pandoc.RawInline('latex', '\\begin{center}'),
img,
pandoc.RawInline('latex', '\\end{center}'),
}
end
return img
end
17 changes: 14 additions & 3 deletions guide.tcg
Original file line number Diff line number Diff line change
Expand Up @@ -553,13 +553,24 @@ becomes:

![Adding an Image](add_plus_button.jpg){#fig:add-plus-button width=60%}

The `{#fig:add-plus-button}` attribute (note there are no spaces between the `)` and the `{`!) does two things:
Including a figure title (`Adding an Image` between the `[]` above) causes the image to numbered, included in
the list of figures, and given a caption.

1. Includes the figure in the List of Figures (if you used `\listoffigures` as described in @sec:toc).
2. Numbers the figure so you can reference it as @fig:add-plus-button by just typing `@fig:add-plus-button`.
The `{#fig:add-plus-button}` attribute (note there are no spaces between the `)` and the `{`!) allows you to
reference it as @fig:add-plus-button by just typing `@fig:add-plus-button`.

Including `width=60%` here specifies that the image should take up 60% of the page's width.

Without the title and `#fig` attribute,

```md
![](add_plus_button.jpg)
```

looks like:

![](add_plus_button.jpg)

![An SVG Image](stack.svg){#fig:sample-svg width=50%}

Even formats that are not natively supported by Pandoc are now supported, like the SVG in @fig:sample-svg.
Expand Down

0 comments on commit 5d5da71

Please sign in to comment.