Skip to content

Add filter to center all images, even non-figure images #153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading