#!/usr/bin/perl
#
#clean a latex file for camera-ready submission
#this is the first part of cleanlatex, it removes removes all comments and
#replaces \def by \newcommand
#
#Jan Poland, March 8, 2006
#

while (<STDIN>) {
  $s=$_;
  $s=~s/^\\def\\(\w+){/\\newcommand{\\\1}{/;
  $s=~s/^\\def\\(\w+)(#\d)*#(\d){/\\newcommand{\\\1}[\3]{/;
  if ($s=~/^%/ && !($s=~/^%+\s*$/ || $s=~/^%-+%*\s*$/)) {$s="%\n";}
  if (!($s=~/^%/)) {$s=~s/([^\\])%.*/\1%/;}
  print $s;
}

