My Course Slide Generation

[This article was first published on Educate-R - R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

This past August I took an opportunity to step back into the University academic world as a Visiting Assistant Professor at the University of Arkansas. I have enjoyed the transition back into the academic world, including a more flexible schedule, variation in topics/duties, and collaborating with colleagues.

However, there has been some growing pains, especially regarding creating my own slides for the courses I teach. Although I am using the same books/curriculum used in previous semesters, I am making my own slides and adding my own pieces as I see fit. In addition, I do not use powerpoint, which all of the existing slides are in. Therefore, I am creating my own versions of the slides using a combination of R, knitr, markdown, pandoc, slidy, and LaTeX. Below is my general process of making my slides and the slides I put online for students to have access to.

Step 1 – Create Source File

I start with a Rmd file. This allows me to embed R code into the source document. This is particularly useful for me to include plots of distributions, graphically showing how ANOVA works, etc. Once I am finished editing my Rmd, if I am using Rstudio I just use the Knit HTML button to automatically generate the markdown and HTML file for me. Alternatively, the knit command from the knitr package will create the markdown file for you (but not the HTML file, although for me the HTML file is not needed in this step). The defaults of the knit command work fine for me.

knit(input = "/path/to/file.Rmd", output = "/path/to/file.md")

Step 2 – Create HTML Presentation

Once we have the markdown file, I now use pandoc to create my HTML presentation. There are a few ways to create HTML presentation slides, but I personally like slidy the best. I like slidy because it easily fills the whole screen and also allows for content to go over the edges of the slide. If content goes outside of the edges of a single slide, you can scroll to see the missing content. I find this useful if I want to blow up an image or have two plots where I can show one then scroll to the second. The pandoc command I use looks something like this:

pandoc -s --mathjax -i -t slidy inputfile.md -o outfile.html

Step 3 (Optional) – Edit CSS for HTML Presentation

I use a custom CSS file to style my HTML presentation so it uses some of the official colors from the University of Arkansas. For example, my header titles use the Arkansas red. To use a custom CSS file, you just need to find the line that mentions CSS in the HTML file and change it to reflect your custom file. The defaults look good, although perhaps slightly bland.

Step 4 – Create pdf slides

I then create a different set of slides using LaTeX that I post on the blackboard site for each of my courses. Pandoc is how I get the tex file to compile with LaTeX. The command is very simple:

pandoc -s inputfile.md -o outfile.tex

Two things I change, I make sure the base text size is 12 pt. I also make sure to use the float package and change any figure positions from htbp to H which forces the figures to stay in position and not float around. Then I compile the resulting tex using Rstudio or from the command line with:

pdflatex -interaction=nonstopmode -synctex=1 outfile.tex

In my opinion this creates great looking html presentations that are highly customizable. One thing to note is that by default to get the slideshow, you need to be connected to the internet. Both slidy and mathjax refer to javascript files that are on downloaded directly from the web. You should be able to download these files, store them locally, and refer to the local versions.

To leave a comment for the author, please follow the link and comment on their blog: Educate-R - R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)