background image in LaTeX Beamer presentation

This post shows how one can change the background image in a Beamer presentation:

 <pre class="example">%% all slides

\usebackgroundtemplate{ \includegraphics[width=\paperwidth, height=\paperheight]{my_bg_image} }

%% single slide { \usebackgroundtemplate{\includegraphics[width=\paperwidth]{my_bg_image}} \begin{frame} \frametitle{Frame with nice background} \begin{itemize} \item 1 \item 2 \item 3 \end{itemize} \end{frame} }

The above method spans the image to cover the entire page size. To include a smaller image and center it, do this:

 <pre class="example">\usebackgroundtemplate{%

\vbox to \paperheight{\vfil\hbox to \paperwidth{\hfil\includegraphics[width=1.5in]{name.jpeg}\hfil}\vfil} }

(I asked this question on the Tex.SX since \hspace{4.5cm} works but \vspace{4.5cm} did not.)

Modify spacings in listing (itemize/enumerate) environments for LaTeX Beamer

I don’t usually worry about display options in LaTeX since it does a good job most of the time. However, when I write presentations using LaTeX Beamer, I make use of the itemize and enumerate environments quite often to list ideas, and the default setting in most of the templates lack generous spacing between items and between nested lists. The enumitem is the preferred method to modify spacing properties in list environments for LaTeX documents. However, Beamer has its own definitions for these environments for use with overlays, etc.

I posted questions regarding how to do so in Beamer here and here. Here is the complete solution. Place the following in the preamble of the document:

 <pre class="src src-sh">%% SPACING BETWEEN ITEMS FOR BEAMER

%% following lets me add length between items %% % \let\oldframe\frame % \renewcommand{\frame}{ % \oldframe % \let\olditemize\itemize % %%\renewcommand\itemize{\olditemize\addtolength{\itemsep}{0.5\baselineskip}} % \renewcommand\itemize{\olditemize\addtolength{\parskip}{0.5\baselineskip}} %% this affects nested list (itemize) as well % } \newlength{\wideitemsep} \setlength{\wideitemsep}{\itemsep} \addtolength{\wideitemsep}{0.5\baselineskip} \let\olditem\item \renewcommand{\item}{\setlength{\itemsep}{\wideitemsep}\olditem} %%\usepackage{enumitem} %% traditional way to modify listing (itemize and enumerate) properties…but beamer has its own definition %% NESTED LISTS %% \setbeamertemplate{itemize/enumerate subbody begin}{\vspace{0.5\baselineskip}} \setbeamertemplate{itemize/enumerate subbody end}{\vspace{0.5\baselineskip}} %% MORE OPTIONS

Similar modifications for Beamer are illustrated here.

Non-LaTeX presentations using org-mode – S5 and HTML5 slides

I recently had frustrations with presentations written using MS Powerpoint; I’m not even going to mention KeyNote as it is only available on a Mac. LibreOffice is my WYSIWYG editor on my Linux machine for writing quick and nicely formatted content. I also have MS Office installed on my machine using WINE. I sometimes use Google Docs for presentation when I have to collaborate. Most of the times, viewing MS-generated files on LibreOffice suffices. When it doesn’t work well, I opt for MS Office. However, I recently had to open a powerpoint presentation with an audio link. It didn’t play on LibreOffice and it didn’t play on my WINE MS Office. I started thinking about a possible route for presentation files that are self-contained and cross-platform. PDF comes to mind first, but to do so would mean I have to use Beamer to generate the slides or to use Adobe Acrobat to create the slides. I don’t want to do either as I’m referring to the scenario of creating quick slides.

HTML came to my mind next. I recalled S5. I remember this post which outlines how one could export to S5 using org-mode. I tried it out finally and things work nicely. This tutorial also mentions an alternative method to generate S5 presentations in org-mode based on the org-export-as-s5 function. Hopefully it will be integrated in the MASTER branch of org-mode soon. To embed audio or video, just paste the html code an html chunk, linking the file multimedia file in the current directory. Now the directory could be transferred to any computer and viewed.

I also stumbled on this link, which allows me to export org files to HTML5 slides. I think the latest file is here, with instructions on how to set up in the comments.

With the S5 and HTML5 slides exporting methods in org-mode, now I can make cross-platform presentations very easily using org-mode. I will probably use the HTML5 method as it doesn’t come with any dependencies like the ui directory from S5.

spacing between items in itemize or enumerate environments (lists)

In LaTeX Beamer, I wanted to adjust the spacing between items in an itemize environment. This post shows how to do it for each individual itemize environment:

 <pre class="src src-sh">\begin{itemize}\addtolength{\itemsep}{-0.5\baselineskip}

\item one \item two \end{itemize}

To do it globally, one can use the enumitem environment per this post; one can actually change lots of feature using enumitem. However, it does not work with LaTeX Beamer since Beamer defines itemize in its frame environment. To change itemsep globally, this post suggests the following in the document’s preamble:

 <pre class="src src-sh">documentclass{beamer}

\newlength{\wideitemsep} \setlength{\wideitemsep}{\itemsep} \addtolength{\wideitemsep}{100pt} \let\olditem\item \renewcommand{\item}{\setlength{\itemsep}{\wideitemsep}\olditem}

Poster presentation

I have to do a poster presentation, and I prefer to do it in LaTeX (as opposed to MS Powerpoint, Adobe InDesign/Pagemaker or Scribus) because I don’t want to worry about formatting and I have existing code from LaTeX Beamer presentations and other tex files. beamerposter is probably the easiest after googling. To get started, I downloaded the file, the latest beamerposter.sty, and beamerthemeI6dv.sty, and started hacking away. The institution logo is declared in beamerthemeI6dv.sty, so modify it.

Presentations/slideshows in a web browser using S5

I use LaTeX Beamer whenever I write a a presentation because

  1. I’m familiar with LaTeX and want to keep up with the skillset,
  2. I prefer to write in plain text, especially in emacs, and
  3. I don’t have to spend time working on the how the presentation looks and just have to worry about content.

I recently re-discovered S5, a way to make presentations using html, viewable by any web browser. I think it is safe to assume that more computers have a web browser than a pdf viewer (especially more than MS Powerpoint, for sure). I don’t really know html, so I searched for org-mode or markdown support. Of course, these exist. For org-mode, check out org-s5. For markdown support, there is Instiki and pandoc. I hope to try these out soon. S5 seems to be a good alternative when my presentation doesn’t involve math equations or source code on display. You can also create Beamer slides easily using org-mode; see this and this.

Animation / Interactive plots in R for inclusion in html websites or latex documents (beamer)

Been wanting to do an interactive/animated plot like the one here for a while (go to the Taylor example). Sage looks like a good program to generate animated graphics, but R is my primary language of choice as a statistician. I don’t want to learn another language just for a single feature (although the other features look good as well). For mathy stuff that require the likes of Mathematica (cannot be done in R), I’ll go to Sage. But for now, I’ll stick with R.

Check out the animation package in R and check out the examples here. It’s quite easy to create animations in R. Just create a series of plot (in png or jpeg format) and make them interactive via the convert command from ImageMagick to pack them into a gif file. We can also use mencoder to turn a series of plot into an avi file or convert to turn them into an mpeg file for inclusion in LaTeX documents or slides.

Some code:

<pre class="src src-R"><span style="color: #7fffd4;">library</span>(animation)

setwd(“~/Documents/UCI/RWorkAndExamples/”) storagefolder <- ‘Animations-CI’ if( !(storagefolder %in% dir()) ) dir.create(storagefolder) outfolder <- file.path(getwd(), storagefolder) oopt <- ani.options(interval=.05, nmax=100, outdir=outfolder, ani.type=“jpeg”,, filename=‘CI-Animations.html’) ##store old options first ani.start() ani.stop()

##addprefix script:
#! /bin/bash
for file in $@
mv $file $addtofile.$file;
echo "Now run rename to change prefix."

##run in shell ##vinh's script addprefix *.jpeg rename prefix. 00 prefix.?.jpeg rename prefix. 0 prefix.??.jpeg rename prefix. 00 prefix.?.jpeg rename prefix. "" prefix.???.jpeg

Check out following this and this to convert image files into movies (for inclusion into pdf via multimedia or movie package):

<pre class="src src-sh">mencoder <span style="color: #ffa07a;">"mf://*.jpeg"</span> -mf <span style="color: #eedd82;">fps</span>=5 -o CI-animations.avi -ovc lavc -lavcopts <span style="color: #eedd82;">vcodec</span>=msmpeg4v2:<span style="color: #eedd82;">vbitrate</span>=800

Check out this to convert image files to gif animation for use on websites:

<pre class="src src-sh">convert -delay 50 -loop 50 ??0.jpeg CI-animations.gif

##check following
saveMovie(expr={for(i in 1:10) plot(rnorm(100))}, outdir=outfolder)

ani.options(nmax=100) saveMovie(expr=clt.ani(obs=300), outdir=outfolder) flip.coin()

###Taylor example ifelse1 <- function(test, yes, no) if(test) yes else no

sin.taylor <- function(x) x - x\^3/factorial(3) + x\^5/factorial(5) - x\^7/factorial(7) sin.taylor2 <- function(x, n=NULL){ if(is.null(n)) sin(x) else{ x +ifelse1(n>=3, - x\^3/factorial(3), 0) + ifelse1(n>=5, x\^5/factorial(5), 0) + ifelse1(n>=7, - x\^7/factorial(7), 0) + ifelse1(n>=9, x\^9/factorial(9), 0) + ifelse1(n>=11, - x\^11/factorial(11), 0) } } curve(sin, xlim=c(-2pi,2pi), ylim=c(-2,2)) x <- seq(-2pi, 2pi, .1) lines(x, f.taylor(x), col="blue", lwd=2) lines(x, f.taylor2(x, n=7), col="blue", lwd=2)

jpeg("sinTaylor%03d.jpeg") for(i in c(1,3,5,7,9,11)){ curve(sin, xlim=c(-2pi,2pi), ylim=c(-2,2), main=paste("Taylor Expansion of f(x)=sin(x)\nOrder = ",i)) lines(x, sin.taylor2(x, n=i), col="blue", lwd=2) legend(4,2, legend=c("f", expression(hat(f))), lwd=c(1,2), col=c("black", "blue"), bty="n") } ##shell: convert -delay 100 -loop 50 sinTaylor00?.jpeg sinTaylor.gif mencoder "mf://sinTaylor00?.jpeg" -mf fps=1 -o sinTaylor.avi -ovc lavc -lavcopts vcodec=msmpeg4v2:vbitrate=800

##consistency n <- 200 x <- runif(n, 0, 4) y <- .2*exp(x) + rnorm(n,2) jpeg("Regression%03d.jpeg") plot(x,y, col="red") fit <- lm(y~x) abline(fit, lwd=2, col="blue")

set.seed(123) jpeg("Consistency%03d.jpeg", quality=50) n.seq <- c(10,20,50,200,1000) nsim <- 4 for(i in 1:length(n.seq)){ n <- n.seq[i] for(j in 1:4){ x <- runif(n, 0, 4) y <- .2exp(x) + rnorm(n,2) plot(x,y, col="red", xlim=c(0,4), ylim=c(-1,15), main=paste("n =", n), cex.main=2) fit <- lm(y~x) abline(fit, lwd=4, col="blue") legend(0,15, legend=paste("Slope =", round(fit$coef[2],2)), bty="n",cex=2) } } ##shell convert -delay 100 -loop 50 Consistency0.jpeg Consistency-Ani.gif mencoder "mf://Consistency0*.jpeg" -mf fps=1 -o Consistency-Ani.avi -ovc lavc -lavcopts vcodec=msmpeg4v2:vbitrate=800