A TeX input state is the N, S or M state used by the TeX input processor while reading character input: new line, skipping blanks or middle of line. It helps determine whether a space or end-of-line character becomes a TeX token.[ref]
TeX source code by Donald E. Knuth. Input stacks: mid_line, skip_blanks and new_line; get_next whitespace cases
Assume ordinary TeX category codes. In N, leading spaces are ignored. An ordinary letter emits its character token and enters M. The first space in M emits one space token and enters S; further spaces in S are ignored. An end-of-line character emits a space from M, emits
\par from N and emits nothing from S. The next line starts in N.[ref]TeX source code by Donald E. Knuth. Cases where character is ignored; Handle situations involving spaces, braces, changes of state
For an original trace, take a line containing two leading spaces,
A, three spaces and B, followed by a space-only line. The first two spaces disappear in N. A enters M; one space survives and the next two disappear in S; B returns to M. The first line end supplies another space. The blank line then supplies \par. The resulting sequence is A, space, B, space, \par.Thus source whitespace is processed before word spacing and text paragraph layout. This state records part of scanning, not whether TeX is currently building a text line or a mathematical formula; TeX control sequences, comments and changed TeX category codes have further scanning rules.
New to topics? Read the docs here!