0

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}

  • Since * is not a letter, it cannot be used directly in a control word; here, a control word is a backslash followed by one or more letters. What you need to do is to make * "active", to use some TeX jargon, and then to assign * a certain meaning, e.g., to make it equivalent to {\ast}. – Mico Feb 12 '18 at 11:28
2

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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.