[Tex/LaTex] Redefining asterisk (*) in math mode

charactersmath-modesymbols

I am attempting to use a symbol from a separate font for the centered asterisk (∗) math operator. The font in question only has the heightened (in many fonts) asterisk glyph (*), which I try to use for the centered variant by lowering it.

In math mode, the operator can be used both by * and \ast, who are defined in exactly the same way at lines 150 and 297 in fontmath.ltx.

\ast can be redefined with \renewcommand, but * seems to be another beast. Can it be changed into a macro, or in any other way change the baseline of the glyph?

\documentclass{minimal}

\DeclareSymbolFont{mymathoperators}{OT1}{phv}{m}{n}

\DeclareMathSymbol{\protoast}{\mathbin}{mymathoperators}{"2A}
\DeclareMathSymbol{*}{\mathbin}{mymathoperators}{"2A}

\renewcommand*{\ast}{\mathbin{\raisebox{-0.7ex}{\ensuremath{\protoast}}}}

\begin{document}

\( good \ast , bad * . \)

\end{document}

Best Answer

Using @egreg's \DeclareMathActive:

enter image description here

\documentclass{article}

\usepackage{amsmath}
\usepackage{etoolbox}

\DeclareSymbolFont{mymathoperators}{OT1}{phv}{m}{n}

\DeclareMathSymbol{\protoast}{\mathbin}{mymathoperators}{"2A}
\DeclareMathSymbol{*}{\mathbin}{mymathoperators}{"2A}

\renewcommand*{\ast}{\mathbin{\raisebox{-0.7ex}{\ensuremath{\protoast}}}}

\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{*}{\ast}

\begin{document}

\(good \ast , bad * . \)

\end{document}
Related Question