Make --toc-depth work well with books in latex/pdf output.

Closes #1210.