# TeX capacity exceeded, sorry [semantic nest size=500]

Reading through tex.web, I note that there is a difference between grouping levels and semantic nesting (i.e., the nesting of math, horizontal, and vertical modes). I can think of commands which increase the grouping level without changing modes: \begingroup, \bgroup. Are there commands which nest modes without affecting the grouping level, and is it possible to reach the overflow "semantic nest size" exceeded seen in the procedure push_nest:

@p procedure push_nest; {enter a new semantic level, save the old}
begin if nest_ptr>max_nest_stack then
begin max_nest_stack:=nest_ptr;
if nest_ptr=nest_size then overflow("semantic nest size",nest_size);
@:TeX capacity exceeded semantic nest size}{\quad semantic nest size@>
end;
nest[nest_ptr]:=cur_list; {stack the record}
end;


A naive

\def~{\hbox\bgroup}
\edef~{~~~~}
\edef~{~~~~}
\edef~{~~~~}
\edef~{~~~~}
~ % 256 times \hbox\bgroup


leads to TeX's capacity being exceeded because of the number of grouping levels.

• By accident I achieved to get this error via \newcommand\foo{\mathnormal{\foo}} (note the recursion). I know too little TeX to judge whether it fulfills what you asked for (i.e., does not affect grouping level), hence I leave it as a comment. Jul 7 at 11:47

The first way that comes to my mind is to start a paragraph in vertical mode, which sets TeX in horizontal mode without grouping.

\def~{x\vbox\bgroup}
\edef~{~~~~}
\edef~{~~~~}
\edef~{~~~~}
\edef~{~~~~}
~


This produces

! TeX capacity exceeded, sorry [semantic nest size=500].