Automatic spacing of symbols

I'm curious how to automatically get a bit of spacing around symbols that are written together.

Let us assume we have symbols A and B that represent some abstract objects. We define commands \A and \B that insert the symbols.

\newcommand\A{\mathrm{A}}
\newcommand\B{\mathrm{B}}

Now I would like to have a bit of space between these symbols when written together with other symbols. Unfortunately, with the above definitions, it is necessary to add these spaces explicitly.

How can I get the extra spacing automatically? It is especially important that not just a static amount of space is added, to prevent extra spaces between equal signs and the symbols, and between repeated symbols.

The MWE that produced above output:

\documentclass[preview,border=10pt,fleqn]{standalone}

\usepackage{amsmath}
\setlength\mathindent{0pt}

\newcommand\A{\mathrm{A}}
\newcommand\B{\mathrm{B}}

\begin{document}

Symbols with no spacing \eqref{nospaces},
explicit \texttt{\textbackslash,} spaces \eqref{spaces}.
\begin{align}
\label{nospaces}
y &= \A x &
y &= x' \A x &
\B &= \A \A &
\B &= \A' \A
\\
\label{spaces}
y &= \A \, x &
y &= x' \, \A \, x &
\B &= \A \, \A &
\B &= \A' \, \A
\end{align}

\end{document}
• Why should \mathbf{A}\,\mathbf{B} be preferred to the normal \mathbf{A}\mathbf{B} in the first place? – egreg Sep 28 '14 at 21:05
• As a matter of personal taste, I prefer to write multiplication with a small space. Usually I'm not dealing with simple two symbol expressions, and things get very messy when not separated well. – user53911 Sep 28 '14 at 21:07
• Never seen. By the way, if vectors are bold italic, matrices should be too. – egreg Sep 28 '14 at 21:10
• I do not agree. They are operators, which means roman for me. Both are bold because they are n-dimensional. But I'm probably just used to this, it's pretty common among the papers I read. – user53911 Sep 28 '14 at 21:14
• No, a matrix is not an operator. It induces an operator, but the two aspects should be kept distinct: mixing them is a sure cause for misunderstandings. Only when you have fixed bases the matrix represents a map and changing the bases will change the representing matrix. An operator is independent of bases. – egreg Sep 28 '14 at 21:25

Definitely not an answer but compare the following two results.

\documentclass[preview,border=10pt,fleqn]{standalone}
\usepackage{mathtools}
\begin{document}
\begin{align*}
y &= Ax &\chi^2 &= x^TAx &C&= AB &D &= A^T B\\
y &= A\,x &\chi^2 &= x^T \, A \, x &C &= A   \, B &D &= A^T \, B\\
y &= A   x &\chi^2 &= x^T A x &C &= AB &D &= A^T B
\end{align*}
\end{document}

I've repeated thrice to look similar. I don't think anything needs to be bold to be able convey the message. Capital letters matrices, lowercase letters vectors. The transpose is not standard some use prime for that but lowercase t always looks like a misprinted prime, especially when matrices are bold, since it doesn't have enough weight.

• I agree that neither vectors nor matrices need to be bold. When writing for a theoretical physics audience, I would not bother to make anything bold. But in my part of astronomy, the dominant style is bold italic vectors, bold matrices, often in sans serif. Probably because this is the style of MNRAS. – user53911 Sep 28 '14 at 21:21
• @Nicolas They won't stop reading if you change your style to a normalized, simplified version. Tradition is strong, but not as much as you think. – percusse Sep 28 '14 at 21:23
• I have changed the question to focus more on the spacing. – user53911 Sep 29 '14 at 13:36

In case there is someone else out there looking for a solution, I will share what I have come up with after some trial and error.

In this answer, the combination \mathrm{}\! is used to add a bit of spacing before a differential d. So I defined the following two commands to add space to the left and right of symbols:

\newcommand\lxspace{\mathop{}\!}
\newcommand\rxspace{\!\mathop{}\nolimits}

Then I add the spaces manually to my symbols:

\newcommand\A{\lxspace\mathrm{A}\rxspace}
\newcommand\B{\lxspace\mathrm{B}\rxspace}

This seems to produce the desired effect:

I like Mathematica's way to denote products with spaces (horresco referens!). To do this in TeX, I have redefined * (see below) so that it inserts a thin space in math mode. This is not automatic, but it seems to work well with ordinary atoms, parentheses and operators. If needed, it can easily be switched off.

For other uses of * in math mode, \ast may be used instead. The behaviour of * outside of math mode is unchanged.

\mathcode\*="8000
{\catcode\*=\active
\gdef*{\mathclose{}\,\mathopen{}}}

$a*b$
$a b$
$a\,b$
$a*\cos b$
$a \cos b$
$a\,\cos b$

(Note that using \, instead of * inserts an unwanted space in the last expression.)

• Ah, Mathematica! That must be where I picked up the habit. Oh and a very nice solution, I will be using this. – user53911 Oct 1 '14 at 19:30