1

I find the asterisk of kpfonts too small when used in super/subscripts so, following answers here and here, I'm using @egreg's brilliant \DeclareMathActive to redefine * in math mode as \textstyle\ast:

\documentclass{article}
\usepackage{kpfonts,etoolbox}

\makeatletter \newcommand{\DeclareMathActive}[2]{% % #1 is the character, #2 is the definition \expandafter\edef\csname keep@#1@code\endcsname{\mathchar\the\mathcode#1 } \begingroup\lccode~=#1\relax \lowercase{\endgroup\def~}{#2}% \AtBeginDocument{\mathcode#1="8000 }% }

\newcommand{\std}[1]{\csname keep@#1@code\endcsname} \patchcmd{\newmcodes@}{\mathcode\-\relax}{\std@minuscode\relax}{}{\ddt} \AtBeginDocument{\edef\std@minuscode{\the\mathcode-}} \makeatother

\DeclareMathActive{*}{{\textstyle\ast}}

\begin{document} $f_\mathscr{F} \quad f^\mathscr{F} \quad R^*$

$A*B$ \end{document}

This works wonderfully, except that in order to make R^* work without bracing the * (as in R^{*}), I have to add braces around \textstyle\ast. This then removes the \mathbin spacing in expressions like A*B.

Is there any hack to \DeclareMathActive that would allow for both unbraced * in super/subscripts and correct spacing in A*B? One idea is to extend DeclareMathActive to take arguments like \mathchoice:

\DeclareMathActiveChoice{<char>}{<display code>}{<text code>}{<script code>}{<scriptscript code>}

Then one could use \DeclareMathActiveChoice{*}{\ast}{\ast}{{\textstyle\ast}}{\ast}.

However I have no idea how to implement such an extension.


Just for context, here's why I want to do this at all. Compare

ast-sizes

And for a professionally typeset comparison, here's the same line in Hartshorne's Algebraic Geometry:

Hartshorne

mbert
  • 4,171

1 Answers1

1

You could make ^ and _ grab arguments like a macro, which would mean x^\frac{1}{2} would no longer work, it would need x^{\frac{1}{2}} but that is no great loss.

enter image description here

\documentclass{article}
\usepackage{kpfonts,etoolbox}

\makeatletter \newcommand{\DeclareMathActive}[2]{% % #1 is the character, #2 is the definition \expandafter\edef\csname keep@#1@code\endcsname{\mathchar\the\mathcode#1 } \begingroup\lccode~=#1\relax \lowercase{\endgroup\def~}{#2}% \AtBeginDocument{\mathcode#1="8000 }% }

\newcommand{\std}[1]{\csname keep@#1@code\endcsname} \patchcmd{\newmcodes@}{\mathcode\-\relax}{\std@minuscode\relax}{}{\ddt} \AtBeginDocument{\edef\std@minuscode{\the\mathcode-}} @makeother^ @makeother_ \makeatother

\DeclareMathActive{*}{\mathbin{\textstyle\ast}} \DeclareMathActive{^}{\foosup} \DeclareMathActive{_}{\foosub} \def\foosup#1{\sp{#1}} \def\foosub#1{\sb{#1}}

\begin{document} $f_\mathscr{F} \quad f^\mathscr{F} \quad R^*$

$A*B$ \end{document}

David Carlisle
  • 757,742