8

I want to typeset vectors with \rightharpoonup heads. I found that the most ideal solution is this answer, where the author uses - to fill the overline when the body is lengthy.

However, I'm now using math time professional 2, and due to its bigger looking plus/minus sign, I had redefined the minus sign, -, borrowing from txfonts. The code is:

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

And then the bar became splits. enter image description here

How can I solve this? Should I redefine the command \relbar? Or should I temporarily specify the - to be the original one within that vector command? How to do that?

Code

\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}
2
  • 2
    Could you add a full MWE so we can easily reproduce the problem?
    – Georg
    May 28, 2017 at 12:19
  • OK, I'm now going to do this. :)
    – Eric
    May 28, 2017 at 12:22

1 Answer 1

10

It happens because the amsmath package says

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

and this causes \std@minus to be reset to the new value (\mathchar "2400"), that points to the minus sign in the new font, at the beginning of your document. It suffices to counteract this setting, so that the original value \mathchar "2200 is reinstated. This can be done as follows:

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

Here is a full, compilable example:

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

You can check by yourself that the output is what you asked for:

Output of the code

Please note that this answer assumes that, for some reason of yours, which I cannot understand, you want to replace only the minus sign, but without switching to a new set of math fonts.

2
  • It works! I use mtpro2 and extract + from newtxmath(where - from txfonts; I noted that newtxmath also uses txfont's -). My commands are these. I want the times-like math font to suit the text, so I first tried mtpro2. But the only unsuited thing is the bigger looking +,-, \times, etc. So I came up with extracting some binary operations from other times-like fonts, such as those mentioned.
    – Eric
    May 29, 2017 at 2:57
  • But extracting the symbols one at a time is cumbersome, so I had tried to require the whole sets in newtxmath. I tried to read the document of newtxmath, figuring out which symbol sets corresponding to which commands. However, I'm not good at LaTeX, so it is too difficult/advanced for me. I never succeed. As you said, how can I switch to a new set of math fonts?
    – Eric
    May 29, 2017 at 3:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .