LaTeX writer: Fixed inconsistencies with reference escaping.

- toLabel is now monadic, and it does the needed string escaping.
- Closes #1130.