#!/usr/bin/perl -w # DISCLAIMER: This script should is supplied "AS IS" and its output checked # for sanity before being used for anything important such as PartII # dissertations. # This code is under the GNU Public Licence (http://www.gnu.org) # (c) Nathan Dimmock (ned21@srcf.ucam.org) 2001-2002 use strict; # zap an entire command (e.g. \cite{...} ) my @commands = ("label", "ref", "cite", "includegraphics", "vspace" ); # Zap words found as arguments to \begin{} and \end{} commands my @section = ("verbatim", "itemize", "enumerate", "table", "tabular", "figure" , "narrow", "minipage", "document" ); # Ignore any text between \begin{} & \end{} my @ignore = ( "equation", "displaymath", "eqnarray" ); my @output; foreach my $file (@ARGV) { #print "$file\n"; my $kill=0; #ignore everything while kill=1 my $currentIgn=""; #open( A, "${file}.tex" ); open( A, "$file" ); my @SRC = ; foreach my $line (@SRC) { if( $kill == 1) # Ignore certain sections completely { if( $line =~ /\\end{$currentIgn}/) { $kill=0; } $line =~ s/.*(\\end{$currentIgn})?//; next; } $line =~ s/%.*// ; # remove comments foreach my $com (@commands) { $line =~ s/\\$com.*}//g; } foreach my $sec (@section) { $line =~ s/\\.*{$sec}//g; } foreach my $ign (@ignore) { if( $line =~ /\\begin\{$ign\}/ && $line !~ /\\end\{$ign\}/ ) { $kill=1; $currentIgn=$ign; } $line =~ s/\\begin{$ign}.*(\\end{$ign})?//; } $line =~ s/\\[a-zA-Z]*//g; # remove things beginning with \ #print "$line"; push(@output, $line); } } print @output;