TeX only breaks inline formulas at binary or relational symbols and these do not occur in you chemical stuff, so the whole part
is a single unbreakable unit.
It doesn't help that you mix math and text here because that doesn't create breakpoints either.
- there are no spaces
- hyphenation of words is only done (by default) for words of length 5 (3+2) and anyway probably not wanted
- hyphenation is also not done if the word is directly followed or preceded by something like math (without a space).
Line breaking is also restricted by
\tolerance which tells TeX how "bad" a line is allowed to get. That is by default quite restricted with the idea that you look and fix bad breaks manually. Default values is 200, if stretching out the spacing more than that TeX will not consider that as a possible solution.
So your options are
- fix bad lines manually when they happen (by adding
\allowbreak in suitable places)
\tolerance to give TeX more options without manual intervention (depending on what level of bad solutions you are allowing, but always stay below 10000!)
- or both in combination
- or use
\sloppy which should make LaTeX linebreak basically always, but than it can be very sloppy, hence the name.
In your particular example, what you need is
\tolerance=1000 (in fact 722) and you get this:
which is not great, but ... (you get the same with
\sloppyin this case as TeX will not choose worse solution just because it is allowed to, but in other cases it might, so take your pick) ... if you care about good typography than 1000 is already pretty bad --- I would only accept it in an emergency, but you might think differently.
I don't speak chem, so I have no idea is, for example a break after the commas in the formula would be generally acceptable, but if they are or if they usually are, then a simple solution is to do something like this (choose your own command name as you like)
and replace the commas where a break is allowed with that. You can choose a higher or a lower number as the penalty depending on how much you prefer to avoid a break.
This gives you then:
without manual intervention (after a simple or not so simple query replace of relevant commas).
It a break should happen only before the
( a similar strategy could be used.
You could even go further and make , or ( active in math and expand to such a definition but I would probably advice against that as it can be fairly fragile if not done correctly.