Fix problem with recursion in table of contents macro

Fixes #1036