Numerous bugfixes for undo, copy/paste + Mathtex (Latex) integration