2

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}
2
  • 2
    You're comparing apples and oranges; the right comparison would be between $AB$ and $\mathit{AB}$.
    – egreg
    Dec 11, 2017 at 8:40
  • The spaces between $\mathit{AB}$ and the adjacent comma and $\mathit{CD}$ and its adjacent comma are small in the png marmot included, based on my MWE, but these spaces become larger (and noticeable) when typeset as part of a paragraph. Unfortunately in my industry, $\mathit{AB}$ is the way these identifiers are typeset in equations. I only came across this space being introduced between $\mathit{AB}$ and the adjacent comma when I tried to include several of these identifiers in a paragraph. My strategy now is to avoid using a comma after $\mathit{AB}$ if the gap becomes too wide.
    – Chris
    Dec 18, 2017 at 7:09

1 Answer 1

2

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

3
  • 1
    Try \textbf{We have $\textit{AB}$} and \textbf{We have $\mathit{AB}$}
    – egreg
    Dec 11, 2017 at 8:33
  • See the difference: $\left(\mathit{B}\right)$ and $\left(\textit{B}\right)$ The spaces behave differently!
    – user91669
    Dec 11, 2017 at 8:59
  • 3
    saying \textit is a better choice because it works in text and math is not good advice, generally \mathit is better for math and \textit is better for text. Dec 11, 2017 at 9:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .