DEV Community

Cover image for Level up your presentations with Go
charly3pins
charly3pins

Posted on • Originally published at charly3pins.dev on

Level up your presentations with Go

If you're a technical person and you don't like to battle with presentation softwares but you want/need to create one, congratulations! you are in the right place. I know that as software engineers we want to be coding or reading or watching things related with software, architecture or devops but not with presentations. Sometimes we are demanded to present something to other team members, to the product owners or even scarier, to the management team!

For that reason I want to introduce you to the Go package present. It's used to create slides in Golang hosted on talks.golang.org or on your private one. I've used it several times, especially when I want to share something to my colleagues on the team (some code of course), because I don't want to waste time with softwares. I just create the project for the slides, add my slides in markdown, add the images needed and just present them to them. Let's see in detail how it works!

Assuming you have Go installed and correctly configured, all you need to install is the package with the following command:

go get -u golang.org/x/tools/present
Enter fullscreen mode Exit fullscreen mode

Test if it works typing:

present
Enter fullscreen mode Exit fullscreen mode

And it should display a message similar to:

2020/10/04 23:23:54 Open your web browser and visit http://127.0.0.1:3999
Enter fullscreen mode Exit fullscreen mode

So you can visit the link, and see the local server ready to host your presentations. Awesome or not? Okay, I know you want to display something other than an empty directory, so let's create an example presentation for that.

Format

Create a directory for your slides:

mkdir go-present-example
cd go-present-example/
Enter fullscreen mode Exit fullscreen mode

Create your first slide:

vim initial.slide
Enter fullscreen mode Exit fullscreen mode

And add the following:

Learning Go present
6 October 2020

Crash Bandicoot
crash.bandicoot@gmail.com

* Hello World

I'm a slide
Enter fullscreen mode Exit fullscreen mode

So if you run again the present command inside your folder and go to the browser again you should be able to see the screen below:
initial slide

Click on the initial.slide link and admire your presentation!
initial presentation

As you can see, the first line is the title, the second the date and then it's followed by the author. On the second slide, actually the first one, it appears the title of the slide and the text of that one. The last one displays a gratitude title and your name and contact (email, twitter, etc.) you added in the slide. See it below:
end presentation

Legacy Present Syntax

It supports Markdown but here we will explore the Legacy Present Syntax, as the Markdown has a lot of resources where you can check. So let's explore a bit the features that present offers for formatting and displaying text in our slides.

First is the classical options for formatting the text:

normal vs `highlighted`
*bold*
_italic_
*multiple*bold*text*
_multiple_italic_text_
Enter fullscreen mode Exit fullscreen mode

And the result:
text formatting

Also you can add a list:

Grocery list for the gopher:

- go routines
- garbage collector
- Rust
Enter fullscreen mode Exit fullscreen mode

text formatting list

Or different level of subsections like that:

** Subsection

Gopher is diving the subsection.

*** Sub-subsection

Another Gopher is diving more into the sub-subsection!
Enter fullscreen mode Exit fullscreen mode

And you will see the slide like this craziness:
text formatting subsections

gophers

Command Invocations

Apart from text formatting there are a special command invocations that you can invoke to take your presentation to another level.

images & videos

The .image command injects a picture in your slide. It accepts 1 or 3 arguments (name, height, width). Name is mandatory, other two must be present or substituted with an _.

.image /images/gopher.jpeg 200 200
.image /images/gopher.jpeg _ 300
Enter fullscreen mode Exit fullscreen mode

images

Like the pictures, you can do the same with a video using the .video command. It accepts 2 or 4 arguments (name, file content-type, height, width). Name and file content-type are mandatories, other two must be present or substituted with and _.

.video videos/gopher-dance.mp4 video/mp4 400 600
.video videos/gopher-dance.mkv video/mkv 500 _
Enter fullscreen mode Exit fullscreen mode

Similar to the images, it also has the .background command to set the background image for a slide. It has only one argument as the file name of the image.

.background images/susan.jpg
Enter fullscreen mode Exit fullscreen mode

links

If you need to insert a link in your presentation you can use the .link command. It accepts 1 or 2 arguments (HTTP url, text label). HTTP url is mandatory, the second one is optional.

.link https://charly3pins.dev charly3pins website
.link https://charly3pins.dev
Enter fullscreen mode Exit fullscreen mode

links

code

The best command imo is the .code one. It allows you to put code extracting them from the source files and injecting them as HTML-escaped pre blocks. It accepts one argument as the file name followed by an optional address that specifies what section of the file to display.

For example taking the Hello world in Go as a source code:

package main

import "fmt"

func main() {
    fmt.Println("Hello world!")
}
Enter fullscreen mode Exit fullscreen mode

We need to specify as:

.code hello.go
Enter fullscreen mode Exit fullscreen mode

And it will show like that:
code

But what happens if you want to highlight some part of the code? Don't worry, present has that "present" and you can add those "optional addresses" we commented below for that. So, modify the code like that to highlight the Printf call:

package main

import "fmt"

func main() {
    fmt.Println("Hello world!") // HL
}
Enter fullscreen mode Exit fullscreen mode

And use the same command in your slide:

.code hello-hl.go
Enter fullscreen mode Exit fullscreen mode

To see the code highlighted:
code-hl

One step further! If you wanna show only a part of your code, for example hide the package and the imports of your file, you can also add the following snippets:

package main

import "fmt"

//START OMIT
func main() {
    fmt.Println("Hello world!") // HL
}
//END OMIT
Enter fullscreen mode Exit fullscreen mode

Again use the same command but adding the following snippet:

.code hello-hl-partial.go /START OMIT/,/END OMIT/
Enter fullscreen mode Exit fullscreen mode

And see the code partially displayed:
code-hl-partial

play

That command is superpowerful in order to help you present some code and highlight or hide some parts. But the show must go on, and the best part is the next one. The command .play is like the code one but it puts a button on the dispalyed source and you can run your program from the browser! Is it magic or not?
magic

So let's use the same source-code that we are using and just add the new command to the slides like this:

.play hello.go
Enter fullscreen mode Exit fullscreen mode

It will appear like the code one but if you notice on the right bottom corner, it appears a small Run button.
code-play

Running the code will display a small black window on the screen displaying the output of the code:
code-played

Presenter Notes

Last but not least is an interesting thing that they provide also. It's well known that in PowerPoint or similar programs you can add your notes only visible for you when presenting the presentation and they are very useful sometimes. So present has that in consideration as well and you can add your presentation notes just adding a : on the beginning of the sentence and that text will be treated as a presenter note.

For example:

* Presenter notes

The gophers like to eat a lot.

: they eat more than half their body weight in food each day

They eat basically plants.

: typically gnaws the roots of a plant just beneath the soil, so the damage isn’t seen
Enter fullscreen mode Exit fullscreen mode

present-notes

As you can see the notes aren't present there, so WHY? Because you need to run the presentation in a "presenter" like that.

present -notes
Enter fullscreen mode Exit fullscreen mode

And it should display a message similar to:

2020/10/04 23:23:54 Open your web browser and visit http://127.0.0.1:3999
2020/10/04 Notes are enabled, press 'N' from the browser to display them.
Enter fullscreen mode Exit fullscreen mode

So if you refresh your browser with the presentation and press N you will see a popup displaying the notes of each slide on the bottom like that:
present-notes-popup

Conclusion

The present tool is super useful for technical presentations, especially in Go. It has its limitations like the format of the slides and the image positioning sometimes tricky, but in general is a great package and for me is the standard for all my presentations. If you wanna dick more in detail about that package check the official documentation and also I would recommend the presentation: Inside the "present" tool by Andrew Gerrand. Also I've uploaded the source code for this tutorial on GitHub.

I hope it helps you and feel free to comment here or contact me on my social media for any comments, questions or suggestions.

Top comments (0)