[Tex/LaTex] \mathit vs \textit for multi-letter identifiers

fontsmath-mode

I would like to include a number of two-letter variables in a sentence separated by commas but sometimes there is a noticeable space between the variable and the comma that follows it when I use mathit. Although the spaces are not as noticeable in the MWE below.

Is it better to use textit instead of mathit? If so, how can I ensure the font matches single-letter variables using the same letters (e.g. $\textit{A}$)?

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\textit{AB}, \textit{BA}, \textit{CD}, \textit{DC}

$\mathit{AB}$, $\mathit{BA}$, $\mathit{CD}$, $\mathit{DC}$

$\textit{AB}$, $\textit{BA}$, $\textit{CD}$, $\textit{DC}$
\end{document}

Best Answer

This is not an answer, but an attempt to talk you out of this notation.

UPDATE This post got feedback from several more experienced users. I agree with all their statements and certainly should have done more research. However, I also feel that their statements provide further reasons for the proposed notation not being optimal.

\documentclass{article}
\usepackage{amsmath}
\newcommand\myvar[1]{\ensuremath{\mathit{#1}}}
\begin{document}
Your options 
\begin{itemize}
 \item \textit{AB}, \textit{BA}, \textit{CD}, \textit{DC}
 \item $\mathit{AB}$, $\mathit{BA}$, $\mathit{CD}$, $\mathit{DC}$
 \item $\textit{AB}$, $\textit{BA}$, $\textit{CD}$, $\textit{DC}$
\end{itemize}
look all the same. In fact, it seems that there is no noticable difference
between these options:\\
\verb|\makebox[0pt][l]{$\mathit{AB}$}$\textit{AB}$|: \makebox[0pt][l]{$\mathit{AB}$}$\textit{AB}$

However, things are different once you wrap these commands in other
environmants:\\
\verb|\textbf{$\mathit{AB}$}|: \textbf{$\mathit{AB}$} vs.\\
\verb|\textbf{$\textit{AB}$}|: \textbf{$\textit{AB}$}\\
\verb|$\left(\mathit{AB}\right)$|: $\left(\mathit{AB}\right)$ vs.\\
\verb|$\left(\textit{AB}\right)$|: $\left(\textit{AB}\right)$

Even the pure math version looks very similar:\\
\verb|\makebox[0pt][l]{$\mathit{AB}$}$AB$|: \makebox[0pt][l]{$\mathit{AB}$}$AB$ 

However, the pure math version comes with different distances:\\
\verb|\makebox[0pt][l]{$\mathit{BA}$}$BA$|: \makebox[0pt][l]{$\mathit{BA}$}$BA$\\
\verb|\makebox[0pt][l]{$\mathit{BA}$}$\textit{BA}$|: \makebox[0pt][l]{$\mathit{BA}$}$\textit{BA}$

You may come up with a command that distinguishes netween math and nonmath
modes: \verb|\newcommand\myvar[1]{\ensuremath{\mathit{#1}}}|

Under boldface, this seems to behave like a math variable should:\\
\verb|\textbf{\myvar{AB}}|: \textbf{\myvar{AB}}\\
\verb|\textbf{$\myvar{AB}$}|: \textbf{$\myvar{AB}$}\\
\verb|\boldmath$\myvar{AB}$\unboldmath|: \boldmath$\myvar{AB}$\unboldmath\\
\verb|\boldmath\myvar{AB}\unboldmath|: \boldmath\myvar{AB}\unboldmath

The main reason for this point is to question whether it is a very wise move to
use this notation. Many people use $AB$ to indicate the
product $A\cdot B$, and $AB$ is virtually indistinguishable from your variable
\myvar{AB}. (I personally write $A\,B$, but get sometimes criticized.)

\paragraph{Bottomline:} Perhaps it is better to use a different notation.
\end{document}

enter image description here

Related Question