在數學模式下重新定義星號 (*)

在數學模式下重新定義星號 (*)

我嘗試使用單獨字體中的符號作為居中星號 (*) 數學運算子。有問題的字體只有加高的(在許多字體中)星號字形 (*),我嘗試透過降低它來將其用於居中變體。

*在數學模式下,運算子和都可以使用\ast,它們在 中的第 150 行和 297 行以完全相同的方式定義fontmath.ltx

\ast可以用 重新定義\renewcommand,但*似乎是另一個野獸。可以將其更改為宏,或以任何其他方式更改字形的基線嗎?

\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}

答案1

使用@egreg的\DeclareMathActive:

在此輸入影像描述

\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}

相關內容