# File mk, line 634
def compile(basename,makefile,makeopt,target,targetext)
  # puts "compile:"; [basename,makefile,makeopt,target,targetext].each { |x| puts "\t"+x.inspect }
  # since we changed dir to where the tex-source is, \input-ed local files
  # may become invisible, so add the original dir to TEXINPUTS:
  # use kpsewhich to find the effective value of TEXINPUTS since it may be
  # unset and then has to be taken from texmf.cnf
  texinputs = `kpsewhich --expand-var '\$TEXINPUTS'`.strip
  
  loop do
    r = sys("TEXINPUTS='#{ENV['PWD']}:#{texinputs}' " +
      "TEX_SOURCE_BASE=\"#{basename}\" " +
      "TEX_DEP='#{tex_dep(basename).join(' ')}' " +
      "DVIPS='dvips -q' " +
      "make #{makeopt} -f #{makefile} #{targetext}"
    )
    break if r[:success] && r[:error].empty?
    # the following causes make errors:
    # File.delete(basename + '.aux') if File.exist?(basename + '.aux')
    # Better may be to do a clean operation.
    show_error_and_edit(basename,target) 
  end
end