# How can I prevent insufficient spacing between a letter with a bar and a calligraphic letter in superscript

When using a bar over a letter in math mode and then having certain calligraphic letters in superscript, the letters overlap with the bar or are at least very close to the letter with the bar. This looks somewhat ugly.

Example:

\documentclass{article}

\begin{document}
$$\bar{d}^{\mathcal{H}}_{hewt}$$
$$\bar{d}^{\mathcal{C}}_{hewt}$$
\end{document}


I am using this notation throughout my document. While I realize that I could add a small space using \,, I would prefer not having to alter this everywhere. Is there a solution which changes the space for all calligraphic superscript letters?

• There are solutions, but the simpler one is to make macros. What does \mathcal{H} or \mathcal{C} stand for? Are they used in other places other than superscripts? As an example if \bar{d}^{\mathcal{H}} is a common occurrence, you could define \def\dH#1{\bar{d}^{\,\mathcal{H}}_{\mathrm{#1}}} and then use \dH{hewt}. Also what does hewt stand for? May be you should write it upright? – Manuel Apr 6 '18 at 9:20

## 3 Answers

This assumes that calligraphic letters, when used in superscripts (or subscripts) are at the beginning of the superscript.

I insert two glob of glue that, in text or display style, cancel each other; in script style, \nonscript nullifies the first negative spacing, leaving only the positive one. The \calsym command has two arguments, the first one used for fine tuning the spacing.

From the example it seems better to add the kern also when the base letter doesn't wear an accent.

\documentclass{article}
\usepackage{amsmath} % recommended

\newcommand{\calsym}[2]{\nonscript\mspace{-#1mu}\mspace{#1mu}\mathcal{#2}}
\newcommand{\cC}{\calsym{2}{C}}
\newcommand{\cH}{\calsym{3}{H}}

\begin{document}

\begin{gather}
\bar{d}^{\cH}_{\mathrm{hewt}}+d^{\cH}
\\
\bar{d}^{\mathcal{H}}_{\mathrm{hewt}}+d^{\mathcal{H}}
\\
\bar{d}^{\cC}_{\mathrm{hewt}}+d^{\cC}
\\
\bar{d}^{\mathcal{C}}_{\mathrm{hewt}}+d^{\mathcal{C}}
\\
a\cH\cC
\\
a\mathcal{H}\mathcal{C}% for checking
\end{gather}

\end{document}


Just an idea ---in case you haven't think about it--- is to define a command:

\documentclass{article}

\newcommand\mybar[3][\empty]{\bar{#2}^{\,\mathcal{#3}}\ifx#1\empty\relax\else_{#1}\fi}

\begin{document}
$$\bar{d}^{\mathcal{H}}_{hewt}$$
$$\bar{d}^{\mathcal{C}}_{hewt}$$
$$\mybar[newt]{d}{H}=1$$
$$\mybar[newt]{d}{C}=1$$
$$\mybar{d}{J}=1$$
\end{document}


I used the subscript as an optional first argument, but you can use just the idea the way you like:

This is an ugly hack, and I won't recommend it in general. But if it works in your document without unwanted side effects, it's an easy way to get what you want:

\documentclass{article}
\usepackage{etoolbox}
\pretocmd{\mathcal}{\mathchoice{}{}{\,}{\,}}{}{}
\begin{document}
$$\bar{d}^{\mathcal{H}}_{hewt}$$
$$\bar{d}^{\mathcal{C}}_{hewt}$$
\end{document}


Likely unwanted side effects: It applies in subscripts as well as superscripts. And in the numerators and denominators of text style fractions. And in superscripts where the calligraphic letter is not the first symbol. That's a lot of potential problems!