# How to define letter-spacing of a custom environment?

Say I have:

%defines a vertical bridge hand with seat name
\newcommand{\hand}[5]{
\begin{minipage}[t]{1.0cm}
\begin{tabbing}
\textsc{#1} \= \\
\s\Hair\=#2 \\
\h \> #3 \\
\d \> #4 \\
\c \> #5
\end{tabbing}
\end{minipage} }%


to produce:

How do I customize the letter-spacing (between letters/numbers after the suit symbol) inside a custom environment? Is it also possible to add custom kerning between certain letters/numbers? (Say apart from my custom letter-spacing, I want to adjust the kerning between K and J.

MWE:

\documentclass[10pt,a5paper,english]{article}
\usepackage{mathptmx}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\pagestyle{empty}
\usepackage{amsmath}

%********************************************************************************
%Use MnSymbol suit symbols
\DeclareFontFamily{U}{MnSymbolCards}{}

\DeclareFontShape{U}{MnSymbolCards}{m}{n}{
<-6>  s*[1.2] MnSymbolC5
<6-7>  s*[1.2] MnSymbolC6
<7-8>  s*[1.2] MnSymbolC7
<8-9>  s*[1.2] MnSymbolC8
<9-10> s*[1.2] MnSymbolC9
<10-12> s*[1.2] MnSymbolC10
<12->   s*[1.2] MnSymbolC12}{}

\newcommand{\mndiamond}{{\usefont{U}{MnSymbolCards}{m}{n}\symbol{"A2}}}
\newcommand{\mnheart}{{\usefont{U}{MnSymbolCards}{m}{n}\symbol{"A3}}}
\newcommand{\mnclub}{{\usefont{U}{MnSymbolCards}{m}{n}\symbol{"A5}}}

\renewcommand{\c}{\mnclub}
\renewcommand{\d}{\mndiamond}
\newcommand{\h}{\mnheart}
%********************************************************************************

%Defines "hair space" to be used after suit symbols
\newcommand{\Hair}{\ifmmode\mskip1mu\else\kern0.08em\fi}

%defines a vertical bridge hand with seat name
\newcommand{\hand}[5]{
\begin{minipage}[t]{1.0cm}
\begin{tabbing}
\textsc{#1} \= \\
\s\Hair\=#2 \\
\h \> #3 \\
\d \> #4 \\
\c \> #5
\end{tabbing}
\end{minipage} }%

\usepackage{babel}
\begin{document}
\noindent \hand{North}{KJ2}{AQ742}{K9}{K87}
\end{document}


I suggest a change in syntax, which has the benefit of making reformatting much easier.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{tgtermes}
\usepackage{xparse}

%***
%Use MnSymbol suit symbols
\DeclareFontFamily{U}{MnSymbolCards}{}

\DeclareFontShape{U}{MnSymbolCards}{m}{n}{
<-6>  s*[1.2] MnSymbolC5
<6-7>  s*[1.2] MnSymbolC6
<7-8>  s*[1.2] MnSymbolC7
<8-9>  s*[1.2] MnSymbolC8
<9-10> s*[1.2] MnSymbolC9
<10-12> s*[1.2] MnSymbolC10
<12->   s*[1.2] MnSymbolC12}{}

\newcommand{\mndiamond}{{\usefont{U}{MnSymbolCards}{m}{n}\symbol{"A2}}}
\newcommand{\mnheart}{{\usefont{U}{MnSymbolCards}{m}{n}\symbol{"A3}}}
\newcommand{\mnclub}{{\usefont{U}{MnSymbolCards}{m}{n}\symbol{"A5}}}

%***

% Defines the separation between cards
\newcommand{\cardsep}{\hspace*{0.3em}}

%defines a vertical bridge hand with seat name
\ExplSyntaxOn
\NewDocumentCommand{\hand}{mm}
{
\blackened_hand:nn { #1 } { #2 }
}

\seq_new:N \l_blackened_hand_seq
\clist_new:N \l_blackened_suit_clist

\cs_new_protected:Nn \blackened_hand:nn
{
\seq_set_split:Nnn \l_blackened_hand_seq { ; } { #2 }
\begin{minipage}[t]{\textwidth}
\begin{tabbing}
\textsc{#1} \\
\mnspade   \= \cardsep \= \blackened_set_suit:n { 1 } \\
\mnheart   \>          \> \blackened_set_suit:n { 2 } \\
\mndiamond \>          \> \blackened_set_suit:n { 3 } \\
\mnclub    \>          \> \blackened_set_suit:n { 4 }
\end{tabbing}
\end{minipage}
}
\cs_new_protected:Nn \blackened_set_suit:n
{
\clist_set:Nx \l_blackened_suit_clist { \seq_item:Nn \l_blackened_hand_seq { #1 } }
\clist_use:Nn \l_blackened_suit_clist { \cardsep }
}
\ExplSyntaxOff

\begin{document}

\hand{North}{K,J,2; A,Q,10,4,2; K,9; K,8,7}

\end{document}


The hand is split into its components at semicolons; then each component is split at commas, so we are able to insert whatever we want. Spaces in the second argument of \hand are completely irrelevant (except you shouldn't put a space in the middle of 10, of course), so the input can be better laid out.

A variant that allows for “horizontal” setting of a hand, with just \hand*. I'd keep the seat name for maximum portability: this way you just have to copy and paste a hand, adding or removing *. Line breaks are possible after the commas.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{tgtermes}
\usepackage{xparse}

%********************************************************************************
%Use MnSymbol suit symbols
\DeclareFontFamily{U}{MnSymbolCards}{}

\DeclareFontShape{U}{MnSymbolCards}{m}{n}{
<-6>  s*[1.2] MnSymbolC5
<6-7>  s*[1.2] MnSymbolC6
<7-8>  s*[1.2] MnSymbolC7
<8-9>  s*[1.2] MnSymbolC8
<9-10> s*[1.2] MnSymbolC9
<10-12> s*[1.2] MnSymbolC10
<12->   s*[1.2] MnSymbolC12}{}

\newcommand{\mndiamond}{{\usefont{U}{MnSymbolCards}{m}{n}\symbol{"A2}}}
\newcommand{\mnheart}{{\usefont{U}{MnSymbolCards}{m}{n}\symbol{"A3}}}
\newcommand{\mnclub}{{\usefont{U}{MnSymbolCards}{m}{n}\symbol{"A5}}}

%********************************************************************************

%Defines "hair space" to be used after suit symbols
\newcommand{\cardsep}{\hspace*{0.3em}}

%defines a vertical bridge hand with seat name
\ExplSyntaxOn
\NewDocumentCommand{\hand}{smm}
{
\IfBooleanTF{#1}
{
\blackened_hand_horizontal:nn { #2 } { #3 }
}
{
\blackened_hand:nn { #2 } { #3 }
}
}

\seq_new:N \l_blackened_hand_seq
\clist_new:N \l_blackened_suit_clist

\cs_new_protected:Nn \blackened_hand_horizontal:nn
{
\seq_set_split:Nnn \l_blackened_hand_seq { ; } { #2 }
\mbox{\mnspade   \ \blackened_set_suit:n { 1 } },~
\mbox{\mnheart   \ \blackened_set_suit:n { 2 } },~
\mbox{\mndiamond \ \blackened_set_suit:n { 3 } },~
\mbox{\mnclub    \ \blackened_set_suit:n { 4 } }
}

\cs_new_protected:Nn \blackened_hand:nn
{
\seq_set_split:Nnn \l_blackened_hand_seq { ; } { #2 }
\begin{minipage}[t]{\textwidth}
\begin{tabbing}
\textsc{#1} \\
\mnspade   \= \cardsep \= \blackened_set_suit:n { 1 } \\
\mnheart   \>          \> \blackened_set_suit:n { 2 } \\
\mndiamond \>          \> \blackened_set_suit:n { 3 } \\
\mnclub    \>          \> \blackened_set_suit:n { 4 }
\end{tabbing}
\end{minipage}
}
\cs_new_protected:Nn \blackened_set_suit:n
{
\clist_set:Nx \l_blackened_suit_clist { \seq_item:Nn \l_blackened_hand_seq { #1 } }
\clist_use:Nn \l_blackened_suit_clist { \cardsep }
}
\ExplSyntaxOff

\begin{document}

\hand*{North}{K,J,2; A,Q,10,4,2; K,9; ---}

\bigskip

\hand{North}{K,J,2; A,Q,10,4,2; K,9; K,8,7}

\end{document}


If you change the definition of \blackened_set_suit:n by

\tl_const:Nn \c_blackened_ten_tl { 10 }
\tl_new:N \l_blackened_suit_tl
\seq_new:N \l_blackened_suit_seq
\cs_new_protected:Nn \blackened_set_suit:n
{
\tl_set:Nx \l_blackened_suit_tl { \seq_item:Nn \l_blackened_hand_seq { #1 } }
\tl_if_blank:VTF \l_blackened_suit_tl
{ --- } % no card in the suit
{
\tl_replace_once:Nnn \l_blackened_suit_tl { 10 } { \c_blackened_ten_tl }
\seq_set_split:NnV \l_blackened_suit_seq { } \l_blackened_suit_tl
\seq_use:Nn \l_blackened_suit_seq { \cardsep }
}
}


then you have to remove the commas from the input above; spaces are again irrelevant, so from an input such as

\hand*{North}{KJ2; AQ1042; ; K 8 7 }

\bigskip

\hand{North}{KJ2; AQ1042; ; K 8 7}


you get

I'm not sure of any gain.

• Your answers always leave me in awe. Notwithstanding other helpful people, your answers are always through, with extreme attention to detail, and complete. Thank you ever so much. Sep 9 '15 at 9:54
• What would be the horizontal version of your macro (without seat name)? Sep 11 '15 at 21:46
• @blackened I added a possible solution. Sep 11 '15 at 22:01
• Sorry I forgot to elaborate. If possible, separated by {}, I guess I do not need line breaks. My initial rather simple macro was: \def\cards#1 #2 #3 #4 {\s{} #1\quad\h{} #2\quad\d{} #3\quad\c{} #4 } And I just want to be able to control the letter spacing. In your macro the cards were separated by commas, does that mean that they have to be separated one way or another? (Because of “10” problem?) Same question also about your initial macro. In general, the more flexibility the macro provides, the more I can tinker with it and perhaps tweak it slightly for other similar purposes. Sep 11 '15 at 22:04
• @blackened Just change the line with \textsc{#1} \\ into \tl_if_blank:nF { #1 } { \textsc{#1} \\ } and use an empty first argument to \hand, such as \hand{}{K,J,2; A,Q,10,4,2; K,9; ---} Sep 22 '15 at 20:04

Instead of your \newcommand{\hand}... you can use:

\def\hand#1#2#3#4#5{\vtop{
\hbox{\textsc{#1}}
\handA \s{#2}
\handA \h{#3}
\handA \d{#4}
\handA \c{#5}
}}
\def\handA#1#2{\hbox{\hbox to1em{\hss#1\hss}\handB#2\relax}}
\def\handB#1{\ifx#1\relax\else #1\if1#1\else\kern2pt \fi\expandafter\handB\fi}


The kerning between letters are set to 2pt, see the \handB definition. You can change this.

Edit: I added one exception: after 1 is not \kern, so ten is set correctly (and a single 1 is no card).

Edit2 If you need the syntax suggested by egreg, i. e.:

\hand{North}{K,J,2; A,Q,10,4,2; K,9; K,8,7}


then my macros can be modified by this way:

\def\hand#1#2{\handX{#1}#2;}
\def\handX#1#2;#3;#4;#5;{\vtop{
\hbox{\textsc{#1}}
\handA \s{#2}
\handA \h{#3}
\handA \d{#4}
\handA \c{#5}
}}
\def\handA#1#2{\hbox{\hbox to1em{\hss#1\hss}\handB#2,,}}
\def\handB#1,{\ifx,#1,\else \ignorespaces#1\kern2pt \expandafter\handB\fi}


Note, that my macros needn't any additional packages, any \ExplSynaxOn etc. What leave me in awe: why the simplest and TeX primitive solutions are not preferred here.

• +1. Very nice indeed. I'd probably go with a smaller kern amount that 2pt, though.
– Mico
Sep 9 '15 at 9:37
• Your macro, for instance, doesn't remove spaces after a card. I know it can be done, of course, but why bother when a higher level set of macros provides this automatically? Sep 9 '15 at 10:36
• This is not a good example of an application where we explicitly need to remove \kern2pt after the list of cards. But if somebody needs it, he/she can add \kern-2pt after \handB#2,,. All is easy without special packages. Sep 9 '15 at 10:45
• @wipet I hope my above comment did not annoy you in some way. Believe it or not, your answer also went into my notes, and taught things I was not aware of. Sep 9 '15 at 17:11
• @wipet What would be the “horizontal” version of your first macro? (That the whole hand will be shown horizontally.) Sep 9 '15 at 18:02