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?
-
4You might be interested in http://www.hartwork.org/beamer-theme-matrix/ – doncherry Aug 20 '12 at 00:58
-
@doncherry,nice! How could I download all those examples? Is there a pdf version? – Sigur Aug 20 '12 at 01:56
-
2@doncherry: I think, it’s better to link to LaTeX Beamer Theme Matrix. – Speravir Aug 20 '12 at 21:59
4 Answers
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}

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.
- 100,947
The drawback of this approach: the theme list must be updated whenever a new theme exists on the globe.
batch.bataccepts 2 arguments:%1is for theme name and%2for 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)automator.texmust be compiled withpdflatex --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}
- 36,086
-
1Nice usage of LaTeX: as a cross-platform shell (because if you made a shell script
batchin your linux, and change the call sequence to\write18{./batch \x\space dummy}, it would work under both windows and linux. – yo' Aug 20 '12 at 05:55
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:

#!/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
- 54,637
Create a Beamer template using
\mythememacro:% 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}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 >> %1Create 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)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}Execute
pdflatex --shell-escape automator.texto produce the Beamer Catalog.
- 36,086