#!/usr/bin/perl -w 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/; # 06/10/2007: "Pino" (Giseppe Vallone) pointed out that this script should # *update* $infof, not just write over it if it already exists. The highlight # box info is stored there, and keyjnote's behavior is to merge. my $info = ''; my $inPageProps = 0; my %PageProps = (); my $slidenum = 0; if(-f $infof){ open(INFO, "$infof") or die "$infof exists, but opening it for reading produced error $!"; while(){ my $line = $_; if($line =~ /^PageProps\s*=\s*{/){ $inPageProps = 1; } elsif($inPageProps == 1){ if($line =~ /^\s*(\d+):?\s*{/){ $slidenum = $1; $inPageProps = 2; } elsif($line =~ /^\s*}/){ $inPageProps = 0; } } elsif($inPageProps == 2){ if($line =~ /^\s*}/){ $inPageProps = 1; } else{ $PageProps{$slidenum} .= $line; } } else{ $info .= $line; } } close(INFO) or die "Error $! closing $infof after reading."; } else{ $info = "# -*- coding: iso-8859-1 -*-\n"; } # At this stage $info includes any preexisting info *except* page properties, # which have been moved into %PageProps. # Find page transitions in the .tex file. $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; if($PageProps{$slidenum} =~ /^\s*'transition':/){ $PageProps{$slidenum} =~ s/(^\s*'transition':\s*)\w+/$1$transition/; } else{ $PageProps{$slidenum} .= " 'transition': $transition\n"; } } } } open(INFO, "> $infof") or die "could not open $infof for writing"; print INFO $info; # Everything but %PageProps. print INFO "PageProps = {\n"; # Open up PageProps. foreach my $k (sort {$a <=> $b} keys %PageProps){ printf INFO "% 3s: {\n", $k; # slidenum print INFO "$PageProps{$k} },\n"; } print INFO "}\n"; close(INFO) or die "error closing > $infof";