From 5d5da71cef43f263f97cf22584e1ecc21df76288 Mon Sep 17 00:00:00 2001 From: Chris Fenner Date: Sun, 21 Jul 2024 14:07:17 -0700 Subject: [PATCH] Add filter to center all images, even non-figure images (#153) --- build.sh | 1 + filter/center-images.lua | 11 +++++++++++ guide.tcg | 17 ++++++++++++++--- 3 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 filter/center-images.lua diff --git a/build.sh b/build.sh index ebf6063..412cfb7 100755 --- a/build.sh +++ b/build.sh @@ -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 diff --git a/filter/center-images.lua b/filter/center-images.lua new file mode 100644 index 0000000..9b4b410 --- /dev/null +++ b/filter/center-images.lua @@ -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 diff --git a/guide.tcg b/guide.tcg index 14ba3f9..aaa986b 100644 --- a/guide.tcg +++ b/guide.tcg @@ -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.