Some refactoring to allow typesetting of arbitrary files.