text text text text text n-To get this right, try inserting this snippet in your document's preamble:
dimensional
\usepackage{amsmath} \renewcommand{\ndimensional}[1]{#1\nobreakdash\discretionary{-}{-}{-}\hspace{0pt}dimensional}Then, replace "n-dimensional" in the document with the following:
\ndimensional{n}or, to get the math environment look to the "n", do this:
\ndimensional{$n$}
What's going on in the snippet?
The #1 refers to whatever you added as a parameter to the command, which in the example above is "n".
The \nobreakdash needs to be combined with a dash character. That means that in other situations you may just need to do this:
\renewcommand{\ndimensional}[1]{#1\nobreakdash-\hspace{0pt}dimensional}While the output will be fine for many use cases, the previous snippet with the \discretionary command is a more general-case solution. (See this forum post for more info.)
The \hspace{0pt} tells LaTex not to allow any space (including a newline) between the previous character and the one that follows, acting like glue between the dash added with the \discretionary command and the "d" of dimensional. Without it, you'll get output like this:
text text text text text n-
-dimensional
Edit: Turns out you need the amsmath package for LaTeX to know what the \nobreakdash command is. I've added the necessary command.