#! /usr/bin/perl
# table$B4D6-$H(Bfigure$B4D6-$rH4$-$@$7$F(B mgp $B$N%Z!<%8$K$9$k(B

$spc68="%"x68;
print '%include "t-kita-default.mgp"'."\n";

while(<>){
    chomp;
    if ($_ =~ /^[ ]*\\begin{(figure[*]?|table[*]?)}/){
	$flag=1;
	$page= ""; $cap= "";
	next;
    }
    if ($flag==1){ # table or figure $B4D6-$NCf(B
	if ($_ =~ /^[ ]*\\end{(figure[*]?|table[*]?)}/){
	    $flag=0;
	    print $spc68."\n";
	    print "%page\n";
	    print "\n";
	    printf("%%filter \"./platex2eps.csh title-%03d\"\n",++$co);
	    print "\\bf ". $cap ."\n";
	    print "%endfilter\n";
	    printf("%%newimage -zoom 400 \"generated_eps/title-%03d.eps\"\n",$co);
	    print "\n";
	    printf("%%filter \"./platex2eps.csh  %s\"\n",$fname);
	    print $page;
	    print "%endfilter\n";
	    print "%center\n";
	    printf("%%newimage -scrzoom 70 \"generated_eps/%s.eps\"\n",$fname);
	    print "\n";
	    next;
	}
	if ($_ =~ /\\onelineskip|\\halflineskip/){
	}elsif ($_ =~ /\\ecaption/){
	    if (!($_ =~ /}/)){ $_ = <>; chomp; }
        }elsif ($_ =~ /\\(label|caption)/){
	    if (!($_ =~ /}/)){ $tmp = <>; chomp $tmp; $_ .= $tmp; }
	    if ($_ =~ /\\label{([^}]+)}/){
                 $fname = $1;
	     }
             if ( ($_ =~ /\\caption{(.*?)}/) && (!($_ =~ /^%/)) ){
                 $cap= $1;
	     }
	}else{
	     $page= $page . $_  . "\n";
        }
    }
}


