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.]