数学模式中的连字符

数学模式中的连字符

每当我在里面写一个带连字符的单词\mathit\mathbf或其他什么的时候......

\mathit{long-variable-name}

... 我总是连字符应为连字符,而不是减号。有一个网页提供了几种解决方法(http://www.logic.at/staff/salzer/etc/mhyphen/),但我想要一个合适的解决方案,这样我就不必写出像这样的怪物

\mathit{long\mhyphen{}variable\myhyphen{}name}

我的想法是重新定义该\mathit命令(及其同类命令),以便当它-出现在其参数中时,会自动替换为产生连字符所需的任何命令。

  • 这可能吗?

  • 这样做会不会带来问题?我的意思是,人们有没有把整个公式里面\mathit?(因为这样你想要-产生减号。

答案1

您可以使用\newmcodes@from amsopn,它用于\operatorname。我不会重新定义\mathit和类似的命令。

\documentclass{article}
\usepackage{amsmath} % actually amsopn

\makeatletter
\DeclareRobustCommand{\varname}[1]{\begingroup\newmcodes@\mathit{#1}\endgroup}
\makeatother

\begin{document}
$\varname{long-variable-name}-\varname{short}=0$
\end{document}

在此处输入图片描述

可以改变的含义\mathit,但我强烈建议你不要:

\usepackage{letltxmacro,amsmath}

\LetLtxMacro\ORImathit\mathit
\makeatletter
\DeclareRobustCommand{\mathit}{%
  \begingroup\newmcodes@\ORImathit{#1}\endgroup
}
\makeatother

答案2

数学模式中所有字符的排版都取决于\mathcode该字符的 。您可以简单地重新设置 的数学代码-

\let\mathitori=\mathit
\def\mathit#1{{\mathcode`-=`- \mathitori{#1}}}

相关内容