This is a question about typesetting diagrams for the Game of Go using the sgf2dg tools (currently in their version 4.252 available at their CPAN home).
The sgf2dg tools can be used to create go diagrams from sgf files (smart game format) and to annotate the diagrams as in this example:
The diagrams look very nice to me and I would like to add comments with numbered stones as well. The sgf2dg TeX library gooemacs.sty makes available the command \textstone{} for exactly that purpose. The lines
This is a black stone: \textstone{\goo\003@}
This is a smaller black stone: {\setGoFonts at 1.8ex \textstone{\goo\003@}}
produce the nice output of:
Now my problem
The \textstone{} command does everything I want for a price: The input of the go stone's label has to be in that specific \goo (or \goe) format as a four digit code. In the example above \goo\003@ will produce a black stone labeled 3. \goo (and their relatives \goe, \bgoo and \bgoe) are font selection mechanisms. Here is the definition of \goo from the package gooemacs.sty:
\def\goo{\offinterlineskip\parindent=0pt\parskip=0pt\obeylines%black odd, white even
\setbox0\hbox{\gooegb +}\global\goIntWd=\wd0\global\goIntHt=\ht0\global\goTextAdj=2pt%
\def\0##1##2##3{\if##1?\gooegb ##3 \else \gooa\char##1##2 \fi}%
\def\1##1##2##3{\if##1?\gooegb ##3 \else \goob\char##1##2 \fi}%
\def\2##1##2##3{\if##1?\gooegb ##3 \else \gooc\char##1##2 \fi}%
\def\3##1##2##3{\if##1?\gooegb ##3 \else \good\char##1##2 \fi}%
\def\4##1##2##3{\if##1?\gooegb ##3 \else \gobl\char##1##2 \fi}%
\def\5##1##2##3{\if##1?\gooegb ##3 \else \gowl\char##1##2 \fi}%
\def\-##1##2{\gooegb ##1}%
\def\!##1{\leavevmode\hbox to \goIntWd{\hss\raise\goTextAdj\hbox{\rm ##1}\hss}}% #1 on empty intersections
}
I do, however, consider their encryption as too complicated to think about while writing my go diagram's annotation.
For annotating the diagrams I want to use a high (higher) level LaTeX macro like \Black{}.
I want to write \Black{3} in my source code and then have it transformed to its corresponding \goo\003@.
Question
My attempt was to define a new command like:
\newcommand{\Black}[1]{%
\ifnum #1 >299 {\goo\#1@}\fi%
}
\Black{301}
but the replacement #1 fails (because of the preceding \ I guess) and produces the output \#1. How can I prevent that? How can I have TeX replace #1 and put it right after a backslash?
Remarks
I do realize there are more problems to solve: font selection based on even/odd label number, missing leading zeros with smaller stone numbers (1-99).
If you try to convert an sgf file to tex be aware of a bug in sgf2dg's version 4.252: stackoverflow.com.
The change of font size command in gooemacs.sty (\setGoFonts at #1) is missing end-of-line-%s, see What is the use of percent signs (%) at the end of lines?.
As a MWE I attach some working TeX code with the sgf2dg package. As mentioned above my attempt at \Black{} failed and is not included here.
The example requires the installation of sgf2dg package (with gooemacs), which is also available on many Linux distributions.
\documentclass[margin=1mm]{standalone}
\usepackage{gooemacs}
\begin{document}
This is a black stone: \textstone{\goo\003@}
This is a smaller black stone: {\setGoFonts at 1.8ex \textstone{\goo\003@}}
\end{document}



\Black{3} in my source code and then have it transformed to its corresponding \goo\003@would be\newcommand\Black[1]{\goo\00#1@}but your suggested code is trying something else testing for 299? (sorry not playing go, it's hard to guess what the intended usage is here) – David Carlisle Jan 15 '17 at 11:11\Black{13}for example fails: \goo\013@ intended, but \goo\0013@ received. – Jan 15 '17 at 11:23\goo\003@is 5 tokens\goo,\0,0,3,@so for\Blackdo you want the first two tokens always to be\goo\0the last token always to be@and the middle two tokens to be a number#1padded with a leading zero if less than 10 ? or do you sometimes need 3 digit input and change the\0token ? – David Carlisle Jan 15 '17 at 11:28\gooin the question. I require input up to\Black{399}(this is how many labels are offered by the fonts). They need token\0for labels up to 99 (with additional zero for single digits), then\1for 100-199,\2for 200-299 and lastly\3for 300-399 – Jan 15 '17 at 11:50?in the input as well, which isn't handled by my answer – David Carlisle Jan 15 '17 at 11:54?is used for a handful of special symbols like triangle or square as label for a go stone. Eventually I want to be able to handle\Black{triangle}or that sort, but I havn't asked about that yet... – Jan 15 '17 at 12:05