What is present?
Present is used to create slides in Golang. These slides can be hosted on talks.golang.org or on your private App Engine project
Why do we need present?
While taking a training session, I realized that using Google slides in conjunction with Golang playground can be a nightmare. When you have to demonstrate many examples to the audience, you are switching tabs and this takes the focus off the presentation. That is when I started digging to explore options to embed Golang playground into Google slide. Of course, I got no success there, but I came across present tool and it was the perfect fit.
I started using present for my sessions. Though it has limited training material available it is easy to understand and put in place. It is also easy to host your presentations; all you need is a Github account.
How to use present?
- We will create a simple presentation while exploring features of present tool. Also, let’s try hosting it using talks.golang.org.
- This tutorial is designed assuming you are using Linux and have go installed on your system.
- Download and install present package
$ go get -u golang.org/x/tools/present
- Run present
- Open http://127.0.0.1:3999 in chrome. You should see a screen of Go talks. Currently, it has no slides.
- Make a directory for your slides
$ mkdir go-slides-example$ cd go-slides-example
- Create a slide file
$ vim sample.slide
- Add the following lines to your sample.slide
- Refresh your chrome. You should be able to see screen given below
- Click on sample.slide to see your presentation
As you can see the first line of slide file corresponds to the Title of your presentation. The second line is the date of presentation; followed by a blank line. On the next line comes the name of the presenter. In the next line, you may add your email id/ twitter id. Let’s explore the following features:
- Formatting: To create a slide you have to specify it as * <Slide title>. Add the following code to your sample.slide to create slide for Formatting.
When you refresh your browser. Your new slide will look something like this.
- Asterisk(*), underscore(_) and backtick(`) are marker characters
- As you can see in the output the words enclosed inside pair of * appear bold. Underscore(_) makes your word appear italic. Back tick(`) apply program font to the word.
- Please note the an opening marker should be preceded by a white space unless it is the beginning of the line. Also, a white space should succeed the close marker unless it is the end of the line.
- To format more than one word we will have to use markers on each word. You cannot enclose multiple words in markers.
2. Images/ Videos: Add Images to your slides
A new slide is added to your presentation.
You can also change the dimension of the image. Use two arguments as shown below:
.image images/betsy.jpg 100 200
If you choose to specify dimension both height and width must be given. If you want to skip any one of the two replace it with an underscore(_).
Like images, you can also add video files to your presentation. Replace .image with .video and give the path of your video file.
3. Code: Now, let’s do some coding. Create hello.go file in your directory. Add the following code to hello.go and sample.slide:
On refresh, you will see a new slide that displays your code in a grey box.
- .code hello.go displays the whole file
- .code hello.go /^//START/,/^//END/ HL12 display only the main func. This is very useful when you only need to show only partial code to your audience. You can avoid unnecessary behind the scenes lengthy codes. You can specify the start and end of your partial code using regex. In this case, I have added two comments //START OMIT and //END OMIT. The regex will match these comments and return the code between these lines. However, we don’t want to display these comments to our audience so we end the comment with OMIT word. When a line ends with word OMIT it is not rendered in your slide.
NOTE: Whenever adding OMIT in your comment be sure you add a white space before it.
- Additionally, you will see some other comments in the hello.go file. // HL is used to highlight a specific line in the code. Be sure you add // HL and not //HL as the latter will not highlight the line instead will be printed in your slide.
- You can also use your own highlighter in // HLxxx format. I am using HL12 in this case. To enable a highlighter specify it after your code invocation in sample.slide. The code lines in the go file that ends with // HL12 will be highlighted, as shown in the second example in the slide.
Note that when you use custom highlighter the default ones i.e. HL becomes void. Hence fmt.Println(“Hello World”) is not highlighted.
4. Run Code: Now let’s move the major feature of present. Let’s run hello.go from the presentation itself. Add the following code to your sample.slide file.
You should see a box similar to the code feature. However, note that there is a small “Run” button on the right bottom corner.
Now, let’s run our code. A small black window will appear on your in your screen displaying the output of your code.
You can add a hyphen — at the start of your line to make it a list item. Be sure you add white space after hyphen for it to be recognized as a bullet.
- Now that our presentation is ready. Let’s host it and get sharing.
- Create a public GitHub repository.
Note: Make sure your repository is public. As we cannot host a presentation using a private repository.
- Fire the following set of commands to push your code on Github
$ git init$ vim README.md
Add the following code to your README.md file
Go based presentations — — — — — — — — — — — * [Golang Basics](https://talks.godoc.org/github.com/<Github username>/<Repository Name>/sample.slide)$ git add .$ git commit -m ‘First commit’$ git push origin master
- Now access your presentation on any of the following links:
https://talks.godoc.org/github.com/<Github username>/<Repository name>/sample.slide#1
https://go-talks.appspot.com/github.com/<Github username>/<Repository name>/sample.slide#1
- Following are links to my hosted presentation. Yours should look similar:
Present is a good tool for technical presentations. Though it has its limitations of its own like it has a strict format of the slide that you cannot change. Nonetheless, it is still a great package that will make it easy for you to embed code into your presentation. I hope it was a useful tutorial. You can also refer to the official documentation of this package. The source code for this tutorial is available on Github. Feel free to drop your questions if any.