# \edef, \xdef and \ifmmode

I don't understand the difference between \edef and \xdef in the following code. Clearly, the \xdef does what I'm expecting but why? AFAIK, $ does not start a group. \documentclass[varwidth]{standalone} \usepackage[T1]{fontenc} \usepackage{lmodern} \begin{document}$\edef\bar{\ifmmode\noexpand\true\else\noexpand\false\fi}$\meaning\bar$\xdef\bar{\ifmmode\noexpand\true\else\noexpand\false\fi}$\meaning\bar \end{document}  • $ does start a group – David Carlisle Sep 11 '15 at 21:54