fix error when the .aux file is cleaned up before being written to the main doc

and only cache the aux file in pdf mode