clean up rendering in LaTeX and HTML to make more use of common functions