0

I'm using the great package chessboard and I am looking to write numbers into each field of the board to have such chessboard :

chessboard with numbers

Currently, I asked python

for i in range(64):
    case = f"{chr(97+i%8)}{1+i//8}"
    print(f"   text=\\scriptsize\\bfseries {i},markfield={case},%")

to write me the following 64 lines.

\documentclass{article}
\usepackage{chessboard}
\begin{document}
\setchessboard{showmover=false}
\chessboard[%
   smallboard,%
   pgfstyle={[base,at={\pgfpoint{0pt}{-0.4ex}}]text},%
   text=\scriptsize\bfseries 0,markfield=a1,%
   text=\scriptsize\bfseries 1,markfield=b1,%
   text=\scriptsize\bfseries 2,markfield=c1,%
   text=\scriptsize\bfseries 3,markfield=d1,%
   text=\scriptsize\bfseries 4,markfield=e1,%
   text=\scriptsize\bfseries 5,markfield=f1,%
   text=\scriptsize\bfseries 6,markfield=g1,%
   text=\scriptsize\bfseries 7,markfield=h1,%
   text=\scriptsize\bfseries 8,markfield=a2,%
   text=\scriptsize\bfseries 9,markfield=b2,%
   text=\scriptsize\bfseries 10,markfield=c2,%
   text=\scriptsize\bfseries 11,markfield=d2,%
   text=\scriptsize\bfseries 12,markfield=e2,%
   text=\scriptsize\bfseries 13,markfield=f2,%
   text=\scriptsize\bfseries 14,markfield=g2,%
   text=\scriptsize\bfseries 15,markfield=h2,%
   text=\scriptsize\bfseries 16,markfield=a3,%
   text=\scriptsize\bfseries 17,markfield=b3,%
   text=\scriptsize\bfseries 18,markfield=c3,%
   text=\scriptsize\bfseries 19,markfield=d3,%
   text=\scriptsize\bfseries 20,markfield=e3,%
   text=\scriptsize\bfseries 21,markfield=f3,%
   text=\scriptsize\bfseries 22,markfield=g3,%
   text=\scriptsize\bfseries 23,markfield=h3,%
   text=\scriptsize\bfseries 24,markfield=a4,%
   text=\scriptsize\bfseries 25,markfield=b4,%
   text=\scriptsize\bfseries 26,markfield=c4,%
   text=\scriptsize\bfseries 27,markfield=d4,%
   text=\scriptsize\bfseries 28,markfield=e4,%
   text=\scriptsize\bfseries 29,markfield=f4,%
   text=\scriptsize\bfseries 30,markfield=g4,%
   text=\scriptsize\bfseries 31,markfield=h4,%
   text=\scriptsize\bfseries 32,markfield=a5,%
   text=\scriptsize\bfseries 33,markfield=b5,%
   text=\scriptsize\bfseries 34,markfield=c5,%
   text=\scriptsize\bfseries 35,markfield=d5,%
   text=\scriptsize\bfseries 36,markfield=e5,%
   text=\scriptsize\bfseries 37,markfield=f5,%
   text=\scriptsize\bfseries 38,markfield=g5,%
   text=\scriptsize\bfseries 39,markfield=h5,%
   text=\scriptsize\bfseries 40,markfield=a6,%
   text=\scriptsize\bfseries 41,markfield=b6,%
   text=\scriptsize\bfseries 42,markfield=c6,%
   text=\scriptsize\bfseries 43,markfield=d6,%
   text=\scriptsize\bfseries 44,markfield=e6,%
   text=\scriptsize\bfseries 45,markfield=f6,%
   text=\scriptsize\bfseries 46,markfield=g6,%
   text=\scriptsize\bfseries 47,markfield=h6,%
   text=\scriptsize\bfseries 48,markfield=a7,%
   text=\scriptsize\bfseries 49,markfield=b7,%
   text=\scriptsize\bfseries 50,markfield=c7,%
   text=\scriptsize\bfseries 51,markfield=d7,%
   text=\scriptsize\bfseries 52,markfield=e7,%
   text=\scriptsize\bfseries 53,markfield=f7,%
   text=\scriptsize\bfseries 54,markfield=g7,%
   text=\scriptsize\bfseries 55,markfield=h7,%
   text=\scriptsize\bfseries 56,markfield=a8,%
   text=\scriptsize\bfseries 57,markfield=b8,%
   text=\scriptsize\bfseries 58,markfield=c8,%
   text=\scriptsize\bfseries 59,markfield=d8,%
   text=\scriptsize\bfseries 60,markfield=e8,%
   text=\scriptsize\bfseries 61,markfield=f8,%
   text=\scriptsize\bfseries 62,markfield=g8,%
   text=\scriptsize\bfseries 63,markfield=h8]
\end{document}

However I'm not satisfied with the solution. I read How to draw a chessboard with numbers? and How can I write numbers on the fields? but didn't find solution.

Looking pages 13 and 54 of the documentation, I was thinking to be able to use ranklabel and filelabel tags with something like

    text= \scriptsize\bfseries\arabic{ranklabel*8+filelabel},
    markboard,

but nothing worked (I was also thinking of xparse)…

Anyway, does someone has an idea to avoid writing 64 lines and simply writing a beautifull LaTeX code? Perheaps, showing me how to use ranklabel and filelabel?

I will appreciate any help, Gérald

1 Answer 1

5
\documentclass{article}
\usepackage{chessboard}
\ExplSyntaxOn %requires texlive 2020, in older system load expl3
\cs_new:Npn \getfieldnumber #1 
 {
  \fp_eval:n { (\tl_tail:V #1 -1)*8 + \exp_args:Ne\int_from_alph:n{\tl_head:V #1} -1}
 }
\ExplSyntaxOff
\begin{document}
\setchessboard{tinyboard,color=magenta,clearboard}
\chessboard[
pgfstyle=
{[base,at={\pgfpoint{0pt}{-0.3ex}}]text},
text= \fontsize{1.2ex}{1.2ex}\bfseries
\sffamily\getfieldnumber\currentwq,
markboard]


\end{document}

enter image description here

2
  • Thanks so lot Ulrike ; two times, firstly for your response and secondly for your package! If I understand correctly, \currentwq returns a string (e.g. b3) then \tl_tail returns the last character (e.g. 3), tl_head returns the first character (e.g. b) which will be converted to number by \int_from_alph. Is it right? Thanks to you, I might I should study expl3 package. Jun 7, 2020 at 9:40
  • yes that is what more or less happens (but I'm not sure if the function is the most effective one regarding the expansion, it was late yesterday). Jun 7, 2020 at 9:44

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.