[Tex/LaTex] Controlling horizontal spacing in math mode in text

amsmathmath-modespacing

I am using the most recent release of TexLive on my MacBook Air. I am using the packages amsmath, amssymb, scalefnt, graphicx,and subcaption in addition to a journal's package.

Like a previous query How to get less spacing in math mode, I want to reduce the white space in math mode but only when an equation occurs in text, as in $a=b.$ I don't want to automatically reduce the white space when in display-math mode, such as

$$a=b$$

or

\begin{align}
a&=b\\
c&=d
\end{align}

I know that I can do various things in individual equations such as
$a{=}b$ or $ a \!=\! b,$ but I don't want to have to do it each time,
and the journal might insist on changes in publication, or perhaps
my co-author will want to do things differently for some other purpose.

I couldn't see how to use \newcommand or \stackrel in a way that makes such a distinction between equations in text and equations in displaymath, but it ought to be simple using {displaystyle} or something similar. I couldn't figure it out.

Help?

Best Answer

Here's a possibility:

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\everymath{\if@display\else\thickmuskip=2mu plus 2mu\fi}
\makeatother

\begin{document}

\begin{center}% just to show the effect
$a=b$
\end{center}
\[
a=b
\]

\end{document}

Alternatively (and preferably), but this requires using \(...\) for inline math:

\documentclass{article}
\usepackage{amsmath}
\usepackage{xpatch}

\xpatchcmd{\(}{$}{$\thickmuskip=2mu plus 2mu }{}{}

\begin{document}

\begin{center}% just to show the effect
\(a=b\)
\end{center}
\[
a=b
\]

\end{document}

Note that $$...$$ will produce reduced spaces, if the first method is used. But this construction should never be used in LaTeX anyway.

enter image description here