The text of the header is placed from the Lua side with a call to tex.print ().
After the main body is finished, I make one more call into the Lua module to write out the current content of the index table.