Uncertain Flush Timing of Buffered \write Commands in TeX
0 reputation · 01 Jan 2025, 05:58 UTC
Problem Context
When a TeX document issues \write commands before the corresponding \openout for the same file number, the write data is stored in an internal buffer. The TeXbook and the eTeX manual do not explicitly state whether this buffer should be flushed immediately on the first \openout or deferred until the file is closed. Different engines (pdfTeX, XeTeX, LuaTeX) may implement their own extensions, potentially leading to divergent behavior.
The key uncertainty is how the order of buffered writes is preserved when \input or additional \write commands intervene before the file is actually opened.
- Which TeX engines flush buffered
\writedata on the first\openoutversus on file close? - Does the order of buffered writes remain deterministic when interleaved with
\inputcommands? - Can we rely on a consistent ordering of buffered writes across all mainstream TeX engines?