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?



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

$ x \in c $

Error ! TeX capacity exceeded, sorry [input stack size=5000].\in ->\in\nolinebreak $ x \in
  • You are re defining \in in terms of \in that will generate infinite loop. What do you want to do exactly – user11232 Sep 18 '15 at 0:58

It is not to do with maths mode. Here's a simpler example:


This gives an error:

! TeX capacity exceeded, sorry [input stack size=5000].
\robin ->\robin 
l.14 \robin

!  ==> Fatal error occurred, no output PDF file produced!


The definition of \robin is fine. But then it is redefined in terms of... \robin. So when TeX tries to expand \robin, it tries to expand \robin~Hood. So it starts by trying to expand \robin. Hence it tries to expand \robin~Hood~Hood and starts by trying to expand \robin and... ad infinitum. It cannot manage infinite loops, so it declares a fatal error when it runs out of capacity. You have to see its point.

infinite Robins

In this kind of case, you need to save the old definition first so you can use the old one in the definition of the new one:


one Robin Hood

That said, I think it unwise to redefine \in and I suspect that you are not using the best environment for the maths you are typesetting if you are tempted to redefine it in the way you describe. However, since your actual example doesn't show why you are so tempted, a bit more context would be needed to say anything further about this.

  • I'm actually writing something like a small book and in various places I spotted that $x\in [a,b]$ was seperated into two lines (which is too painful for my eyes) and I cannot deal with each one of them. I tried your recommendations, but then another problem immerged: ! Missing number, treated as zero.<to be read again>a $ x \in [a,b] as well as ! Illegal unit of measure (pt inserted).<to be read again>$ $ x \in [a,b]$ when typing [a,b] instead of c in my previews example. @Bernard – Jim Sep 18 '15 at 1:54
  • @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:

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.