如何修改\relbar?

如何修改\relbar?

我想排版\rightharpoonup带头的矢量。我发现最理想的解决方案是这个答案-,当正文较长时,作者使用它来填充上划线。

-但是,我现在使用的是 math time professional 2,由于它的加号/减号看起来更大,我借用了重新定义了减号txfonts。代码如下:

\DeclareSymbolFont{vvsymbols}{OMS}{txsy}{m}{n}
\SetSymbolFont{vvsymbols}{bold}{OMS}{txsy}{bb}{n}
\DeclareMathSymbol{-}{\mathbin}{vvsymbols}{0}

然后,杠铃就分裂了。 在此处输入图片描述

我该如何解决这个问题?我应该重新定义命令吗\relbar?或者我应该暂时将命令指定-为该矢量命令中的原始命令?怎么做?

代码

\documentclass[12pt,a4paper,openany,fleqn]{book}
\usepackage[margin=2cm, top=2cm]{geometry}
\usepackage{amsmath}
\usepackage[subscriptcorrection,nofontinfo,zswash,mtphrb]{mtpro2} %this could be commented
\parindent=0pt
\makeatletter
\newcommand*\MY@leftharpoonupfill@{%
    \arrowfill@\leftharpoonup\relbar\relbar
}
\newcommand*\MY@rightharpoonupfill@{%
    \arrowfill@\relbar\relbar\rightharpoonup
}
% These are not needed, for now:
% \newcommand*\MY@leftharpoondownfill@{%
%   \arrowfill@\lefttharpoondown\relbar\relbar
% }
% \newcommand*\MY@rightharpoondownfill@{%
%   \arrowfill@\relbar\relbar\rightharpoondown
% }
\newcommand*\overleftharpoon{%
    \mathpalette{\overarrow@\MY@leftharpoonupfill@}%
}
\newcommand*\overrightharpoon{%
    \mathpalette{\overarrow@\MY@rightharpoonupfill@}%
}

% Support for smaller size arrows:
\newcommand*\@dblsty@mathpalette[2]{%
    % Works like "\mathpalette", but macro passed in #1 must take
    % (at least) three arguments, of which the first _two_ are
    % style selections.
    \mathchoice
    {#1\displaystyle       \scriptstyle       {#2}}%
    {#1\textstyle          \scriptstyle       {#2}}%
    {#1\scriptstyle        \scriptscriptstyle {#2}}%
    {#1\scriptscriptstyle  \scriptscriptstyle {#2}}%
}
\newcommand*\@dblsty@overarrow@[4]{%
    % #1 := stretchable covering arrow
    % #2 := base style
    % #3 := style for covering arrow
    % #4 := base symbol
    \vbox{\ialign{##\crcr
            #1#3\crcr
            \noalign{\nointerlineskip}%
            $\m@th\hfil #2#4\hfil$\crcr
    }}%
}
\newcommand*\smalloverleftharpoon{%
    \@dblsty@mathpalette{\@dblsty@overarrow@\MY@leftharpoonupfill@}%
}
\newcommand*\smalloverrightharpoon{%
    \@dblsty@mathpalette{\@dblsty@overarrow@\MY@rightharpoonupfill@}%
}
\newcommand*\myvec{%
    \@dblsty@mathpalette{\@dblsty@overarrow@\MY@leftharpoonupfill@}%
}

\makeatother
\DeclareSymbolFont{vvsymbols}{OMS}{txsy}{m}{n}
\SetSymbolFont{vvsymbols}{bold}{OMS}{txsy}{bb}{n}
\DeclareMathSymbol{-}{\mathbin}{vvsymbols}{0}
\begin{document}
$1+1=2=3-1$ (You can see the minus sign became smaller.)\\
$\overrightharpoon{AB}:=\overrightharpoon{\textit{counter}}$
\end{document}

答案1

这是因为amsmath包装上写着

\AtBeginDocument{%
  \mathchardef\std@minus\mathcode`\-\relax
  \mathchardef\std@equal\mathcode`\=\relax
}

这会导致\std@minus重置为新值 ( \mathchar "2400"),该值指向文档开头的新字体中的减号。只需取消此设置即可\mathchar "2200恢复原始值。这可以按如下方式完成:

\@ifdefinable\ORG@std@minus{\let\ORG@std@minus\std@minus}
\DeclareSymbolFont{vvsymbols}{OMS}{txsy}{m}{n}
\SetSymbolFont{vvsymbols}{bold}{OMS}{txsy}{bb}{n}
\DeclareMathSymbol{-}{\mathbin}{vvsymbols}{0}
\AtBeginDocument{\let\std@minus\ORG@std@minus}

这是一个完整的、可编译的示例:

\documentclass[12pt,a4paper,openany,fleqn]{book}
\usepackage[T1]{fontenc}
\usepackage[margin=2cm, top=2cm]{geometry}
\usepackage{amsmath}

\parindent=0pt

\makeatletter

\newcommand*\MY@leftharpoonupfill@{%
    \arrowfill@\leftharpoonup\relbar\relbar
}
\newcommand*\MY@rightharpoonupfill@{%
    \arrowfill@\relbar\relbar\rightharpoonup
}
% These are not needed, for now:
% \newcommand*\MY@leftharpoondownfill@{%
%   \arrowfill@\lefttharpoondown\relbar\relbar
% }
% \newcommand*\MY@rightharpoondownfill@{%
%   \arrowfill@\relbar\relbar\rightharpoondown
% }
\newcommand*\overleftharpoon{%
    \mathpalette{\overarrow@\MY@leftharpoonupfill@}%
}
\newcommand*\overrightharpoon{%
    \mathpalette{\overarrow@\MY@rightharpoonupfill@}%
}

% Support for smaller size arrows:
\newcommand*\@dblsty@mathpalette[2]{%
    % Works like "\mathpalette", but macro passed in #1 must take
    % (at least) three arguments, of which the first _two_ are
    % style selections.
    \mathchoice
    {#1\displaystyle       \scriptstyle       {#2}}%
    {#1\textstyle          \scriptstyle       {#2}}%
    {#1\scriptstyle        \scriptscriptstyle {#2}}%
    {#1\scriptscriptstyle  \scriptscriptstyle {#2}}%
}
\newcommand*\@dblsty@overarrow@[4]{%
    % #1 := stretchable covering arrow
    % #2 := base style
    % #3 := style for covering arrow
    % #4 := base symbol
    \vbox{\ialign{##\crcr
            #1#3\crcr
            \noalign{\nointerlineskip}%
            $\m@th\hfil #2#4\hfil$\crcr
    }}%
}
\newcommand*\smalloverleftharpoon{%
    \@dblsty@mathpalette{\@dblsty@overarrow@\MY@leftharpoonupfill@}%
}
\newcommand*\smalloverrightharpoon{%
    \@dblsty@mathpalette{\@dblsty@overarrow@\MY@rightharpoonupfill@}%
}
\newcommand*\myvec{%
    \@dblsty@mathpalette{\@dblsty@overarrow@\MY@leftharpoonupfill@}%
}

\@ifdefinable\ORG@std@minus{\let\ORG@std@minus\std@minus}
\DeclareSymbolFont{vvsymbols}{OMS}{txsy}{m}{n}
\SetSymbolFont{vvsymbols}{bold}{OMS}{txsy}{bb}{n}
\DeclareMathSymbol{-}{\mathbin}{vvsymbols}{0}
\AtBeginDocument{\let\std@minus\ORG@std@minus}

\makeatother



\begin{document}

$1+1=2=3-1$ (You can see the minus sign became smaller.)\\
Yet the harpoons come out right:
$\overrightharpoon{AB}:=\overrightharpoon{\textit{counter}}$

\end{document}

你可以自己检查输出是否是你要求的:

代码输出

请注意这个答案假设,由于某些我无法理解的原因,您只想替换减号,但不想切换到一组新的数学字体。

相关内容