# get width and height of character in the power

I want to create a "minus-sign" in a superscript of a letter in math mode using \rule{width}{height} to get control over the look of it. In principle, I get something to my liking, but I fail to make the width and height adjust to when I use it in the power of an expression.

I tried:

\newlength{\charheight}
\newlength{\charwidth}
\newcommand{\supmin}[1]{%
\settoheight{\charheight}{#1}
\settowidth{\charwidth}{#1}
#1^{\rule{\charwidth}{\charheight}}
}


and

\newcommand{\supmin}[1]{%
#1^{\rule{1ex}{1em}}
}


both failed to adjust the box in the superscript when used in the power:

\documentclass[12pt,a4paper]{article}
\usepackage{amsmath, amssymb, amsthm}

\begin{document}
\begin{align}
k \binom{N}{k} - \supmin{k} p^{\supmin{k}} > 0
\end{align}
\end{document}


To my eye, these boxes have the same size.

• They have the same size because \settoheight{...}{k} and \settowidth{...}{k} effectively measure how large a k would be in the main text. They do not take into account the fact that you are using them in math mode (or in a superscript). You could measure e.g. the height of a script style k with \settoheight{...}{$\scriptstyle k$}. – Circumscribe Nov 4 '18 at 13:01
• (In egreg's answer, \mathpalette is used to automatically insert \displaystyle, \textstyle, \scriptstyle or \scriptscriptstyle (whichever is appropriate) as #1 to \sup@min (and the original argument as #2).) – Circumscribe Nov 4 '18 at 13:02

This is a job for \mathpalette:

\documentclass[12pt,a4paper]{article}
\usepackage{amsmath}

\makeatletter
\newcommand{\supmin}[1]{{\mathpalette\sup@min{#1}}}
\newcommand{\sup@min}[2]{%
\begingroup % <- important
\sbox\z@{$\m@th#1#2$}%
#2^{\rule{\wd\z@}{\ht\z@}}%
\endgroup
}
\makeatother

\begin{document}
\begin{align}
k \binom{N}{k} - \supmin{k} p^{\supmin{k}} > 0
\end{align}
\end{document}


• Nice, doing a bit of scaling and using offset gave me the desired result: \rule[0.3\ht\z@]{0.8\wd\z@}{0.03\ht\z@} – user3820991 Nov 4 '18 at 14:25