#!/usr/bin/perl ## dirty little script for generating pdf bookmarks from the lop file use File::Basename; die "no filename given\n" unless $ARGV[0]; ($name, $path, $suffix) = fileparse($ARGV[0], qw(\. \.out \.lop)); $in = join("", $path, $name, ".lop"); $out = join("", $path, $name, ".out"); open LOP, $in or die $!; open OUT, ">$out" or die $!; print OUT '\let\WriteBookmarks\relax', "\n"; while () { chomp; s/^\\contentsline\s+//; (/\{(.+)\}\{(.+)\}\{(.+)\}\{(.+)\}/) and do { $title = $2; $tag = $4; if (($1 eq 'Topic') or ($1 eq 'Assignment') or ($1 eq 'Answers')) { $level = 0; $savetag = $4; $upper = ""; } else { $level = 1; $upper = $savetag; }; ## it would be much better to typeset the pdf bookmarks... $title =~ s/\\text[^{]+\{([^}]+)\}/$1/g; $title =~ s/\$//g; $title =~ s/\\([^ ]+) /$1/g; $title =~ s/[{}]//g; print OUT '\BOOKMARK [', $level, ']{', $tag, '}{', $title, '}{', $upper, '}', "\n"; }; }; print "wrote $out\n"; close LOP; close OUT;