
#line 2802 "ext.nw"
$INPUT = $ARGV[0] && shift;

if ($INPUT eq "")
{  print "usage: emptyline expexts an argument\n";
   die;
}

open (INPUT)  || die "Can't find input file $INPUT: $!\n";

while (<INPUT>)
{ $codechunk = ""; 
  if (/nwbegincode/) 
    { $line = $_; chop($line);
      print $line,"\\nwcodepenalty=\\Lhighpen\n"; 
      $_ = <INPUT>;
      $anzahl = 0;           
      while (!/nwendcode/)
        { if (/\S/) {$codechunk .= $_;}
          else {$codechunk .= "\\vspace{\\Lemptyline}"; $anzahl++;}         
          $_ = <INPUT>;
        }
    }
  if (/begin{Lcode}/)
    { print;
      $_ = <INPUT>; 
      $anzahl = 0;          
      while (!/end{Lcode}/)
        { if (/^[\{\}\\ t]*$/) {$codechunk .= "\\vspace{\\Lemptyline}"; $anzahl++;} 
          else {$codechunk .= $_;}         
          $_ = <INPUT>;
        }
    }
  if ($codechunk)
    { $nlines = ($codechunk =~ tr/\n/\n/); $lcount = 0;
      while ($codechunk =~ /^([^\n]*)\n/)
       { $line = $1;  $lcount++;
         $codechunk = $';
         if ($lcount <= 3 || ($lcount >= $nlines - 3 && $lcount < $nlines))  
            {print $line, "\\nwcodepenalty=\\Lhighpen\n";}
         else {print $line , "\\nwcodepenalty=\\Llowpen\n";}
           
       }
      print $codechunk;
    }
    
  print;   # Prints text and nwendcode and end{Lcode} respectively.
  while ($anzahl > 0) {print "\%\n"; $anzahl--;}
}

close(<INPUT>);

