#!/usr/bin/perl -w

# Copyright 2006 Rob Reid, using the GNU public license version 2.

# Produces a .info file for use with KeyJnote, using special comments in a
# LaTeX file.

my $usage = q {
Use: gettransitions talk.tex

talk.tex should be a LaTeX file using the beamer documentclass.
The transitions commented immediately after each \\begin{frame} or
\\pause will be put into talk.pdf.info.
};

my $texf = $ARGV[0];
if($texf !~ /\.tex$/){
  print $usage;
  exit(1);
}

my $infof = $texf;
$infof =~ s/\.tex$/.pdf.info/;
open(INFO, "> $infof") or die "could not open $infof for writing";
print INFO "# -*- coding: iso-8859-1 -*-\n\nPageProps = {\n";

my $slidenum = 0;
while(<>){
  my $tline = $_;
  chomp $tline;

  if($tline =~ /^[^%]*\\(begin{frame}|pause)/ || $tline =~ "%O"){
      ++$slidenum;
      print "$slidenum: $tline\n";
      if($tline =~ /%O?\s*([A-Z]\w+)/){
	  my $transition = $1;
	  printf INFO " % 2d: {\n", $slidenum;
	  print INFO "       'transition': $transition\n     },\n";
      }
  }
}
print INFO "}\n";
close(INFO) or die "error closing > $infof";
