Shared code and utilities for autotoc