The Australian sharemarket gained by Wednesday lunchtime after an early retreat, with mining stocks the best performers.