#!/usr/bin/perl -w

open(OMIT, "module-6-slides.ofh") or die "Couldn't open .ofh file";
my %omit = ();
while(<OMIT>) {
  chomp;
  $omit{$_} = 1;
}
close(OMIT);

open(AUX, "module-6-slides.aux") or die "Couldn't open aux file";
my $totalPages = 0;
while(<AUX>) {
  if(/\\beamer\@documentpages\s*{(\d*)}/) {
    $totalPages = $1;
    last;
  }
}
close(AUX);

my @pages = ();
for(my $i = 1; $i <= $totalPages; $i++) {
  push @pages, $i unless $omit{$i};
}

my $pageSpec = join(',', @pages);

open(HANDOUT, ">module-6-handout.tex") or die "Couldn't open handout tex for writing";
print HANDOUT <<EOF;
\\documentclass[a4paper, landscape]{article}
\\usepackage{pdfpages}
\\begin{document}
\\includepdf[pages={$pageSpec},nup=2x2, delta = 10
10,frame, noautoscale, scale=1]{module-6-slides.pdf}
\\end{document}
EOF
close(HANDOUT);
