5

Is it possible to get list of tokens which comes from TeX "mouth"? If I understand correctly: in mouth all macros, conditionals and special operations (like \the and \input) are expanded and then goes to "stomach".

1

2 Answers 2

7

The question is rather under specified. TeX's macro processor is not like (say) the C pre-processor where all macro expansion happens first and then an expanded source is passed to the compiler. In TeX macros are just expanded as needed and are interleaved with non-expandable assignments, which can change the result of future macro expansion.

So it is not possible to take a latex document and expand it out to just consist of TeX primitives.

It is possible to force the expansion of the following token until the next token is non expandable, so that you may then inspect that non-expandable token, but perhaps that isn't what you want.

2
  • "it is not possible to take a latex document and expand it out to just consist of TeX primitives." Surely this is possible, but requires a lot of work and programming;; and I suppose that if the list of unexpandable primitives/tokens is feed to TeX in the correct order (... and catcode, somehow) then the output should be identical?
    – user202729
    Commented Dec 10, 2021 at 5:50
  • @user202729 I was trying to highlight the difference with the C pre-processor macros where you can run cpp to do all the expansion without using a C compiler to get an expanded C program you can compile that isn't possible with tex, you need the typesetting engine available to do expansion \setbox0\hbox{abc}\ifdim\wd0>20pt yes\else no\fi for example. It is of course possible to make a tex-primitive document that makes the same output as any specific latex run, just take the \showbox output and set the same characters and rules at the same places. Commented Dec 10, 2021 at 6:42
3

As far as I understand, Knuth didn't use formal language techniques to parse TeX, just ad-hoc methods. I doubt such a list exists formally (just a few dozen scattered facts in his brain some years back...), I'm afraid to get it you'd have to get a fine comb, much patience, and a copy ot TeX's source.

(I'd like to be proven wrong, though.)

1
  • 4
    You don't need the tex source to understand TeX's parser (although it is available of course) The grammar of every TeX command is given in the TeXBook. Commented Mar 25, 2013 at 18:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .