Spacing in "$d=2$-dimensional"
Building on @Mico's code, with the help of xparse
, I propose a \Diml
command, in which the spacing around the = sign is tighter, and the argument is input in a more natural way, as d = some value. It is of course easy to adjust the spacing to your taste.
\documentclass{article}
\usepackage{amsmath} %
\usepackage{xparse}
\newcommand{\Diml}[1]{\dimlargs{#1}}
\NewDocumentCommand{\dimlargs}{>{\SplitArgument{1}{=}}m}
{\dimlargsaux#1}
\NewDocumentCommand{\dimlargsaux}{mm}{%
\text{$ #1\mkern2mu{=}\mkern2mu#2 $\nobreakdash-dimensional}}%
\begin{document}
$\Diml{d=1},\;\Diml{e = n }$
\end{document}
Assuming you've loaded the amsmath
package, I would make use of its \nobreakdash
directive to make sure there's never a line break between 2-
and dimensional
.
\documentclass{article}
\usepackage{amsmath} % for \nobreakdash and \text macros
%% Define a macro that takes an optional argument;
%% default value of optional argument is '2'.
\newcommand\diml[1][2]{\text{$#1$\nobreakdash-dimensional}}
\begin{document}
$d=\diml$, $d=\diml[3]$, $d=\diml[n]$
\end{document}