One thing to note is that TeX's only means of nesting arguments are braces. You can define a macro \def\whatever[#1]{...}
but when you call it as \whatever[oh[well]]
, things go down the drain awfully. Calling it as \whatever[{oh[well]}]
however works swimmingly, and \whatever
never notices it has been taken for a ride by slipping a ]
into its argument. So the braces can be used as a means of hiding occurences of the closing delimiter from TeX without actually affecting the intended argument.
It also means that whenever you call a macro using delimited arguments with a non-literal argument (more exactly, an argument not completely under your own control, as it often happens when you write a macro package to be used by others), you should always add a layer of braces around each delimited argument, like \whatever[{#1}]
or similar. There is no other way to ensure that arguments will not get chopped up into something different because they themselves may contain a closing bracket.
TeX has three modes of operation: (1) Converting the input stream to tokens, (2) expanding the token, (3) executing a complete command (made up of tokens).
In more detail, it first prepares one line of input by stripping off the EOL (OS dependent) and all spaces from the end of the line (usually also tab characters). Then it adds its own endline character (the value of \endlinechar
, normally ctrl-M).
It then reads the line one character at a time until it obtains a complete token (generally a single character or a control sequence). This token is passed to stage (2) the macro expansion engine, which expands it (if it can be) or asks for more tokens from stage (1) (if needed for the expansion process) or passes it along to stage (3), the execution process. This process either executes the command, or asks for more tokens from stage (2), which may then have to ask for more tokens from stage (1).
The tokenizing stage converts most characters to a token consisting of a character-code/category-code pair. Since the execution engine is capable of assigning new category codes to a character, it can influence the behavior of stage (1).
One slight complication is the existence of an endline character within a line. TeX considers that the end and ignores the rest of the line. Also a comment character (normally %
) causes the rest of the line to be ignored, including the endline character.
Note that tokenization happens within a line (you cannot start a macro token on one line and finish it on the next), but expansion -- step (2) -- can request more tokens and that can continue over to the next line.
I don't know whether you can put this process under either of your two schemes. The "chunks" are either lines or tokens, neither of which have constant length, so the first description is out. And certainly TeX doesn't read a whole file at once (except perhaps it may move it from disk to an input buffer for efficiency).
As for outputting the results: TeX sends it a page at a time to the output. It evaluates whether a full page has been obtained after each paragraph has been processed. When it breaks paragraphs into lines (along with hyphenation and margin justifying), it operates on an entire paragraph at a time.
Best Answer
Textures was such an implementation, on Mac OS, and it was created in the mid eighties. It had a “Flash Mode” feature which worked exactly as Knuth describes in the TeXbook. I suppose Knuth was referring to Textures among others. It has been extant until a couple of years ago. Since then, I've got no news about it…
What happened to Textures and Bluesky Research?
On Mac OS X, Claus Gerhardt's Flashmode allows this feature on TeXShop. (I've not tested it yet, but others do use it and it seems to work well.)
http://www.math.uni-heidelberg.de/studinfo/gerhardt/Flashmode/
Edit As indicated in the previous link about Textures, there is a new site dedicated to it: http://www.blueskytex.com. It provides a (free) download link to a no longer developed beta version for Mac OS X. More news are promised for soon (2015 July 1).