improve latex inline math

fixes issues #69 and #62.