<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl -T

# The content of the following variable is configuration data:
@DiscoverMacro::datafile_path = ('program','.');

=head1 NAME

discovermacro.pl - Discover which LaTeX package contains a missing macro

=head1 SYNOPSIS

B&lt;discovermacro.pl&gt; \I&lt;themissingmacro&gt;

B&lt;discovermacro.pl&gt; I&lt;mydocument.log&gt;

B&lt;discovermacro.pl&gt;

=head1 DESCRIPTION

The ucs package uses many macros from many packages which have to be 
included with B&lt;\usepackage&gt; before the inclusion of F&lt;ucs.sty&gt;.

The missing macro can be given directly as parameter. Note that the
backslash must be included, so with most shells you either need to
quote it or write a double backslash (e. g. \\cyrc or '\cyrc').

An alternative way is to give a LaTeX log file as parameter in which
case the missing macros are parsed from it. 

If no argument is given, the newest LaTeX log file in the current
directory is used as default.

=head1 ALTERNATIVES

B&lt;discovermacro.pl&gt; uses the data file F&lt;ltxmacrs.txt&gt; which is human
readable, thus can be used directly.

=cut

use strict;

package DiscoverMacro::H;

sub cleanline($) {
    my $line = shift;
    chomp $line;
    $line =~ s/^\s*//;
    $line =~ s/^\#.*//;
    return $line;
}


sub readline2($) {
    my $file = shift;
    my $line = &lt;$file&gt;;
    while ($line =~ /\\\n?$/s) {
	$line =~ s/\\\n?$//;
	my $next = &lt;$file&gt;;
	$next =~ s/^\s*//;
	$line .= $next;
    }
    return $line;
}

sub escape($$) {
    my ($format,$text) = @_;
    if ($format eq 'text/plain') {
	$text =~ s/\[\[\[.*?\]\]\]//g;
    } elsif ($format eq 'text/html') {
	$text =~ s{[&lt;&gt;&amp;]|(\n[ \t]*)}{ my $x=$&amp;;
	    if ($x =~ /^\n/) {
		$x=~s/\t/        /g;
		$x=~s/ /&amp;nbsp;/g;
		"&lt;br&gt;$x"; 
	    } else {
		sprintf "&amp;#%d;", ord $&amp; }}egs;
	$text =~ s{\[\[\[.+?\]\]\]}{
	    my ($t) = ($&amp; =~ /\[\[\[(.+?)\]\]\]/);
	    my @t = split / /,$t;
	    my $r = '';
	    if ($t[0] eq 'NAME') {
		$r = "&lt;a name=\"$t[1]\"&gt;";
	    } elsif ($t[0] eq 'HREF') {
		$r = "&lt;a href=\"$t[1]\"&gt;";
	    } elsif ($t[0] eq '/NAME') {
		$r = "&lt;/a&gt;";
	    } elsif ($t[0] eq '/HREF') {
		$r = "&lt;/a&gt;";
	    } else {
		warn "escape($format,[[[$t[0]...]]])";
	    }
	}ge;
	return $text;
    } elsif ($format eq 'identifier') {
	$text =~ s/[^a-z0-9]/
	    sprintf "_%02X", ord $&amp;/ge;
    } else {
	warn "Unknown format $format";
	return escape('text/plain',$text);
    }
    return $text;
}

sub header($$) {
    my ($format,$header) = @_;
    $header = escape($format,$header);
    if ($format eq 'text/plain') {
	my $len = length $header;
	return "\n$header\n".('=' x $len)."\n";
    } elsif ($format eq 'text/html') {
	return "&lt;p&gt;&lt;table border=1&gt;\n&lt;tr&gt;&lt;th align=left colspan=2&gt;$header&lt;/th&gt;&lt;/tr&gt;\n";
    } else {
	warn "Unknown format $format";
	return header('text/plain',$header);
    }
}

sub footer($) {
    my ($format) = @_;
    if ($format eq 'text/plain') {
	return "\n";
    } elsif ($format eq 'text/html') {
	return "&lt;/table&gt;&lt;/p&gt;\n\n";
    } else {
	warn "Unknown format $format";
	return footer('text/plain');
    }
}

sub line($$) {
    my ($format,$line) = @_;
    $line = escape $format, $line;
    if ($format eq 'text/plain') {
	return "$line\n";
    } elsif ($format eq 'text/html') {
	return "&lt;tr&gt;&lt;td colspan=2&gt;$line&lt;/td&gt;&lt;/tr&gt;\n";
    } else {
	warn "Unknown format $format";
	return line($format,$line);
    }
}


sub twocol($$$) {
    my ($format,$col1,$col2) = @_;
    $col1 = escape $format, $col1;
    $col2 = escape $format, $col2;
    if ($format eq 'text/plain') {
	return "$col1\t$col2\n";
    } elsif ($format eq 'text/html') {
	return "&lt;tr&gt;&lt;td&gt;$col1&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/td&gt;&lt;td&gt;$col2&lt;/td&gt;&lt;/tr&gt;\n";
    } else {
	warn "Unknown format $format";
	return twocol('text/plain',$col1,$col2);
    }
}


package DiscoverMacro::Feature;

use vars qw/$obj_count/;
$obj_count = 0;

sub new($$$) {
    my ($proto,$db,$name) = @_;
    $obj_count++;
    my $class = ref($proto) || $proto;
    my $self = {};
    bless $self, $class;
    $self-&gt;{name} = $name;
    $self-&gt;{db} = $db;
    $self-&gt;loadfeature();
    return $self;
}

sub DESTROY {
    $obj_count--;
}

sub getfontenc($) {
    my $self = shift;
    return $self-&gt;{fontencoding};
}

sub getlatexcmd($) {
    $_[0]-&gt;{latexcmd};
}

sub getneeds($) {
    my $self = shift;
    return $self-&gt;{needs};
}

sub getpackages($) {
    my $self = shift;
    return $self-&gt;{packages};
}

sub getpackages_ascode($) {
    my $self = shift;
    return join '', map {
	my $p = $_;
	$p = "{$_}" unless $p =~ /\}$/;
	"\\usepackage$p\n";
    } @{$self-&gt;{packages}};
}


sub loadfeature($) {
    my $self = shift;
    my $pos = $self-&gt;{db}-&gt;getfeaturepos($self-&gt;{name});
    unless (defined $pos) {
	$self-&gt;{undefined} = 1;
	return;
    }
    my $file = $self-&gt;{db}-&gt;getfileat($pos);
    my $line;
    my $lastfile = undef;
    while (defined ($line = DiscoverMacro::H::readline2($file))) {
	my $tlastfile;
	$line = DiscoverMacro::H::cleanline $line;
	next if $line eq '';
	my @line = split ' ',$line;
	if ($line[0] eq 'FONTENCODING') {
	    warn "Two fontencodings in feature $self-&gt;{name}"
		if defined $self-&gt;{fontencoding};
	    $self-&gt;{fontencoding} = $line[1];
	} elsif ($line[0] eq 'CTAN') {
	    if (!defined $lastfile) {
		die "CTAN not preceded by FILE in feature $self-&gt;{name}"; }
	    my $ctan = $self-&gt;{ctan};
	    warn "Two CTAN locations defined for file $lastfile ".
		"in feature $self-&gt;{name}" if defined $$ctan{$lastfile};
	    $$ctan{$lastfile} = $line[1];
	    $self-&gt;{ctan} = $ctan;
	} elsif ($line[0] eq 'LATEXCMD') {
	    warn "Two LATEXCMDs in feature $self-&gt;{name}"
		if defined $self-&gt;{latexcmd};
	    $self-&gt;{latexcmd} = $line[1];
	} elsif ($line[0] eq 'NEEDS') {
	    warn "Two NEEDS lines in feature $self-&gt;{name}"
		if defined $self-&gt;{needs};
	    $self-&gt;{needs} = join ' ',@line[1..$#line];
	} elsif ($line[0] eq 'END') {
	    warn "FEATURE $self-&gt;{name} ended by END $line[1]"
		if $line[1] ne 'FEATURE';
	    last;
	} elsif ($line[0] eq 'COMMENT') {
	    my $comment = readblock($file,'COMMENT',1);
	    if (defined $self-&gt;{comment}) {
		warn "Two COMMENT sections in feature $self-&gt;{name}.".
		    "Concatenating";
		$comment = "$self-&gt;{comment}$comment"; }
	    $self-&gt;{comment} = $comment;
	} elsif ($line[0] eq 'INSTALL') {
	    my $install = readblock($file,'INSTALL',1);
	    if (defined $self-&gt;{install}) {
		warn "Two INSTALL sections in feature $self-&gt;{name}.".
		    "Concatenating";
		$install = "$self-&gt;{install}$install"; }
	    $self-&gt;{install} = $install;
	} elsif ($line[0] eq 'FILE') {
	    push @{$self-&gt;{files}}, $line[1];
	    $tlastfile = $line[1];
	} elsif ($line[0] eq 'PACKAGE') {
	    push @{$self-&gt;{packages}}, $line[1];
	} else {
	    warn "Unknown command in feature $self-&gt;{name}: $line[0]";
	}
	$lastfile = $tlastfile; $tlastfile = undef;
    }
}

sub readblock($$$) {
    my ($file,$blocktype,$raw) = @_;
    my $line;
    my $str = '';
    while (defined ($line = $raw?&lt;$file&gt;:DiscoverMacro::H::readline2($file))) {
	return $str if ($line =~ /^\s*END\s+\Q$blocktype\E\s*$/);
	$line = DiscoverMacro::H::cleanline $line unless $raw;
	#print "L:$line\n";
	$str .= $line;
    }
    warn "EOF in $blocktype";
    return $str;
}

sub isdefined($) {
    my $self = shift;
    return !$self-&gt;{undefined};
}

sub as_text($$) {
    my ($self,$f) = @_;
    my $link = "[[[NAME ".
	DiscoverMacro::H::escape('identifier',$self-&gt;{name})."]]]";
    my $text = DiscoverMacro::H::header
	($f,"${link}Feature: $self-&gt;{name}\[[[/NAME]]]");
    if ($self-&gt;{undefined}) {
	$text .= DiscoverMacro::H::line($f,"No information available");
    }
    if (defined $self-&gt;{fontencoding}) {
	$text .= DiscoverMacro::H::twocol($f,"Fontencoding:",
					  $self-&gt;{fontencoding});
    }
    for my $i (@{$self-&gt;{packages}}) {
	$text .= DiscoverMacro::H::twocol($f,"Package:",$i);
    }
    if (defined $self-&gt;{needs}) {
	$text .= DiscoverMacro::H::twocol($f,"Needs:",$self-&gt;{needs});
    }
    for my $i (@{$self-&gt;{files}}) {
	my $ctan = ${$self-&gt;{ctan}}{$i};
	if (defined $ctan) {
	    $ctan = " (CTAN: [[[HREF http://www.ctan.org/tex-archive/".
		"$ctan]]]$ctan\[[[/HREF]]])";
	} else { $ctan = ''; };
	$text .= DiscoverMacro::H::twocol($f,"Needed file:",$i.$ctan);
    }
    if ($self-&gt;{comment}) {
	$text .= DiscoverMacro::H::twocol($f,"Comment:",$self-&gt;{comment});
    }
    if ($self-&gt;{install}) {
	$text .= DiscoverMacro::H::twocol($f,"Installation:",$self-&gt;{install});
    }
    $text .= DiscoverMacro::H::footer $f;
    return $text;
}

package DiscoverMacro::Macro;

use Data::Dumper;

use vars qw/$obj_count/;
$obj_count = 0;

sub new($$$) {
    my ($proto,$db,$macro) = @_;
    my $class = ref($proto) || $proto;
    my $self = {};
    $obj_count++;
    bless $self, $class;
    $self-&gt;{macro} = $macro;
    $self-&gt;{db} = $db;
    $self-&gt;loadlist();
    return $self;
}

sub DESTROY {
    $obj_count--;
}

sub isdefined($) {
    my $self = shift;
    return !$self-&gt;{undefined};
}

sub getname($) {
    my $self = shift;
    return $self-&gt;{macro};
}

sub getlist($) {
    my $self = shift;
    return $self-&gt;{list};
}

sub loadlist($) {
    my $self = shift;
    my $macros = $self-&gt;{db}-&gt;{macros};
    my $macro = $self-&gt;{macro};
    my $list = $$macros{$macro};
    unless (defined $list) {
	my $regex = $self-&gt;{db}-&gt;{regexmacros};
	while (my ($re,$l) = each %$regex) {
	    #print "RE: $re\n";
	    if ($macro =~ /$re/) {
		$self-&gt;{regex} = $re;
		$list = $l; last; }
	}
    }
    unless (defined $list) {
	$self-&gt;{undefined} = 1;
	return;
    }
    $self-&gt;{list} = $list;
    my %tlist;
    my @list = grep { my $bad = $_ eq 'OR' || $_ eq 'AND' || $tlist{$_};
		  $tlist{$_}=1; !$bad; } split ' ', $self-&gt;{list};
    my %features = ();
    for my $i (@list) {
	$features{$i} = new DiscoverMacro::Feature($self-&gt;{db},$i)
	    unless defined $features{$i};
    }
    $self-&gt;{features} = \%features;
}

sub getfeature($) {
    my ($self,$name) = @_;
    return ${$self-&gt;{features}}{$name};
}

sub as_text($$) {
    my ($self,$f) = @_;
    my $text = '';
    my $link = "[[[NAME ".
	DiscoverMacro::H::escape('identifier',$self-&gt;{macro})."]]]";
    $text .= DiscoverMacro::H::header
	($f,"${link}Macro: $self-&gt;{macro}\[[[/NAME]]]");
    if ($self-&gt;{undefined}) {
	$text .= DiscoverMacro::H::line($f,"Macro is unknown.");
    } else {
	my $list = $self-&gt;{list};
	my $features = $self-&gt;{features};
	$list =~ s{\S+}{
	    my $w = $&amp;;
	    if ($$features{$w}) {
		$w = "[[[HREF #".DiscoverMacro::H::escape('identifier',$w).
		    "]]]$w\[[[/HREF]]]";
	    }
	    $w;
	}ge;
	$text .= DiscoverMacro::H::twocol($f,"Available with:",$list);
    }
    $text .= DiscoverMacro::H::footer($f);
    for my $feature (values %{$self-&gt;{features}}) {
	$text .= $feature-&gt;as_text($f);
    }
    return $text;
}

package DiscoverMacro;

use IO::File;
use Data::Dumper;

use vars qw/$obj_count @datafile_path/;
$obj_count = 0;

sub new($) {
    my ($proto) = @_;
    my $class = ref($proto) || $proto;
    my $self = {};
    $obj_count++;
    bless $self, $class;
    $self-&gt;{missingmacros} = {};
    $self-&gt;opendata();
    return $self;
}

sub DESTROY {
    $obj_count--;
}

sub skip_to_end($$$) {
    my ($file,$type,$lnr) = @_;
    my $line;
    while (defined ($line = DiscoverMacro::H::readline2($file))) {
	return $file-&gt;getpos 
	    if $line =~ /^\s*END\s*\Q$type\E\s*$/;
    }
    warn "Could not find end of $type-section started on line $lnr";
    return undef;
}

sub lineinfo($) {
    my $lnr = shift;
    return "ltxmacrs.txt:$lnr: ";
}

sub opendata($) {
    my $self = shift;
    my $macros = {};
    my $regexmacros = {};
    my $features = {};
    my $datafile = $self-&gt;{datafile};
    unless (defined $datafile) {
	for my $dir (@datafile_path) {
	    if ($dir eq 'program') {
		$datafile = $0; $datafile =~ s@[^/]*$@ltxmacrs.txt@;
	    } elsif (-d $dir) {
		$datafile = "$dir/ltxmacrs.txt";
	    } else {
		$datafile = "$dir";
	    }
	    if (-e $datafile) { last; }
	    else { $datafile = undef; }
	}
	die "Could not find data file ltxmacrs.txt in path ".
	    join ', ', map {
		($_ eq 'program')?'script location':$_ } @datafile_path
		    unless defined $datafile;
	$self-&gt;{datafile} = $datafile;
    }
    my $data = new IO::File($datafile,"r") or
	die "Could not open $datafile for reading";
    my $line;
    while (defined ($line = DiscoverMacro::H::readline2($data))) {
	$line = DiscoverMacro::H::cleanline($line);
	next if $line eq '';
	my (@line) = split ' ', $line;
	if ($line[0] eq 'MACRO') {
#	    print Dumper(\@line);
	    warn lineinfo($.)."Macro $line[1] given twice\n"
		if defined $$macros{$line[1]};
	    $$macros{$line[1]} = join ' ', @line[2..$#line];
	} elsif ($line[0] eq 'REGEX') {
	    warn lineinfo($.)."Regex macro $line[1] given twice\n"
		if defined $$regexmacros{$line[1]};
	    $$regexmacros{$line[1]} = join ' ', @line[2..$#line];
	} elsif ($line[0] eq 'FEATURE') {
	    $$features{$line[1]} = $data-&gt;getpos;
	    skip_to_end($data,'FEATURE',$.);
	} else {
	    warn lineinfo($.)."Unknown command '$line[0]'\n";
	}
    }
    $self-&gt;{macros} = $macros;
    $self-&gt;{regexmacros} = $regexmacros;
    $self-&gt;{features} = $features;
    $self-&gt;{datafile} = $data;

#    print Dumper($macros);
}

sub getmacro($$) {
    my ($self,$macro) = @_;
    return new DiscoverMacro::Macro($self,$macro);
}

sub getfeaturepos($$) {
    my ($self,$feature) = @_;
    my $features = $self-&gt;{features};
    return $$features{$feature};
}

sub readlog($$;$) {
    my ($self,$filename,$file) = @_;
    my $found = 0;
    if (!defined $file) {
	$file = new IO::File($filename,"r")
	    or die "Could not open log file '$filename' for reading: $!";
    }
    my $line;
    while (defined ($line = &lt;$file&gt;)) {
	chomp $line;
	if ($line =~ /^! Undefined control sequence\.$/) {
	    chomp ($line = &lt;$file&gt;);
	    #print "LINE: '$line'\n";
	    my $dots = '';
	    my ($macro) = ($line =~ /(\\.)$/);
	    ($dots,$macro) = 
		($line =~ /(...)(\\[a-zA-Z@]+) ?$/) unless defined $macro;
	    ($dots,$macro) = 
		($line =~ /(...)([a-zA-Z@]+) ?$/) unless defined $macro;
	    my $regex = 0;
	    if ($dots eq '...') {
		$regex = 1;
		$macro =~ s/^\\//;
		$macro = "\\\\[a-zA-Z@]*\Q$macro";
	    } else {
		$macro = "\\$macro" unless $macro =~ /^\\/;
	    }
	    unless (defined $macro) {
		warn "$filename:$.: Could not identify undefined control in:\n".
		    "\t$line\n";
		next; };
	    #print "MACRO: '$macro'\n";
	    if ($regex) {
		$found = 0;
		for my $m (keys %{$self-&gt;{macros}}) {
		    if ($m =~ /$macro/) {
			$self-&gt;addmacro($m);
			$found = 1; }
		}
		$self-&gt;addmacro("REGEX:$macro") unless $found;
	    } else {
		$self-&gt;addmacro($macro);
	    }
	    $found = 1;
	} elsif ($line =~ /^! Package babel Error: You haven\'t defined the language (.+) yet.$/) {
	    my $lang = $1;
	    $self-&gt;addmacro("\\selectlanguage{$lang}");
	    $found = 1;
	} elsif ($line =~ /^! LaTeX Error: Environment .* undefined\.$/) {
	    my ($env) =
		($line =~ /^! LaTeX Error: Environment (.*) undefined\.$/);
	    unless (defined $env) {
		warn "$filename:$.: Could not identify environment in:\n".
		    "\t$line\n" unless defined $env;
		next; };
	    $self-&gt;addmacro("\\begin{$env}");
	    $found = 1;
	} elsif ($line =~ /^! LaTeX Error: Encoding scheme \`.*\' unknown\.$/) {
	    my ($fe) =
		($line =~ /^! LaTeX Error: Encoding scheme \`(.*)\' unknown\.$/);
	    unless (defined $fe) {
		warn "$filename:$.: Could not identify fontencoding in:\n".
		    "\t$line\n" unless defined $fe;
		next; };
	    $self-&gt;addmacro("\\fontencoding{$fe}");
	    $found = 1;
	} elsif ($line =~ /^! LaTeX Error: Command .* (not provided|unavailable)/) {
	    my ($macro) =
		($line =~ /^! LaTeX Error: Command (.*) (not provided|unavailable)/);
	    unless (defined $macro) {
		warn "$filename:$.: Could not identify macro in:\n".
		    "\t$line\n" unless defined $macro;
		next; };
	    $macro = "\\$macro" unless $macro =~ /^\\/;
	    $self-&gt;addmacro("$macro");
	    $found = 1;
	} elsif ($line =~ /^! Package ucs Error: Unknown .* tag '.*' \((.*)\)\.$/) {
	    my ($macro) =
		($line =~ /^! Package ucs Error: Unknown .* tag '.*' \((.*)\)\.$/);
	    unless (defined $macro) {
		warn "$filename:$.: Could not identify macro in:\n".
		    "\t$line\n";
		next; };
	    $macro = "\\$macro" unless $macro =~ /^\\/;
	    $self-&gt;addmacro("$macro");
	    $found = 1;
	} elsif ($line =~ /^! Font .*=([^=]+) at .* not loadable: Metric \(TFM\)/) {
	    my ($tfm) = ($line =~ /^! Font .*=([^=]+) at .* not loadable: Metric \(TFM\)/);
	    unless (defined $tfm) {
		warn "$filename:$.: Could not identify TFM filename in:\n".
		    "\t$line\n";
		next; };
	    print "XXX: $tfm\n";
	    $self-&gt;addmacro("$tfm.tfm");
	    $found = 1;
	}
    }
    close $file;
    return $found;
}

sub addmacro($$%) {
    my ($self,$macro) = @_;
    my $macros = $self-&gt;{missingmacros};
    return $$macros{$macro} if $$macros{$macro};
    my $res = $self-&gt;getmacro($macro);
    $$macros{$macro} = $res if defined $res;
    return $res;
}

sub getfileat($$) {
    my ($self,$pos) = @_;
    my $file = $self-&gt;{datafile};
    $file-&gt;setpos($pos) or
	die "Could not seek in datafile to pos $pos";
    return $file;
}

sub getmissingmacros($) {
    my $self = shift;
    return $self-&gt;{missingmacros};
}

sub as_text($$) {
    my ($self,$f) = @_;
    my $macros = $self-&gt;{missingmacros};
    my $str = '';
    for my $m (keys %$macros) {
	$str .= $$macros{$m}-&gt;as_text($f);
    }
    return $str;
}

sub close($) {
    my $self = shift;
    $self-&gt;{macros} = undef;
    $self-&gt;{features} = undef;
    $self-&gt;{missingmacros} = undef;
    close $self-&gt;{datafile};
}

sub getfeature($$) {
    my ($self,$feature) = @_;
    return new DiscoverMacro::Feature($self,$feature);
}

sub scanformacro($%) {
    my ($self,%args) = @_;
    my $file = $args{file};
    my $fh = new IO::File($file,"r") or
	die "Could not open $file for reading: $!";
    my $line;
    # {\newenvironment}{\renewenvironment}{\newif}
    my $newcommand = '\\\\newcommand|\\\\renewcommand|\\\\providecommand|'.
	'\\\\DeclareRobustCommand|\\\\def';
    my $newenvironment = '\\\\newenvironment|\\\\renewenvironment';
    my @macros;
    while (defined ($line = &lt;$fh&gt;)) {
	chomp $line;
	print "L: $line\n";
	$line =~ s{($newcommand) \s* \{? (\\[a-zA-Z@]+) \}?}{
	    print "MACRO: $2\n";
	    my ($env) = ($2 =~ /^\\end(.*)$/);
	    if (defined $env) {
		print "ENV: $env\n"; }
	}gxeo;
	$line =~ s{($newenvironment) \s* \{ ([^\}]+) \} }{
	    print "ENV: $2\n";
	}gxeo;
    }
    print Dumper [\@macros];
}


sub main(@) {
    if (@_) {
	for my $file (@_) {
	    my $obj = new DiscoverMacro;
	    if (-e $file) {
		$obj-&gt;readlog($file);
	    } else {
		$obj-&gt;addmacro($file);
	    }
	    print $obj-&gt;as_text('text/plain');
	};
    } else {
	my ($file) = 
	    sort { my @a = stat $a; my @b = stat $b; $b[9] &lt;=&gt; $a[9] }
	grep { $_ ne 'missfont.log' } (&lt;*.log&gt;);
	die "No logfile found" if (!defined $file);
	print "Using logfile $file.\n";
	&amp;main($file);
    }
}

sub test() {
    my $obj = new DiscoverMacro;
    $obj-&gt;scanformacro(file =&gt; 'test.tex');
    exit;
}

#test;

caller || &amp;main(@ARGV);

1;
</pre></body></html>