8

With the help of egreg, my bridge-related macros have come a long way. The following MWE:

%********************************************************************************
\documentclass[10pt]{article}
\usepackage[paperwidth=6in,paperheight=9in, margin=1in]{geometry}
\usepackage{MnSymbol}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{xparse}
\usepackage{tikz}
\usepackage{libertine}
%********************************************************************************


%********************************************************************************
% Use MnSymbol suit symbols

\DeclareFontFamily{U}{MnSymbolCards}{}

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

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


%********************************************************************************
% BRIDGE HAND
% macros to produce horizontal and vertical bridge hand

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

%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 } }\quad
  \mbox{\mnheart   \ \blackened_set_suit:n { 2 } }\quad
  \mbox{\mndiamond \ \blackened_set_suit:n { 3 } }\quad
  \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}
 \tl_if_blank:nF { #1 } { \textbf{#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}
 }

\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 }
   }
 }
\ExplSyntaxOff
%********************************************************************************


%********************************************************************************
% BRIDGE DIAGRAM

\newcommand{\bd}[4]{%
\begin{tabular}[t]{ p{7em} p{7em} p{7em}}
 & #1 & \\
#2 & {\vspace{4pt}\begin{tikzpicture} \draw (0,0) rectangle (1.3,1.3); \end{tikzpicture}} & #3\\
   & #4 &
\end{tabular}
}
%********************************************************************************


%********************************************************************************
% custom minipage (needed for spacial cases)

\newlength{\myminipageparskip}
\newenvironment{bdminipage}
  {\setlength{\myminipageparskip}{1ex}% save the value
   \begin{minipage}{21em}% open the minipage
   \setlength{\parskip}{\myminipageparskip}% restore the value
  }
  {\end{minipage}}
%********************************************************************************


\begin{document}

\begin{center}
\begin{bdminipage}
\bd
{\hand{North}{QJ42; 7; AJ763; 843}}%
{\hand{West}{K1085; AK543; Q4; AJ}}%
{\hand{East}{976; Q862; K10952; K}}%
{\hand{South}{A3; J109; 8; Q1097652}}%
\end{bdminipage}
\end{center}

\end{document}

produces:

enter image description here

How can modify the macro so that I can produce diagrams like:

enter image description here

The example has only two suits, but it could have been one, the suit symbols might have been different, I might wish not to include seat names, in some extreme cases, one seat may have two suits, while other seats have only one suit, etc. So, flexibility is paramount, and infinitely appreciated.

5

Add an optional argument to \hand that specifies what suits you want to show; the order is unimportant, the suits are called by name: S = spades, H = hearts, D = diamonds, C = clubs.

There are slight complications for getting the alignments right, but I think I solved them.

    %********************************************************************************
\documentclass[10pt]{article}
\usepackage[paperwidth=6in,paperheight=9in, margin=1in]{geometry}
%\usepackage{MnSymbol} % not needed
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{array}
\usepackage{xparse}
\usepackage{tikz}
\usepackage{libertine}
%********************************************************************************


%********************************************************************************
% Use MnSymbol suit symbols

\DeclareFontFamily{U}{MnSymbolCards}{}

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

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


%********************************************************************************
% BRIDGE HAND
% macros to produce horizontal and vertical bridge hand

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

%defines a vertical bridge hand with seat name
\ExplSyntaxOn
\NewDocumentCommand{\hand}{sO{S,H,D,C}mm}
 {
  \IfBooleanTF{#1}
   {
    \blackened_hand_horizontal:nnn { #2 } { #3 } { #4 }
   }
   {
    \blackened_hand:nnn { #2 } { #3 } { #4 }
   }
 }

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

\cs_new_protected:Nn \blackened_hand_horizontal:nnn
 {
  \seq_set_split:Nnn \l_blackened_hand_seq { ; } { #3 }
  \hspace*{-1em}% remove the initial \quad
  \clist_if_in:nnT { #1 } { S }
   { \quad \mbox{\mnspade   \ \blackened_set_suit:n { 1 } } }
  \clist_if_in:nnT { #1 } { H }
   { \quad \mbox{\mnheart   \ \blackened_set_suit:n { 2 } } }
  \clist_if_in:nnT { #1 } { D }
   { \quad \mbox{\mndiamond \ \blackened_set_suit:n { 3 } } }
  \clist_if_in:nnT { #1 } { C }
   { \quad \mbox{\mnclub    \ \blackened_set_suit:n { 4 } } }
 }

\cs_new_protected:Nn \blackened_hand:nnn
 {
  \seq_set_split:Nnn \l_blackened_hand_seq { ; } { #3 }
  \bool_gset_false:N \g_blackened_newline_bool
  \begin{minipage}{\textwidth}
  \begin{tabbing}
  \tl_if_blank:nTF { #2 }
    { \bool_gset_false:N \g_blackened_newline_bool }
    { \bool_gset_true:N \g_blackened_newline_bool \textbf{#2} }
  \clist_if_in:nnT { #1 } { S }
   { \blackened_newline: \mnspade   \= \cardsep \= \blackened_set_suit:n { 1 } }
  \clist_if_in:nnT { #1 } { H }
   { \blackened_newline: \mnheart   \= \cardsep \= \blackened_set_suit:n { 2 } }
  \clist_if_in:nnT { #1 } { D }
   { \blackened_newline: \mndiamond \= \cardsep \= \blackened_set_suit:n { 3 } }
  \clist_if_in:nnT { #1 } { C }
   { \blackened_newline: \mnclub    \= \cardsep \= \blackened_set_suit:n { 4 } }
  \end{tabbing}
  \end{minipage}
  \bool_gset_false:N \g_blackened_newline_bool
 }

\tl_const:Nn \c_blackened_ten_tl { 10 }
\tl_new:N \l_blackened_suit_tl
\seq_new:N \l_blackened_suit_seq
\bool_new:N \g_blackened_newline_bool

\cs_new_protected:Nn \blackened_newline:
 {
  \bool_if:NTF \g_blackened_newline_bool
   { \\ }
   { \bool_gset_true:N \g_blackened_newline_bool }
 }

\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 }
   }
 }
\ExplSyntaxOff
%********************************************************************************


%********************************************************************************
% BRIDGE DIAGRAM

\newcommand{\bd}[4]{%
\begin{tabular}{ m{7em} m{7em} m{7em}}
 & #1 & \\
#2 & \parbox{7em}{
       \vspace{1ex}
       \begin{tikzpicture} \draw (0,0) rectangle (1.3,1.3); \end{tikzpicture}
       \vspace{1ex}
     } & #3\\
   & #4 &
\end{tabular}
}
%********************************************************************************


%********************************************************************************
% custom minipage (needed for spacial cases)

\newlength{\myminipageparskip}
\newenvironment{bdminipage}
  {\setlength{\myminipageparskip}{1ex}% save the value
   \begin{minipage}{21em}% open the minipage
   \setlength{\parskip}{\myminipageparskip}% restore the value
  }
  {\end{minipage}}
%********************************************************************************


\begin{document}

\begin{center}
\begin{bdminipage}
\bd
{\hand{North}{QJ42; 7; AJ763; 843}}%
{\hand{West}{K1085; AK543; Q4; AJ}}%
{\hand{East}{976; Q862; K10952; K}}%
{\hand{South}{A3; J109; 8; Q1097652}}%
\end{bdminipage}

\bigskip

\begin{bdminipage}
\bd
{\hand[S,H]{North}{QJ42; 7; AJ763; 843}}%
{\hand[S,H]{West}{K1085; AK543; Q4; AJ}}%
{\hand[S,H]{East}{976; Q862; K10952; K}}%
{\hand[S,H]{South}{A3; J109; 8; Q1097652}}%
\end{bdminipage}

\bigskip

\begin{bdminipage}
\bd
{\hand[S]{}{QJ42; 7; AJ763; 843}}%
{\hand[H]{}{K1085; AK543; Q4; AJ}}%
{\hand[D]{}{976; Q862; K10952; K}}%
{\hand[C]{}{A3; J109; 8; Q1097652}}%
\end{bdminipage}
\end{center}

\end{document}

enter image description here

  • Unless I am terribly missing something, your new macro causes a peculiar behavior, but only for the first hand. (See the North hand in the first example in your output.) (If you simply repeat the same diagram, the second outputs everything as it should be.) (And it does not matter whether the hand is in a bridge diagram or not, even if it is by itself, the first one causes the same behavior.) – blackened Oct 21 '15 at 7:48
  • Okay, no worries. (I’ll keep in touch even if you tell me to go away.) – blackened Oct 21 '15 at 8:14
  • @blackened Now it should be OK – egreg Oct 21 '15 at 8:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.