Capacity exceeding error with \renewcommand

When I write the command, \in I many times need to add a \nolinebreak and so I wrote in the preamble \renewcommand{\in}{\in \nolinebreak}, but this resulted in an error message {see bellow}. I suspect that this has to do with the fact that \in needs to be in mathmode but I have no idea how to fix it. Any suggestions?

\documentclass{book}

\usepackage{amsfonts}
\usepackage{amsthm}
\usepackage{amsmath}

\renewcommand{\in}{\in \nolinebreak}

\begin{document}
$x \in c$
\end{document}

• @Jim That is because \nolinebreak takes an optional argument which TeX expects to be a number. It does not expect it to be a,b. So it complains. To recover, it then tries to make it 0. At least, I think so. It is a different problem than the one which your question is about. At this point, 'I told you so' is the obvious response: as I said, redefining \in is not wise. You could specify the optional command in your redefinition so TeX doesn't look for another one. Or you can try adding e.g. {} to stop it scanning for the \[ token. – cfr Sep 18 '15 at 2:11
• @Jim OK. Definitely do not use the second one. {} will do weird things. \oldin\linebreak[4] works in minimal testing. (Obviously substitute a different number depending on what you want.) It is still, IMNSHO, A Very Bad Idea. – cfr Sep 18 '15 at 2:31
• Redefining \in was not wise indeed, but I think I would have a hard time fixing those linebreaks elseway. As for my second problem setting \renewcommand {\in} {\oldin \nolinebreak [4] } will do the job. Thank you for the information. – Jim Sep 18 '15 at 2:32
• @Jim Definitely don't include spaces, especially not the one at the end. At least, you might get away with it because it is maths mode, but it looks dodgy to me ;). – cfr Sep 18 '15 at 2:39

Try this:

\let\oldin\in
\renewcommand{\in}{\oldin\nolinebreak}

• In Rome they would say «quanno ce vo’, ce vo’» (basically, «I know it's not documented, but…»): \oldin\nobreak is much more efficient. On the other hand, I'd not bother about redefining \in this way. – egreg Sep 18 '15 at 8:20