# Kerning after variable names with multiple letters

This question is related to Two letter variable names and Multiple letters without spacing in Math [duplicate], but it seems to me that the answers to these questions do not fully solve my problem.

In the example

\documentclass{article}

\usepackage{lmodern}
\usepackage{amsmath}

\begin{document}

\par (1) $\left\{ S, Y, Z \right\}$
\par (2) $\left\{ Satz, Y, Z \right\}$
\par (3) $\left\{ \text{\textit{Satz}}, \text{\textit{Y}}, \text{\textit{Z}} \right\}$
\par (4) $\left\{ \mathit{Satz}, \mathit{Y}, \mathit{Z} \right\}$

\end{document}


the result

of (3) \text{\textit{Satz}} and (4) \mathit{Satz} is satisfactory with respect to the inter-word spacing of the letters. In (1) and (2), however, the spacing between Y and , looks better. Is there a way to combine both advantages without the need for manual kerning?

Please note that, although Y is a single-letter variable name, similar problems would arise if a multi-letter variable name ended with Y.

• Use $\left\{ \mathit{Satz}, Y, Z \right\}$ and avoid to many multiletter variables. Even if it works more or less with \mathit, it is confusing and -- as you see -- the spacing is not really adapted to them. – Ulrike Fischer Nov 22 '17 at 17:52
• Replace with \{\mathit{SatZ}, Z,Y\} and you'll see this is only an optical illusion. – Bernard Nov 22 '17 at 17:53
• @UlrikeFischer Multi-letter variable names cannot be fully avoided when dealing with formal grammars in theoritical informatics. There could be a case such as SatzY in which your advice would not help. – Matthias Nov 22 '17 at 17:54
• Then you will have to add negative space. – Ulrike Fischer Nov 22 '17 at 17:56
• @Matthias: No, I meant between (3) and (4). – Bernard Nov 22 '17 at 19:20

\usepackage{xparse}

\ExplSyntaxOn

\NewDocumentCommand \var { m }
{
\tl_if_single:nTF { #1 }
{ #1          }
{ \mathit{#1} }
}

\ExplSyntaxOff


Whatever you do, use a command. And then you will be able to change the definition at the end even to get particular meanings (this is easily done with \str_case:nn).

• This is a perfect solution. In real world I already have a command for variables that occur in formal grammars which I decided to omit in the MWE. However I have not had the obvious idea of an if statement. In the F branch of your if statement I can easily introduce specific kernings depending on the last letter of the variable name. – Matthias Nov 22 '17 at 17:59
• Better than that, I think would be if you introduced each case that required particular treatment, \str_case:nnF {#1} { { Y } { <whatever> } { Z } { <whatother> } { SatZ } { <\mathit{SatZ} \kern5pt etc.> } } { \tl_if_single:nTF {#1} { #1 } { \mathit{#1} } } that way you have many particular cases, and in case nothing matches, you get the general “do nothing” in case of single letter, or “apply \mathit” in case of multiple letter. – Manuel Nov 22 '17 at 18:10