Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Rather than changing the theme by hand and compiling it for each available theme, is there an easier way to do so such that I can get a PDF presentation for each available theme automatically?

share|improve this question
4  
You might be interested in hartwork.org/beamer-theme-matrix –  doncherry Aug 20 '12 at 0:58
    
@doncherry,nice! How could I download all those examples? Is there a pdf version? –  Sigur Aug 20 '12 at 1:56
2  
@doncherry: I think, it’s better to link to LaTeX Beamer Theme Matrix. –  Speravir Aug 20 '12 at 21:59

4 Answers 4

up vote 8 down vote accepted

here is a shell script which creates a main document main.tex with two example pages of all themes of current TL2012. It can be modified for using it under Windows. Run the script in an empty directory. The complete document is at http://perce.de/temp/main.pdf and this is the first page:

enter image description here

#!/bin/sh
DIR=`kpsewhich beamerthemeBerlin.sty`
DIR=`dirname $DIR`
#THEME=`echo $DIR | sed -e 's/beamertheme//'`

CreateExaDocument() {
  cat <<End_Of_File > $THEMESHORT.tex
  \\documentclass{beamer}
  \\usetheme{$THEMESHORT}
  \\title{A Beamer test with Theme ``$THEMESHORT''}
  \\author{Me}
  \\date{today}
  \\institute{Zentraleinrichtung Datenverarbeitung}
  \\begin{document}
  \\maketitle
  \\begin{frame}{Frametitle}{Framesubtitle}
  foo bar baz
  \\end{frame} 
  \\end{document} 
End_Of_File
}

for FILE in `ls --hide=compatibility $DIR` ; do
  THEME=`basename $FILE .sty`
  THEMESHORT=`echo $THEME | sed -e 's/beamertheme//'`
  echo $THEMESHORT
  CreateExaDocument
  pdflatex $THEMESHORT
  pdflatex $THEMESHORT
  rm *.aux *.toc *.log *.out *.nav *.snm
done

# now we crate a new PDF doc with all examples
rm -f main.pdf
echo "\\documentclass[a4paper]{article}" > main.tex
echo "\\usepackage{graphicx,geometry}" >> main.tex
echo "\\geometry{margin=10mm}" >> main.tex
echo "\\parindent=0pt" >> main.tex
echo "\\begin{document}" >> main.tex
for FILE in `ls *.pdf` ; do
    echo "\\frame{\\includegraphics[width=0.49\\linewidth,page=1]{$FILE}}" >> main.tex
    echo "\\hfill\\frame{\\includegraphics[width=0.49\\linewidth,page=2]{$FILE}}" >> main.tex
    echo "\\par\\bigskip" >> main.tex
done    
echo "\\end{document}" >> main.tex
pdflatex main #--output-directory=/tmp main
pdflatex main #--output-directory=/tmp main
rm *.aux *.log 
share|improve this answer
    
Actually I use my own answer in my production. –  Who is crazy first Aug 21 '12 at 4:18

Here's a little perl script (my second in 2 days, I promise I'm not obsessed... much) that you can run as follows

perl createBeamer.plx slides.tex

or you can call it with any number of files

perl createBeamer.plx file1.tex file2.tex file3.tex

Note there are a few necessary lines in each of your .tex files, detailed below.

You just need to specify which themes you want to use in the array @themes, and then you'll get a whole lot of pdfs from running one script- magic :)

createBeamer.plx

#!/usr/bin/perl

use strict;
use warnings;

my @themes=("default","Rochester","CambridgeUS","Boadilla","Warsaw","AnnArbor");
my $tmptheme='';
my $filename='';

while (@ARGV)
{
    # get filename from arguments
    $filename = shift @ARGV; 

    # make sure file exists
    if(-e $filename)
    {
        # strip .tex extension
        $filename =~ s/\.tex//; 

        # loop through the themes
        foreach $tmptheme (@themes)
        {
            system("pdflatex","\\def\\mytheme{$tmptheme}\\input{$filename}");
            system("cp","$filename.pdf","$filename$tmptheme.pdf");
        }
    }
    else
    {
        print "File does NOT exist, please try again\n";
    }
}

slides.tex

\documentclass{beamer}

\ifdefined\mytheme
\usetheme{\mytheme}
\else
% default theme
  \usetheme{Warsaw}
\fi

\begin{document}

\begin{frame}
  \frametitle{Fingernails are pretty}
  hello world
\end{frame}

\end{document}

screenshot

EDIT

If you want a slightly more dynamic approach, then you can read the beamer themes in directly from their location

# location of themes
my $directory="/usr/local/texlive/2012/texmf-dist/tex/latex/beamer/themes/theme/";
opendir (DIR, $directory) or die $!;
while (my $file = readdir(DIR)) {
          # remove beamertheme from the name
          $file =~ s/beamertheme//;

          # remove .sty extension
          $file =~ s/\.sty//;

          # store it
          push(@themes,$file);
              }

and just comment out (or remove) the previous definition of @themes.

Of course, if you wanted to make it amazingly portable, you could perform a directory search each time.

share|improve this answer

The drawback of this approach: the theme list must be updated whenever a new theme exists on the globe.

  1. batch.bat accepts 2 arguments: %1 is for theme name and %2 for filename to include.

    rem batch.bat
    echo off
    
    del %1.pdf
    
    pdflatex -draftmode -interaction=batchmode --jobname=%1 "\newcommand\mytheme{%1}\input{%2}"
    pdflatex -interaction=batchmode --jobname=%1 "\newcommand\mytheme{%1}\input{%2}"
    
    for %%x in (aux log out toc nav snm) do (del %1.%%x)
    
  2. automator.tex must be compiled with pdflatex --shell-escape automator.

    % automator.tex
    \documentclass{article}
    \usepackage{filecontents}
    \begin{filecontents*}{dummy.tex}
    \documentclass{beamer}
    \usetheme{\mytheme}
    \title{Beamer Tutorial}
    \subtitle{in less than 10 minutes}
    \author{Garbage Collector}
    \date{\today}
    \begin{document}
        \maketitle
        \begin{frame}{Introduction}
    
        \end{frame}
    \end{document}
    \end{filecontents*}
    
    \usepackage{tikz}
    \begin{document}
    \foreach \x in {default,Rochester,CambridgeUS,Boadilla,Warsaw,AnnArbor}
        {\immediate\write18{batch \x\space dummy}}
    \end{document}
    
share|improve this answer
1  
Nice usage of LaTeX: as a cross-platform shell (because if you made a shell script batch in your linux, and change the call sequence to \write18{./batch \x\space dummy}, it would work under both windows and linux. –  tohecz Aug 20 '12 at 5:55
  1. Create a Beamer template using \mytheme macro:

    % template.tex
    \documentclass{beamer}
    \usetheme{\mytheme}
    \title{Beamer Tutorial}
    \subtitle{using \mytheme\ theme}
    \author{Garbage Collector}
    \date{\today}
    \begin{document}
        \maketitle
        \begin{frame}{Introduction}
            Stick together team and hold this position!
        \end{frame}
        \begin{frame}{Special Relativity}
            \[E\neq mc^2\]
        \end{frame}
        \begin{frame}{General Relativity}
            \[pV=nRT\]
        \end{frame}
    \end{document}
    
  2. Create a batch file to get all available beamer themes installed:

    rem makelist.bat
    
    echo off
    
    rem %1: output file name with extension
    
    dir /b C:\texlive\2012\texmf-dist\tex\latex\beamer\themes\theme\*.sty > %1
    
    dir /b C:\texlive\2012\texmf-dist\tex\latex\beamer\themes\theme\compatibility\*.sty >> %1
    
  3. Create a batch file to compile the Beamer template with each available theme:

    rem createslide.bat
    
    echo off
    
    rem %1: theme name
    rem %2: Beamer input file name with or without extension
    
    del %1.pdf
    
    pdflatex -draftmode -interaction=batchmode --jobname=%1 "\newcommand\mytheme{%1}\input{%2}"
    pdflatex -interaction=batchmode --jobname=%1 "\newcommand\mytheme{%1}\input{%2}"
    
    for %%x in (aux log out toc nav snm) do (del %1.%%x)
    
  4. Create another TeX input file to create Beamer Album or Catalog automatically:

    % automator.tex
    \documentclass{article}
    \usepackage{pdfpages}
    
    \makeatletter
    \def\trim beamertheme{}
    \def\theme{\expandafter\trim \filename@base}
    
    \def\MakeThemeList#1{\immediate\write18{makelist #1}}
    
    \newread\reader
    
    % #1: theme list filename, #2: beamer template filename
    \def\CreateAPresentationForEachTheme#1#2{%
    \openin\reader=#1\relax
    \loop
        \read\reader to \themestyle
        \unless\ifeof\reader
            \filename@parse{\themestyle}%
            \immediate\write18{createslide \theme\space #2}%
    \repeat
    \closein\reader}
    
    
    % #1: theme list filename
    \def\CreateAlbum#1{%
    \openin\reader=#1\relax
    \loop
        \read\reader to \themestyle
        \unless\ifeof\reader
            \filename@parse{\themestyle}%
            \includepdf[pages=-,nup=2x2,delta=10pt 10pt,landscape]{\theme}%
    \repeat
    \closein\reader}
    
    \makeatother
    
    \begin{document}
    \MakeThemeList{themelist.txt}
    \CreateAPresentationForEachTheme{themelist.txt}{template.tex}
    \CreateAlbum{themelist.txt}
    \end{document}
    
  5. Execute pdflatex --shell-escape automator.tex to produce the Beamer Catalog.

    enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.