# scriptscriptstyle-sized prime, with relative scaling

My question is closely related to How do you get a scriptscriptstyle-sized prime? However, I don't know how to use the answer to that question to solve my problem.

In the first line of the sample output below, I'm using ' in various contexts which are presumably determining whether the rendered prime will be in subscriptstyle, scriptscriptstyle, etc. This works fine until I get to a certain level of nesting, at which point the prime doesn't get any smaller, as is the case with the fourth '. (I believe primes #2 and #3 are, and should be, the same size.) This behaviour is nicely explained by @egreg in the earlier question: basically ' is equivalent to ^{\prime}, so one gets a scriptscriptstyle prime in scriptstyle and the same inscriptscriptstyle.

What I would like is for prime #4 to be scaled accordingly, and the earlier question proposes a solution. However I'm not sure how to adapt that solution so that the scaling is automatic: I'd like to be able to use ' (or some suitable macro) uniformly in my definitions, and have the the resulting prime be rendered at the appropriate size, as determined by the context.

The second line of output shows what happens when I naively adopt the solution from the earlier question. The behaviour seems wrong: the first prime is too small, and prime #4 is still too big.

\documentclass{article}

\usepackage{amsmath}
\usepackage{scalerel}

\newcommand\scale{\vstretch{#1}{\hstretch{#1}{#2}}}
\newcommand\ssp{#1^{\scale{.6}{\scriptstyle\prime}}}

\begin{document}
$\ssp{a} \quad E^{\ssp{a}} \xrightarrow{\ssp{a} \quad E^{\ssp{a}}}$
$a' \quad E^{a'} \xrightarrow{a' \quad E^{a'}}$
\end{document}


How do I adapt the solution from the earlier question to give me relative scaling? I tried removing the explicit \scriptstyle from the definition of \ssp; then prime #4 looks right, but #2 and #3 look wrong.

• The prime is sized relative to the fonts used, if you do a^{a^{a^{a^{a}}}} The a get no smaller after subsubscript size, would you really want just the primes to get smaller? why? Apr 16, 2014 at 11:45
• Indeed, I want the primes to track the font size. But in this case, the fourth 'a' is smaller, but the fourth prime isn't, no?
– Roly
Apr 16, 2014 at 14:15

The \ssp definition in the cited answer, How do you get a scriptscriptstyle-sized prime?, was specifically for \scriptscriptstyle only. To adapt a macro (I kept the same name, but you can change it to suit) for all math styles, just use \mathchoice. In most math styles, it is just #1^\prime. Only in \scriptscriptstyle does the alternate definition kick in (I have also simplified the alternate definition slightly).

\documentclass{article}

\usepackage{amsmath}
\usepackage{graphicx}

\newcommand\ssp{\mathchoice{#1^\prime}{#1^\prime}{#1^\prime}%
{#1^{\scalebox{.7}{$\scriptscriptstyle\prime$}}}
}

\begin{document}
$\ssp{a} \quad E^{\ssp{a}} \xrightarrow{\ssp{a} \quad E^{\ssp{a}}}$
\end{document}
` 