removed unnecessary code
added escaping of LaTeX special characters
added test (1st line) for correct escaping of LaTeX special characters