Fixed some bugs

- The scroll handler unnecessarily locked the document
  leading to a dead lock
- A failed mathtex call lead to a segfault