Math & ScienceSpacing after the equal Sign

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Spacing after the equal Sign

Post by Cham »

I'm experiencing a small spacing "glitch" in all the equations, after the equal sign. See for example the MWE below :

Code: Select all

\documentclass[12pt]{article}
\usepackage{amsmath}

\begin{document}

This example (bad) :
	\begin{equation}
		y(x) = - x - x.
	\end{equation}
Or this one (good) :
	\begin{equation}
		y(x) = -\: x - x.
	\end{equation}
Or this one (bad) :
	\begin{equation}
		y(x) = -\ x - x.
	\end{equation}

\end{document}
The first term on the right side has a minus sign. See the spacing after it, just before the first x. The first equation is clearly wrong. The second version is my solution. The third equation is wrong (too much space after the first minus sign).

IMHO, the spacing after the first minus sign should be exactly as the second minus sign.

What should be the "right" spacing? What is the "right" command? Should I stay with -\:? The options -\, and -\; doesn't seem to be the right spacing.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Spacing after the equal Sign

Post by Stefan Kottwitz »

There's a a difference between an unary minus sign and a binary minus operator.

You could change it this way if you would prefer, inserting {}:

Code: Select all

y(x) = {} - x - x.
minus-sign.png
minus-sign.png (3.39 KiB) Viewed 19781 times
The equal sign = is a relation symbol, that's why the following minus would be treated as an unary symbol. {} is treated like an ordinary math symbol, now the minus stands between two ordinary math symbols and becomes binary. However, I would say it should be unary at this place, i.e. the normal behavior is correct: an unary sign is closer to the variable or number, that's also the case for the plus sign. I'm pretty sure in math documents it's used this way, it might be that your desired spacing is not what's commonly used.

Stefan
LaTeX.org admin
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Spacing after the equal Sign

Post by localghost »

Cham wrote:[…] What should be the "right" spacing? What is the "right" command? Should I stay with -\:? The options -\, and -\; doesn't seem to be the right spacing.
The first line is correct, all others are wrong. Hence the problem is non-existent. Everything else is perhaps a matter of personal taste.


Thorsten
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Spacing after the equal Sign

Post by Cham »

Ok. Now this is all clear. Thanks guys.

But then, what about this ? If it's the correct default behavior, I think it's pretty ugly :

Code: Select all

        \begin{equation}
                y(x) = - \frac{1}{2} \; x - x.
        \end{equation}
The minus sign is too close to the fraction bar. It's hard to read.

Also, adding "{}" after the equal sign add too much space after it. It feels unbalanced. The only solution I see is using "\:" after the minus sign.

EDIT : By the way, the new "OPEN IN WRITELATEX" feature is very nice ! Very usefull ! :)
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Spacing after the equal Sign

Post by Stefan Kottwitz »

I still don't see a problem with the default horizontal spacing:
spacing.png
spacing.png (4.27 KiB) Viewed 19770 times
It's pretty normal: around binary operators the spacing is wider, for example to better separate summand terms, while a minus sign for a negative number stronger belongs to the number. This spacing supports the reading in a way that the reader notices stronger bindings (sign, factor) compared to less strong bindings (plus, minus). It's consistently done, so perhaps in such a case of a fraction dash you don't like it - well, fine-tuning is up to you if you like it. Or which general rule would you implement?

Stefan
LaTeX.org admin
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Spacing after the equal Sign

Post by Cham »

Stefan_K wrote:Or which general rule would you implement?
I prefer a full democracy of all signs, since the order of terms in an equation is very often arbitrary. All signs should be treated on the same footing.

Usually, an equation in physics doesn't show any number. We only have symbols.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Spacing after the equal Sign

Post by Stefan Kottwitz »

After a closer look, I guess there is no skip inserted between a minus sign and the number, variable or fraction.
Cham wrote:I prefer a full democracy of all signs, since the order of terms in an equation is very often arbitrary. All signs should be treated on the same footing.
Three lenghts are used for the spacing. You could set two or all threee to be equal, such as by

Code: Select all

\thinmuskip=\thickmuskip
\medmuskip=\thickmuskip
However, occasionally using \> (med), \, (thin) or \; (thick) may be ok for finetuning.

Stefan
LaTeX.org admin
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Spacing after the equal Sign

Post by Cham »

Is the \> command (tab, in mathmode ?) the same spacing as \: ?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Spacing after the equal Sign

Post by Stefan Kottwitz »

Default, yes, in the sources I see

Code: Select all

\let\:=\>
and source2e says it's a "Nickname for the medium space since \> is not available inside tabbing".

However, amsmath changes something. If I use \show to verify it, it shows a difference after loading amsmath:
  • \> is \mskip\medmuskip
  • \: is \tmspace+\medmuskip{.2222em}
So better keep using \: with amsmath for consistency and because they usually know how to improve math typesetting.

Stefan
LaTeX.org admin
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Spacing after the equal Sign

Post by Cham »

Thanks for the explanation Stefan, very usefull, as usual.

So I'll stay with \: after the plus or minus sign.
Post Reply