LaTeX Breaking Spaces, Non-Breaking Spaces, and Math Spacing Commands
In LaTeX, I always use a space character to add a blank space between the text, and sometimes commands \ , \quad, and \qquad to add some spacing between contents in math environments. Technically, all of them are breaking spaces1:

which means that LaTeX can make a new line there if needed. In addition to them, there are some non-breaking spaces (sometimes called ties), where making a new line is not allowable, such as: \thinspace (\,), \negthinspace (\!, a kind of negative distance), \enspace, and \nobreakspace (~, which is the most classic tie):

Then, let’s test these commands one by one:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
\documentclass[12pt]{article}
\usepackage{forloop}
\usepackage{showframe}
\usepackage{xcolor}
\newcounter{x}
\newcommand{\helpertestblank}[1]{%
\forloop{x}{0}{\value{x} < 30}{123#1}%
}
\begin{document}
\thispagestyle{empty}
% =====Breaking spaces====
\noindent{\color{red}\verb*| |}
\helpertestblank{ }
\noindent {\color{red}\verb*|\quad|}
\helpertestblank{\quad}
\noindent {\color{red}\verb*|\qquad|}
\helpertestblank{\qquad}
\noindent {\color{red} \verb*|\enskip|}
\helpertestblank{\enskip}
\noindent {\color{red}\verb*|\ |}
\helpertestblank{\ }
% ========================
% =====Non-breaking spaces====
\noindent {\color{red}\verb*|\thinspace|}
\helpertestblank{\thinspace}
\noindent {\color{red}\verb*|\,|}
\helpertestblank{\,}
\noindent {\color{red}\verb*|\negthinspace|}
\helpertestblank{\negthinspace}
\noindent {\color{red}\verb*|\!|}
\helpertestblank{\!}
\noindent {\color{red}\verb*|\enspace|}
\helpertestblank{\enspace}
\noindent {\color{red}\verb*|\nobreakspace|}
\helpertestblank{\nobreakspace}
\noindent {\color{red}\verb*|~|}
\helpertestblank{~}
% ========================
\end{document}

Above non-breaking spaces are useful in some cases, improving our writing details and making article look more professional, such as1:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
\documentclass{article}
\usepackage{amsmath}
\begin{document}
Question~1
Donald~E. Knuth % In the first name and middle initial
Mr.~Knuth
function~$f(x)$
1,~2, and~3
\end{document}

And among which, command \! can be used to generate a negative distance, and is frequently used in math environments, here are some examples1:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
\documentclass{article}
\usepackage{amsmath}
\DeclareMathOperator\dif{d\!} % For differential symbols
\begin{document}
\renewcommand{\arraystretch}{2}
\begin{tabular}{ll}
With adjustment by \verb*|\!| & Without adjustment\\
$ \int_0^1 f(t) \dif t
= \iint_D g(x,y) \dif x \dif y $ & $ \int_0^1 f(t) \dif t
= \iint_D g(x,y) \mathrm{d} x \mathrm{d} y $\\
$ x^2 \! / 2 $ & $ x^2 / 2 $\\
$ |\!{\gets} 5 {\to}\!| $ & $| {\gets} 5 {\to}|$\\
$ A^{\!T} $ & $ A^T $
\end{tabular}
\end{document}

Honestly, I totally didn’t notice these details before!!!
In above cases, note how we type a differential symbol:
1
2
3
4
5
\usepackage{amsmath}
\DeclareMathOperator\dif{d\!} % For differential symbols
% ...
$ \int_0^1 f(t) \dif t
= \iint_D g(x,y) \dif x \dif y $
A modified \dif command is declared in the preamble, which preserves the spacing before the differential symbol and simultaneously shrink the spacing after that1. It’s much more elegant than the way \mathrm{d} I always used before!!!
Besides, there are also three spacing commands that can be used in math environments, i.e., \:, \>, and \;1:

such as:
1
2
3
4
5
6
7
8
9
10
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
aa\:a\>a\;a
\]
\end{document}

In addition, we can use \setlength command to specify the spacing value of above math spacing commands1:
\thinmuskipfor thin-space command\,and\!(default3mu)\medmuskipfor medium-space command\:and\>(default4mu plus 2mu minus 4mu)\thickmuskipfor thick-space command\;(default5mu plus 5 mu)
For example,
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
aa\,a\!a\:a\>a\;a
\]
\setlength{\thinmuskip}{7mu}
\setlength{\medmuskip}{19mu plus 2mu minus 4mu}
\setlength{\thickmuskip}{23mu plus 5 mu}
\[
aa\,a\!a\:a\>a\;a
\]
\end{document}

References