# Weird spacing between some letters in math mode

Input:

$$\begin{split} democ_{i,t}={} & \alpha\,democ_{i,t-5} \quad+\quad \beta\,students\;abroad_{i,t-5} \quad+\quad \\ & \gamma\,democ.\;in\;receiving\;countries_{i,t-5} \quad+\quad\ \\ & \delta\,(students\;abroad_{i,t- 5}*democ.\;in\;receiving\;countries_{i,t-5}) \quad+\quad \\ & country\;fixed\;effects_i \quad+\quad time\;fixed\;effects_t \quad+\quad \epsilon_{i,t} \end{split}$$


Output: Why is there extra spacing between the f's in 'effects' when every other word is properly spaced? How do I fix it?

• You have to use \text{} from amsmath package. Otherwise, it is not a text, but a sequence of math variables. – Sigur Nov 4 '18 at 2:41
• @Sigur Those are variables and not text so I want them to be like that. Will I have to use \text{} and italicize it to achieve this? – vader9280 Nov 4 '18 at 2:43
• Why not perfect? – Sigur Nov 4 '18 at 2:53
• I would possibly use \mathit rather than \textit but never use the default math italic font for multi-letter identifiers, it is explictly designed with wide sidebearings so adjacent letters do not look like part of a ward but as a product of variables. – David Carlisle Nov 4 '18 at 10:42
• @Mico yes that's why I said "perhaps" rather than "do":-) it is the usual issue \mathit is set up for the math font setup as a fixed math alphabet font. \textit is the current text italic font (so for example would be bold italic if the text font outside the math was bold) and it might be a completely different font set, by default they are both computer modern italic but math and texts fonts are separately specified and do not have to be the same. – David Carlisle Nov 4 '18 at 11:04

I propose this format (with \bigl( \bigr) if you wish):

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{aligned} \textit{democ}_{i,t} &= \alpha\, (\textit{democ}_{i,t-5}) + \beta\, (\textit{students abroad}_{i,t-5}) \\ &\quad + \gamma\, (\textit{democ. in receiving countries}_{i,t-5}) \\ &\quad + \delta\, (\textit{students abroad}_{i,t- 5}) (\textit{democ. in receiving countries}_{i,t-5}) \\ &\quad + \textit{country fixed effects}_i + \textit{time fixed effects}_t + \epsilon_{i,t} \end{aligned}
\end{document}


Here's an answer that's quite similar, at first glance, to @Sigur's answer. It differs from Sigur's by (a) providing adjustments to make sure that the . ("dot", "period", "full stop") isn't misinterpreted as a sentence-ending punctuation mark, (b) placing the parentheses solely around the variable names, not their subscript terms, (c) providing for explicit italic corrections and, most importantly, (d) taking a more "LaTeX-y" approach to things, by which I mean separating meaning from form, by defining a macro called \vn (short for "variable name") that's to be used to display variable names. In the code below, I've chosen the definition \newcommand\vn[1]{\textit{#1}}. An advantage of such a setup is that if you ever, at some point in the future, decide that you'd rather display variable names using an upright rather than an italic font, all you'd need to do is change the definition of \vn. In particular, you would not have to go and check each and every instance of \textit in the document and decide whether it needs to be changed to \textrm.

The following code also makes some spacing adjustments between \vn{democ} and its associated subscript terms.

\documentclass{article}
\usepackage{amsmath}
\newcommand\vn[1]{\textit{#1\/}} % to display a variable name
%% note the italic correction provided by "\/"
\begin{document}

$$\begin{split} \vn{democ}_{\mkern1.5mu i,t} &= \alpha\, \vn{democ}_{\mkern1.5mu i,t-5} + \beta\, (\vn{students abroad})_{i,t-5} \\ &\quad +\gamma\, (\vn{democ.\ in receiving countries})_{i,t-5} \\ &\quad +\delta\, (\vn{students abroad})_{i,t-5}\, (\vn{democ.\ in receiving countries})_{i,t-5} \\ &\quad +(\vn{country fixed effects})_i + (\vn{time fixed effects})_t + \epsilon_{i,t} \end{split}$$
\end{document}

• I think in latex italic correction is included by default. Are you sure you need \/? May be I'm wrong. – Manuel Nov 4 '18 at 11:14
• @Manuel - If one stays entirely within text mode, as in ... \textit{word} ..., then the italics correction would indeed be performed automatically at the end of the argument of \textit. For the example at hand, though, that's not the case: math stuff (specifically, a closing parenthesis) follows the text-italic material. Do check for yourself the output of (\vn{students abroad}) -- specifically, the distance between d and ) -- if the macro is set up with and without the italic correction. – Mico Nov 4 '18 at 14:20

Inspired by Mico's solution, here's an improved one that

1. Doesn't need \,
2. Automatically adds parentheses if the variable consists of several words
3. Uses \mathit instead of \textit
4. Doesn't need “backslash space” after a period

Here's the code

\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\vn}{m}
{
\seq_set_split:Nnn \l_tmpa_seq { ~ } { #1 }
\int_compare:nTF { \seq_count:N \l_tmpa_seq > 1 }
{
\seq_set_map:NNn \l_tmpb_seq \l_tmpa_seq { \exp_not:N \mathit { ##1 } }
(\seq_use:Nn \l_tmpb_seq { \  })
}
{ \mathop{}\!\mathit{#1} }
}
\ExplSyntaxOff

\begin{document}

$$\begin{split} \vn{democ}_{i,t} ={} & \alpha \vn{democ}_{i,t-5} + \beta \vn{students abroad}_{i,t-5} \\ & +\gamma \vn{democ. in receiving countries}_{i,t-5} \\ & +\delta \vn{students abroad}_{i,t-5} \vn{democ. in receiving countries}_{i,t-5} \\ & +\vn{country fixed effects}_i + \vn{time fixed effects}_t + \epsilon_{i,t} \end{split}$$

\end{document}