2020-06-09 02:18:48 +02:00
title: SVG + makefile = slide deck
2020-06-08 00:23:21 +02:00
summary: "You don't need LibreOffice to prepare your presentation -- or: an introduction to makefiles"
published: 2020-06-02
---
2020-06-09 11:34:51 +02:00
Text-based slides are boring and not effective.
While preparing a presentation for my intermediary thesis' defence, I wanted to create something that would support my story better.
I wanted to use graphics instead of words so the language centres of my dear audience's brains could focus on my speech rather than reading.
Rather than importing slide-sized graphics in a GUI, I thought a makefile would be a nice way to do the trick.
Makefiles these days are commonly used as a shell script with multiple entry points.
2020-06-09 13:46:31 +02:00
But they can do much more than that!
2020-06-09 11:34:51 +02:00
You give it a filename, and it will build that file if its dependencies have been changed.
Traditionally makefiles are used for C programs, but there's no reason you can't use them for any build you want.
Even this website is built by a makefile!
Want to join me and write one together?
2020-06-08 00:23:21 +02:00
## Writing the makefile
Putting the name of our output file in variables will make it easier to change it later.
```makefile
OUTPUT = slides.pdf
```
2020-06-09 11:34:51 +02:00
We'll make a list of SVGs in the current directory, and convert it into a list of PDF targets.
2020-06-09 13:46:31 +02:00
Sorting is necessary to put your slides in the order you want.
2020-06-09 11:34:51 +02:00
The `$(:=)` construct is used to go from `%.svg` to `build/%.pdf` .
2020-06-08 00:23:21 +02:00
```makefile
SLIDES ::= $(sort $(wildcard *.svg))
SLIDES_PDF ::= $(SLIDES:%.svg=build/%.pdf)
```
2020-06-09 11:34:51 +02:00
I love this next rule.
2020-06-09 13:46:31 +02:00
It teaches *make* that it should use Inkscape if it needs to create a PDF.
2020-06-08 00:23:21 +02:00
`$@` refers to the target (`build/….pdf`), and `$<` refers to the first dependency (`….svg`).
2020-06-09 13:46:31 +02:00
Inkscape's `--export-pdf filename` option exports to PDF without opening the GUI.
2020-06-09 11:34:51 +02:00
2020-06-08 00:23:21 +02:00
**TODO: isn't there a way to automatically depend on all parent directories?**
```makefile
build/%.pdf: %.svg build
2020-06-09 13:46:31 +02:00
inkscape --export-pdf "$@" "$< "
2020-06-08 00:23:21 +02:00
```
2020-06-09 13:46:31 +02:00
Now we tell *make* that the final output can be created from the individual slides (`$(SLIDES_PDF)`) by calling pdfjoin.
2020-06-08 00:23:21 +02:00
2020-06-09 13:46:31 +02:00
*Make* will recursively make sure that all dependencies are up to date.
2020-06-09 11:34:51 +02:00
Because we add the SVG source file as a dependency, it will know that the individual PDF files have to be rebuilt if their source was changed.
And if any slide was changed, the end result will be updated too.
But if there was no change, it won't; nothing is rebuilt unnecessarily!
2020-06-08 00:23:21 +02:00
**TODO: DRY**
**TODO: Do we need to fix sh's space disease here?**
```makefile
$(OUTPUT): $(SLIDES_PDF)
pdfjoin $(SLIDES_PDF) -o "$@"
```
2020-06-09 11:34:51 +02:00
If you look at the `build/%.pdf` rule, you see that it depends on `build` .
2020-06-09 13:46:31 +02:00
With this rule, *make* will know how to create this directory.
2020-06-08 00:23:21 +02:00
```makefile
build:
mkdir -p "$@"
```
2020-06-09 11:34:51 +02:00
It is common to create a `clean` to clean up.
Since `clean` is not a file, we have to mark the target as "phony".
Failing to do so would result in **TODO how to finish this sentence?**
2020-06-08 00:23:21 +02:00
```makefile
.PHONY: clean
clean:
rm -rf "$(OUTPUT)" build/
```
2020-06-09 13:46:31 +02:00
One more thing: the default target, for when you call *make* without arguments, is the first one in the makefile (with [some caveats][gmake_docs_targets]).
You could override this with `.DEFAULT_GOAL := your_target_name_here` , but it's just as easy to reorder the rules, which is what I've done in the summary below.
[gmake_docs_targets]: https://www.gnu.org/software/make/manual/html_node/Goals.html "Goals – GNU make documentation"
This is the finished makefile:
```makefile
OUTPUT = slides.pdf
SLIDES ::= $(sort $(wildcard *.svg))
SLIDES_PDF ::= $(SLIDES:%.svg=build/%.pdf)
$(OUTPUT): $(SLIDES_PDF)
pdfjoin $(SLIDES_PDF) -o "$@"
build/%.pdf: %.svg build
inkscape --export-pdf "$@" "$< "
build:
mkdir -p "$@"
.PHONY: clean
clean:
rm -rf "$(OUTPUT)" build/
```
2020-06-08 00:23:21 +02:00
2020-06-09 11:34:51 +02:00
**TODO: write about first rule being the default**
2020-06-08 00:23:21 +02:00
**TODO: split into 2 posts?**
2020-06-09 13:46:31 +02:00
## Further help with *make*
I'm using *GNU make* and I'll admit I don't know if this works in other flavours.
GNU's documentation is installed on my system and accessible with `info make` (< kbd > tab</ kbd > to jump to next link, < kbd > enter</ kbd > to activate it, < kbd > l</ kbd > to return to previous screen, < kbd > Shift+h</ kbd > for help).
When online you can also use the [online documentation][gmake_docs].
[gmake_docs]: https://www.gnu.org/software/make/manual/html_node/index.html "GNU make documentation"
2020-06-09 11:34:51 +02:00
2020-06-08 00:23:21 +02:00
## Creating and presenting slides
2020-06-09 11:34:51 +02:00
Create one SVG per slide, you can do that in Inkscape.
Set the document size to something with the desired aspect ratio.
In my experience this is 16:9 for newer projectors and 4:3 for older models.
2020-06-08 00:23:21 +02:00
2020-06-09 11:34:51 +02:00
To use the resulting slide deck during your presentation, I can recommend [pdfpc ](https://pdfpc.github.io/ ).
But any old PDF viewer that has a fullscreen mode will work, of course.