chunk save & TOC handling; generalized for any type of document