As suggested in, e.g., this question, I use non-breaking spaces in LaTeX to avoid some bad line breaks, e.g., "the dimension of~$X$"
However, in some cases, this leads to words being hyphenated in an unpleasant way. For instance, when writing "Let $E$ be a vector space of dimension~$d$", everything is usually fine, but sometimes LaTeX will decide to hyphenate "dimension". Yet I find the line break "of dimension / $d$" less jarring than the line break, e.g., "of dimen-/sion $d$".
I fix examples by hand when they occur, by removing the non-breaking space; but this is unpleasant because it needs to be added back whenever the text changes.
It seems to me like the correct solution would be to have an "almost-non-breaking space", i.e., I would like to be able to write "Let $E$ be a vector space of dimension#$d$" with some character or macro #, with the effect that the space should not be broken except if it would cause a hyphenation. Is there a reasonable way to achieve this?
[As TeX has a way to tweak the penalty associated with hyphenations (see, e.g., this answer), I would imagine that there ought to be a way to specify that a line break at one point should be possible but discouraged unless a word needs to be hyphenated... hence this question.]
Let $E$ be a vector space of \mbox{dimension}~$d$, but that, of course, makes appropriate hyphenation harder. In such cases,sloppyparis an option. – Steven B. Segletes Dec 22 '16 at 18:41#will cause undesired results which you'd want to change manually. Minute irritations like this should be left for end-of-document modifications before publication. – Werner Dec 22 '16 at 18:55dimension\penalty1000\ $d$. This means that the space is a viable breakpoint but breaking will cost a penalty of 1000. A penalty of 10000 would correspond to~. (My advice, don’t try to outsmart the system) – Henri Menke Dec 22 '16 at 19:10\newcommand{\nb}{\penalty100\ }, right? If yes, please feel free to post your comment as an answer! – a3nm Dec 22 '16 at 19:26