Skip to content

Commit 5d5da71

Browse files
authored
Add filter to center all images, even non-figure images (#153)
1 parent a9971bc commit 5d5da71

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@ if [ -n "${pdf_output}" -o -n "${latex_output}" ]; then
497497
--filter=mermaid-filter
498498
--lua-filter=informative-sections.lua
499499
--lua-filter=convert-images.lua
500+
--lua-filter=center-images.lua
500501
--lua-filter=parse-html.lua
501502
--lua-filter=apply-classes-to-tables.lua
502503
--lua-filter=landscape-pages.lua

filter/center-images.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function Image (img)
2+
-- Center images even if they aren't captioned.
3+
if FORMAT:match 'latex' then
4+
return {
5+
pandoc.RawInline('latex', '\\begin{center}'),
6+
img,
7+
pandoc.RawInline('latex', '\\end{center}'),
8+
}
9+
end
10+
return img
11+
end

guide.tcg

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -553,13 +553,24 @@ becomes:
553553

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

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

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

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

564+
Without the title and `#fig` attribute,
565+
566+
```md
567+
![](add_plus_button.jpg)
568+
```
569+
570+
looks like:
571+
572+
![](add_plus_button.jpg)
573+
563574
![An SVG Image](stack.svg){#fig:sample-svg width=50%}
564575

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

0 commit comments

Comments
 (0)