除了手动更改主题并为每个可用主题进行编译之外,有没有更简单的方法可以做到这一点,以便我可以自动获取每个可用主题的 PDF 演示文稿?
答案1
这是一个 shell 脚本,它创建一个主文档 main.tex,其中包含当前 TL2012 所有主题的两个示例页面。可以对其进行修改以在 Windows 下使用。在空目录中运行该脚本。完整文档位于http://perce.de/temp/main.pdf这是第一页:
#!/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
答案2
这是一个小perl
脚本(这是我两天内写的第二个脚本,我保证我不会太过痴迷),你可以按如下方式运行它
perl createBeamer.plx slides.tex
或者你可以用任意数量的文件来调用它
perl createBeamer.plx file1.tex file2.tex file3.tex
请注意,每个.tex
文件中都有几行必要的内容,如下所述。
你只需要在数组中指定要使用的主题@themes
,然后运行一个脚本就能获得很多pdfs
魔法:)
创建Beamer.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";
}
}
幻灯片.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}
编辑
如果你想要一个稍微更动态的方法,那么你可以直接从其位置读取 beamer 主题
# 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);
}
并注释掉(或删除)先前的定义@themes
。
当然,如果您想让它具有极强的可移植性,您可以每次执行目录搜索。
答案3
这种方法的缺点是:每当地球上出现新的主题时,就必须更新主题列表。
batch.bat
接受 2 个参数:%1
主题名称和%2
要包含的文件名。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.tex
必须用 进行编译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}
答案4
使用宏创建 Beamer 模板
\mytheme
:% 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}
创建一个批处理文件来安装所有可用的 Beamer 主题:
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
创建一个批处理文件来使用每个可用主题编译 Beamer 模板:
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)
创建另一个 TeX 输入文件以自动创建 Beamer 相册或目录:
% 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}
执行
pdflatex --shell-escape automator.tex
以生成 Beamer 目录。