コントラクトブリッジに関するLaTeXコマンド
コントラクトブリッジのことをLaTeXで書こうと思いました。
まあ、tabularだろうなあと思ったのですが、先達はあらまほしきことかな、検索してみたらoneclub77さんとおっしゃる方がサンプルを公開していらっしゃいました。
http://www.geocities.jp/fqwdg204/mirror/LaTeXBridge.html
なるほど、multicolumnにするとNとSの手を横に延ばせますね。
さて、こういうのはコマンドにしたくなるものです。
\newcommand{\hand}[4]{% \begin{tabular}{l} $\spadesuit$\ {\ttfamily #1} \\ $\heartsuit$\ {\ttfamily #2} \\ $\diamondsuit$\ {\ttfamily #3} \\ $\clubsuit$\ {\ttfamily #4} \\ \end{tabular}% } \newcommand{\conditions}[3]{% \begin{tabular}{l} \footnotesize{Board {#1}} \\ \footnotesize{{#2} Dealt} \\ \footnotesize{{#3} Game} \\ \end{tabular}% } \makeatletter \newcommand{\diagram}[6][\relax]{\@diagram{#1}{#2}{#3}{#4}{#5}{#6}} \def\@diagram#1#2#3#4#5#6{ \def\tablesquare{% \begin{tabular}{|ccc|} \hline & \texttt{N} & \\ \texttt{W} & \vulsymb{#2} & \texttt{E} \\ & \texttt{S} & \\ \hline \end{tabular}% }% \begin{tabular}{lll} {#1} & \multicolumn{2}{l}{#3} \\ {#4} & \multicolumn{1}{c}{\tablesquare} & {#5} \\ & \multicolumn{2}{l}{#6}\\ \end{tabular}% } \makeatother \makeatletter \newcommand{\vulsymb}[1]{\@vulsymb#1\relax\relax\relax\relax\relax\relax\relax\relax\relax} \def\@vulsymb#1#2#3#4#5#6#7#8#9{% \def\Hbarsymb{\texttt{-}}% \def\Vbarsymb{\texttt{\symbol{"7C}}}% \def\Crosssymb{\texttt{+}}% \def\firstchar{#1}% \if\firstchar N\Vbarsymb\fi% \if\firstchar S\Vbarsymb\fi% \if\firstchar E\Hbarsymb\fi% \if\firstchar W\Hbarsymb\fi% \if\firstchar B\Crosssymb\fi% } \makeatother
変更点は、フォントを私の好みに合わせてttにしたくらいです。
以下、個別に:
\newcommand{\hand}[4]{% \begin{tabular}{l} $\spadesuit$\ {\ttfamily #1} \\ $\heartsuit$\ {\ttfamily #2} \\ $\diamondsuit$\ {\ttfamily #3} \\ $\clubsuit$\ {\ttfamily #4} \\ \end{tabular}% }
第1引数から第4引数には、スペードからクラブまでを順に入れてください。
前述の通り、フォントがttになっています。
10を「10」で表記すると見づらくなりそうなので、「T」表記派向けかもしれません*1。
\newcommand{\conditions}[3]{% \begin{tabular}{l} \footnotesize{Board {#1}} \\ \footnotesize{{#2} Dealt} \\ \footnotesize{{#3} Game} \\ \end{tabular}% }
最初は独立したコマンドではなくて直後の\diagramコマンドの一部だったんですが、\diagramの引数が多すぎて見づらくなったので独立させてしまいました。
\makeatletter \newcommand{\diagram}[6][\relax]{\@diagram{#1}{#2}{#3}{#4}{#5}{#6}} \def\@diagram#1#2#3#4#5#6{ \def\tablesquare{% \begin{tabular}{|ccc|} \hline & \texttt{N} & \\ \texttt{W} & \vulsymb{#2} & \texttt{E} \\ & \texttt{S} & \\ \hline \end{tabular}% }% \begin{tabular}{lll} {#1} & \multicolumn{2}{l}{#3} \\ {#4} & \multicolumn{1}{c}{\tablesquare} & {#5} \\ & \multicolumn{2}{l}{#6}\\ \end{tabular}% } \makeatother
私の知識不足で、N-W-E-SとN-E-S-Wのどちらが(あるいはまったく別の順序が)コントラクトブリッジ界隈の標準なのかわからなかったので、次善策としてラップしました。
取り敢えずN-W-E-Sの順に入れるようにしてありますが、もしもN-E-S-W順に変更するなら、
\newcommand{\diagram}[6][\relax]{\@diagram{#1}{#2}{#3}{#4}{#5}{#6}}
の部分を
\newcommand{\diagram}[6][\relax]{\@diagram{#1}{#2}{#3}{#6}{#4}{#5}}
に書き換えてください。
\diagramの最初の引数には\conditionsが代入されるのを想定していますが、もちろんほかのものでも構いません。
#2にはバルネラビリティが入ります(後述)。N-SとかE-WとかBothとかを書いてください。ただし、Noneのときは空にしてください。
\makeatletter \newcommand{\vulsymb}[1]{\@vulsymb#1\relax\relax\relax\relax\relax\relax\relax\relax\relax} \def\@vulsymb#1#2#3#4#5#6#7#8#9{% \def\Hbarsymb{\texttt{-}}% \def\Vbarsymb{\texttt{\symbol{"7C}}}% \def\Crosssymb{\texttt{+}}% \def\firstchar{#1}% \if\firstchar N\Vbarsymb\fi% \if\firstchar S\Vbarsymb\fi% \if\firstchar E\Hbarsymb\fi% \if\firstchar W\Hbarsymb\fi% \if\firstchar B\Crosssymb\fi% } \makeatother
きちんとTeXのことを知っている人が見たら、ひどいと思われるでしょう。
TeXの文字列処理をまったく知らないまま、取り敢えず知っている方法で書いたらこうなりました。
\vulsymbは、9文字までの文字列を受け取ると、その最初の文字がNかSなら縦棒、EかWなら横棒、Bなら十字に置換されます。BはBothのつもりです。
Noneと書くと縦棒になってしまうのがダメなところです。Noneのときは空にしておいてください。
タブあり版
ところで、タブが8文字幅になっちゃってて見づらいので、もう無い方がいいかと思って、上では全部取っちゃったんですが、本当はタブがありました。
\newcommand{\hand}[4]{% \begin{tabular}{l} $\spadesuit$\ {\ttfamily #1} \\ $\heartsuit$\ {\ttfamily #2} \\ $\diamondsuit$\ {\ttfamily #3} \\ $\clubsuit$\ {\ttfamily #4} \\ \end{tabular}% } \newcommand{\conditions}[3]{% \begin{tabular}{l} \footnotesize{Board {#1}} \\ \footnotesize{{#2} Dealt} \\ \footnotesize{{#3} Game} \\ \end{tabular}% } \makeatletter \newcommand{\diagram}[6][\relax]{\@diagram{#1}{#2}{#3}{#4}{#5}{#6}} \def\@diagram#1#2#3#4#5#6{ \def\tablesquare{% \begin{tabular}{|ccc|} \hline & \texttt{N} & \\ \texttt{W} & \vulsymb{#2} & \texttt{E} \\ & \texttt{S} & \\ \hline \end{tabular}% }% \begin{tabular}{lll} {#1} & \multicolumn{2}{l}{#3} \\ {#4} & \multicolumn{1}{c}{\tablesquare} & {#5} \\ & \multicolumn{2}{l}{#6} \\ \end{tabular}% } \makeatother \makeatletter \newcommand{\vulsymb}[1]{\@vulsymb#1\relax\relax\relax\relax\relax\relax\relax\relax\relax} \def\@vulsymb#1#2#3#4#5#6#7#8#9{% \def\Hbarsymb{\texttt{-}}% \def\Vbarsymb{\texttt{\symbol{"7C}}}% \def\Crosssymb{\texttt{+}}% \def\firstchar{#1}% \if\firstchar N\Vbarsymb\fi% \if\firstchar S\Vbarsymb\fi% \if\firstchar E\Hbarsymb\fi% \if\firstchar W\Hbarsymb\fi% \if\firstchar B\Crosssymb\fi% } \makeatother
*1:スペーシングすれば良いのでしょうけど、スペーシングのことを良く知らないのです。