How can I redefine the minus sign to be of the same width as plus?

The situation

In the standard Computer Modern (and also in Latin Modern) the math-mode minus and plus symbols are, in some font sizes, not of the same width. This causes slight misalignments in formulas. I would like to redefine the math-mode - to have the same width as +, in any font size.

The example

\documentclass[12pt]{standalone}%
%
\begin{document}%
\newlength{\test}%
\begin{tabular}{rll}%
textstyle & \fbox{$-$} & \settowidth{\test}{$-$}\the\test\\
textstyle & \fbox{$+$} & \settowidth{\test}{$+$}\the\test\\
scriptstyle & \fbox{$\scriptstyle-$} & \settowidth{\test}{$\scriptstyle-$}\the\test\\
scriptstyle & \fbox{$\scriptstyle+$} & \settowidth{\test}{$\scriptstyle+$}\the\test\\
scriptscriptstyle & \fbox{$\scriptscriptstyle-$} & \settowidth{\test}{$\scriptscriptstyle-$}\the\test\\
scriptscriptstyle & \fbox{$\scriptscriptstyle+$} & \settowidth{\test}{$\scriptscriptstyle+$}\the\test\\
\end{tabular}%
\end{document}%


This shows that the minus is wider than the plus in both 12pt and 6pt math fonts, but has the same width in 8pt.

The solution?

I'll post one below, but I am not happy with it.

• i'm not surprised that the 12pt plus and minus have different widths, because the plus is in cmr12, which has a slightly narrowed aspect ratio, and the minus is scaled from cmsy10, since cmsy12 doesn't exist. but i am surprised that the 6pt widths are different, since both cmr6 and cmsy6 were among the "original 75" fonts defined with metafont. i will investigate further when time permits. – barbara beeton Apr 10 '17 at 21:19
• \mathrlap{+}\phantom{-} ? – John Kormylo Apr 11 '17 at 3:12
• 1. John, this is worse than my solution (see below), because it does not even bother to center the plus in the width of the minus. 2. Anyway, defining a symbol that is a minus with the width of a plus is not that hard (again, see below), but I don't like the drawbacks of redefining the minus character. Does anyone know whether it is instead possible to automatically modify the font files such that the width of the minus is changed, without redefining the minus character in latex? – wea0 Apr 18 '17 at 10:57
• So, am I stuck with either having a - which does not possess the same width as +, or having a - that does not work in superscripts? Is there any way to define a new command which exhibits \mathbin spacing and simultaneously works when used as a superscript without having to be enclosed in parentheses? – wea0 Jul 29 '17 at 0:13

My attempt at a solution

\newlength{\widthplus}%
\newcommand{\minuspalette}[2]{\settowidth{\widthplus}{$#1+$}\mathbin{\makebox[\widthplus]{$#1#2$}}}%
\newcommand{\goodminus}{\mathpalette{\minuspalette}{\mathchar"2200}}% use \mathchar"2200 instead of - to avoid infinite recursion
{\catcode-13\gdef-{\goodminus}}% make - active temporarily, so that it can be redefined
\mathcode-"8000% make - active in math mode


I simply define a box that has the same width as a plus sign, but will be filled with a minus glyph. I do not shrink the symbol, only make its bounding box smaller. Via \mathpalette the definition is automatically correct for all math sizes. Then I make - active (but only temporarily), such that it can be redefined. And finally I make - permanently active in math-mode only (not to mess with text-mode hyphens), such that the new definition is used there.

What I don't like about it

Precisely because minus is now active in math-mode I can no longer use it as a single superscript or subscript, such as in $e^-$. It can now only be used if extra braces are put around the -. This is inconvenient and breaks many things in my existing project. Can anyone think of a solution which achieves the same effect as mine, but without this downside?

Note: I take a very different view of the original question in the following discussions and solutions. And, no, I do not like the idea of making + and/or - active in math mode for alignment purposes.

This problem exists not only for Computer Modern/Latin Modern, and not only for the pair + and -

With the default Computer Modern family (or the Latin Modern family), this width problem is barely visible to the human eyes. However, with other math fonts newtxmath, newpxmath or mtpro2, this problem is much more visible and it goes beyond just for + and -. The following MWE illustrates my point:

\documentclass{article}
\usepackage{mathtools}
% Latin Modern
%\usepackage{lmodern}
% newtxmath
\usepackage{newtxtext}
\usepackage{newtxmath}
% mtpro2
%\usepackage{newtxtext}
%\usepackage[lite]{mtpro2}
\begin{document}
Cases: $f(x) = \begin{cases} +1 & x>0 \\ -1 & x=0 \\ -1 & x\le0 \end{cases}$

Stacked subscripts: $\displaystyle \sum_{\substack{i=0 \\ i>0}}$
\end{document}


In the case of newtxmath, it’s rather clear that the equal sign = is narrower than the > sign, and, zooming in large enough, one will find out that the \le sign is slightly wider than >.

In the case of mtpro2, we observe different widths between + and -. And, this time, the = sign is wider than the other two relation symbols.

This problem is unpredictable and “by design”

We may now conclude that the width differences are by design; that is, the widths of these symbols are chose by the font designer(s). More importantly, the widths behave differently in unpredictable ways across different math font families and across different design/optical sizes. Clearly, any solutions that involve making +, -, = and so on active would be ineffective and dangerous.

When do we need mono-width symbols?

For most “one-liner” math equations, I don’t think mono-width symbols are needed. However, there is one occasion in which they are useful: When typing inside tabular-like environments, e.g., tables, arrays, cases, matrices, etc.

When inside such multi-lined tabular-like math equations, horizontal alignment within each column becomes crucial. But, it is impossible to foresee the aforementioned design flaws in different math font families.

How do we get mono-width symbols?

My solution is inspired by \phantomrel:

When you want to align a split equation with proper indentation, you can create something like

\newcommand*\phantomrel[1]{\mathrel{\phantom{#1}}}


Then, \phantomrel{=} will yield an invisible equal sign (with correct surrounding spaces) and produce the desired indentation.

Therefore, instead of making certain characters active and breaking many other things, I propose two specially designed commands:

\tabularrel{<arg>}


and

\tabularbin{<arg>}


The names are taken from “proportional versus tabular figures”. Each of the two commands essentially makes a box of fixed width according to some “standard symbol”, then it puts the actual symbol horizontally centered. Of course, \mathpalette is required to get the correct math sizes.

Here is a MWE:

\documentclass{article}
\usepackage{mathtools}
% Latin Modern
%\usepackage{lmodern}
% newtxmath
\usepackage{newtxtext}
\usepackage{newtxmath}
% mtpro2
%\usepackage{newtxtext}
%\usepackage[lite]{mtpro2}

% Standard relation and binary symbols
\newcommand*\standardrel{<}% Change this to =' for mtpro2
\newcommand*\standardbin{+}
% Tabular relation and binary symbols
\makeatletter
\newcommand*\tabularrel[1]{%
\mathrel{\mathpalette\tabular@rel{#1}}%
}
\def\tabular@rel#1#2{%
\makebox[\widthof{\ensuremath{{#1\standardrel}}}][c]{${#1#2}$}%
}
\newcommand*\tabularbin[1]{%
\mathbin{\mathpalette\tabular@bin{#1}}%
}
\def\tabular@bin#1#2{%
\makebox[\widthof{\ensuremath{{#1\standardbin}}}][c]{${#1#2}$}%
}
\makeatother

\begin{document}
Cases: $f(x) = \begin{cases} \tabularbin+1 & x\tabularrel>0 \\ \tabularbin-1 & x\tabularrel=0 \\ \tabularbin-1 & x\tabularrel\le0 \end{cases}$

Stacked subscripts: $\displaystyle \sum_{\substack{i\tabularrel=0 \\ i\tabularrel>0}}$
\end{document}
`

Voilà!!!

Of course, this method of aligning tabular-like math can be applied to any math fonts.