Find optimal kerning for space between inline math and text

Here's an analysis of what happens:

\documentclass[10pt]{article}
\usepackage{tabularx}
\usepackage[table]{xcolor}

\setlength{\fboxrule}{0.1pt}
\setlength{\fboxsep}{-\fboxrule}

\begin{document}
$\mathrm{C}^*$-algebra

\fbox{$\mathrm{C}^*$}-algebra

\fbox{$\mathrm{C}^{\fbox{$\scriptstyle*$}}$}-algebra

\begin{tabular}{@{}ll}
\fbox{$\mathrm{C}^*$}\kern-.1ex-algebra &
$\mathrm{C}^*$\kern-.1ex-algebra \\
\fbox{$\mathrm{C}^*$}\kern-.15ex-algebra &
$\mathrm{C}^*$\kern-.15ex-algebra \\
\fbox{$\mathrm{C}^*$}\kern-.2ex-algebra &
$\mathrm{C}^*$\kern-.2ex-algebra \\
\fbox{$\mathrm{C}^*$}\kern-.25ex-algebra &
$\mathrm{C}^*$\kern-.25ex-algebra \\
\fbox{$\mathrm{C}^*$}\kern-.3ex-algebra &
$\mathrm{C}^*$\kern-.3ex-algebra \\
\end{tabular}
\end{document}

enter image description here

The first three rows show the normal typesetting, which I don't find really bad, but it's subjective. The following rows show the same with increasing amount of (negative) kerning; on the left you can see the relation of the hyphen with the bounding box of “C*”. When you have decided the right amount, do

\newcommand{\csalg}{$\mathrm{C}^*$\kern-.1ex-algebra}

and type \csalg{} when you want to use the term. Choose the name you prefer, of course. It's probably worthy defining it even if you eventually decide for no kerning.


This answer presents two other ideas:

Protruding value of package microtype

The TeX engine pdfteX supports a feature "character protrusion". Certain characters (e.g. -, ., ,) are allowed to move into the margins. This can improve the visual smoothness of the margins.

Macro \leftprotrude grabs the next character and looks at its value for the protrusion into the left margin. \lpcode<font><character slot> expands to an integer number, the unit is a per mill of 1em.

Package microtype enables character protrusion and configures some values for the protrusion (they are font-dependent).

Vertical position of the star

For fun, the example also shows some alternatives:

  • Text mode: \textsuperscript{*}
  • Math mode: star set as limit of an operator (\mathop).

Example

\documentclass{article}

\usepackage{microtype}
\newcommand*{\leftprotrude}[1]{%
  \begingroup
    \leavevmode
    \kern-.001\dimexpr\numexpr(\lpcode\font`#1)em\relax
  \endgroup
  #1%
}

\newcommand*{\CalgA}[1]{%
  \mbox{$\mathrm{C}^{*}$#1-algebra}%
}
\newcommand*{\CalgB}[1]{%
  \mbox{$\mathop{\mathrm{C}}\nolimits^{*}$#1-algebra}%
}
\newcommand*{\CalgC}[1]{%
  \mbox{C\textsuperscript{*}#1-algebra}%
}

\begin{document}
\begin{tabular}{l@{}|l@{}|l@{}|l}
  \CalgA{} & \CalgB{} & \CalgC{} & \small(unmodified) \\
  \CalgA{\leftprotrude} & \CalgB{\leftprotrude} & \CalgC{\leftprotrude}
    & \small\verb|\leftprotrude| \\
  \CalgA{\negthinspace} & \CalgB{\negthinspace} & \CalgC{\negthinspace}
    & \small\verb|\negthinspace| \\
\end{tabular}
\end{document}

Result

Tags:

Kerning