Latex fix2

By our powers combined, here is a proposed fix for Issue #418 
@grosu especially, but also everybody else: please check pdf output and suggest improvements.

@dwightguth please review

Note: this is the same pull request as #433  only rebased from master.