Building Slide Presentations with present
Presentation as Code
The Golang package present may be the key to making attractive slide presentations with less work and hassle.
Creating slide presentations has been a necessary part of technical life for a long time, but creating crisp and beautiful slides using the popular traditional tools requires a lot of tedious work. I have always been intrigued by the elegant presentations in Golang community talks, but there was no clear-cut information available on how those beautiful presentations were rendered. In researching, I stumbled upon a Golang package named, not surprisingly, present
[1], which renders amazing presentation slides from markup text description. For many years now, present
has been my go-to tool for creating and delivering impressive presentations.
Getting Started
There is no separate installation step needed to start using the present
utility. It's just a statically linked binary that is grab-and-run; there's no need to set up any other runtime dependencies. You do need the Golang compilation toolchain already set up on your machine if you want to run the present
command natively. Alternatively, you can run present
out of the box, provided Docker Engine is installed on your machine (which is very common nowadays). I personally took the Docker route to use present
without doing any extra work. You can use the Dockerfile (Listing 1) and script (Listing 2) to fetch and run present
to display your slides on your local machine.
Listing 1
Dockerfile
Listing 2
run.sh
To create a Docker image from which you can launch present
, use the following command:
docker build . -t present
You can also launch the present
container to serve your slides from a bind-mounted directory (e.g., files in your current directory), by executing the command:
docker run -d --rm -v ${PWD}/files:/src/files:ro -p 58888:8888 present
Now open your web browser and access localhost:58888 to ensure everything is running to deliver your presentation. Figure 1 shows the present
container accessed by its localhost endpoint in my browser. Don't be confused about it not showing a presentation – I'll create the presentation next.
Slides Basics
Now it's time to dirty your hands with present
's slides description language. The preferred way to craft your slides is using the CommonMark markup language [2]. (You can also use legacy syntax [1] to describe your slides, but that's not discussed here.) To start, create a file named mytest.slide
(Listing 3) in the bind-mounted ./files
directory.
Listing 3
mytest.slide
Now refresh your present
endpoint browser page, and the newly created slide file link should appear (Figure 2).
If you click mytest.slide now, you'll see an elegant three-slide presentation (the first and last slides are shown in Figures 3 and 4). Congratulations, you have created a presentation – without the frustration of dragging and dropping and the impossible formatting in a slide creation tool. You can move between the slides using the left and right arrow keys and also create a PDF using the Ctrl+P print dialog.
The slide description starts with a header block with the presentation topic prefixed with #
and a space. Optionally, you could put other metadata such as a subtitle, date, tags, summary, and old URL lines after the #
. An optional author block follows the header section, with at least a space in between them. The author block can contain your name, title, email, URL, twitter handle, etc. present
automatically renders the last slide with the author block (Figure 4). It only puts author info that is not an email, URL, or twitter handle on the first slide (Figure 3). You could have multiple author blocks, each separated with at least a space between them. Any line starting with //
is treated as a comment.
The presentation slide sections follow the author blocks. A slide section starts with ##
followed by at least one space. Each slide could have a subsection too, starting with ###
and followed by at least one space. The content of a slide is governed by CommonMark to format text.
To add more content to the slides, update your mytest.slide file with the code in Listing 4 and refresh the browser page rendering the presentation.
Listing 4
mytest.slide Basic Content
Now you should see common markup features (bold/italic text, lists, block quotes, links, images, horizontal rules, in-line code, etc.) implemented on your slide (Figure 5). To learn more about these markup features, see the CommonMark documentation [2].
Lines starting with a colon are treated as presenter notes. Pressing N in the browser showing your presentation opens a separate pop-up window displaying the notes (Figure 6).
More Enriched Slides
If you want more than text, hyperlinks, and logos in your slides, you can use present
description language features to render eye-candy slides. To do this, present
provides a number of special commands using invocations. Any line starting with a dot character is an invocation. These commands include adding images, setting background, showing/editing/running code, creating a hyperlink, injecting video, including figure captions, and more. As an example, use the code in Listing 5 to once again update your mytest.slide file content, put the necessary images and sources into your presentation directory, and refresh the browser page rendering the presentation. Figure 7 shows a slide rendered using various invocations.
Listing 5
mytest.slide Images and Sources Content
The .image
invocation optionally takes height and width arguments. If any of these arguments are specified as an underscore, then scaling preserves the aspect ratio of the image. The .background
invocation doesn't take any argument except the image. If your image is not big enough, then the background command will fill your slide with a repeated pattern of the mentioned image.
Both .code
and .play
invocations can strip the unnecessary code from the respective source and only display the necessary portion of the code. The -edit
command enables you make modifications in the displayed code during your presentation. The play
command displays code with a Run button to run the Go program from the browser.
Now you have enough knowledge to render rich presentations using the present
description language. You can explore the full details of the present
description language in the package documentation [1]. For more example slides and scripts, check out my GitHub repository [3].
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you've found an article to be beneficial.
News
-
The GNU Project Celebrates Its 40th Birthday
September 27 marks the 40th anniversary of the GNU Project, and it was celebrated with a hacker meeting in Biel/Bienne, Switzerland.
-
Linux Kernel Reducing Long-Term Support
LTS support for the Linux kernel is about to undergo some serious changes that will have a considerable impact on the future.
-
Fedora 39 Beta Now Available for Testing
For fans and users of Fedora Linux, the first beta of release 39 is now available, which is a minor upgrade but does include GNOME 45.
-
Fedora Linux 40 to Drop X11 for KDE Plasma
When Fedora 40 arrives in 2024, there will be a few big changes coming, especially for the KDE Plasma option.
-
Real-Time Ubuntu Available in AWS Marketplace
Anyone looking for a Linux distribution for real-time processing could do a whole lot worse than Real-Time Ubuntu.
-
KSMBD Finally Reaches a Stable State
For those who've been looking forward to the first release of KSMBD, after two years it's no longer considered experimental.
-
Nitrux 3.0.0 Has Been Released
The latest version of Nitrux brings plenty of innovation and fresh apps to the table.
-
Linux From Scratch 12.0 Now Available
If you're looking to roll your own Linux distribution, the latest version of Linux From Scratch is now available with plenty of updates.
-
Linux Kernel 6.5 Has Been Released
The newest Linux kernel, version 6.5, now includes initial support for two very exciting features.
-
UbuntuDDE 23.04 Now Available
A new version of the UbuntuDDE remix has finally arrived with all the updates from the Deepin desktop and everything that comes with the Ubuntu 23.04 base.