Automatically detect root document.