1

Consider the following two examples:

Example A

\documentclass{article}

\usepackage{xskak}

\begin{document}

\usetextfig
\textsymfigsymbol{R}a1 versus 
\usesymfig
\textsymfigsymbol{R}a1

\end{document}

outputA

Here, the notation style is changed.

Example B

\documentclass{article}

\usepackage{xskak}
\usesymfig

\setboardfontsize{10pt}

\begin{document}

\textsymfigsymbol{Q} versus
\raisebox{-1.5pt}{\BlackQueenOnWhite}

\end{document}

outputB

Here, the piece color is changed.

Addendum

The other commands for the black pieces are

\BlackKingOnWhite
\BlackRookOnWhite
\BlackBishopOnWhite
\BlackKnightOnWhite
\BlackPawnOnWhite

Question

Can I somehow combine the two examples?

I would like a command where I can switch between typesetting a black or a white piece (all the different pieces!), and at the same time be able to switch between algebraic notation and figure notation globally using \usetextfig or \usesymfig.

cis
  • 8,073
  • 1
  • 16
  • 45

3 Answers3

2

I would do it like this. By using ex as value and setting the fontsize in the command it will work for other font sizes too:

\documentclass{article}

\usepackage{xskak}

\usesymfig


\usepackage{tikz}
\makeatletter
  \newcommand*\cfss@king@@LSBblack  {\raisebox{-0.31ex}{\setboardfontsize{\f@size}\BlackKingOnWhite}}
  \newcommand*\cfss@queen@@LSBblack {\raisebox{-0.37ex}{\setboardfontsize{\f@size}\BlackQueenOnWhite}}
  \newcommand*\cfss@rook@@LSBblack  {\raisebox{-0.26ex}{\setboardfontsize{\f@size}\BlackRookOnWhite}}
  \newcommand*\cfss@bishop@@LSBblack{\raisebox{-0.35ex}{\setboardfontsize{\f@size}\BlackBishopOnWhite}}
  \newcommand*\cfss@knight@@LSBblack{\raisebox{-0.30ex}{\setboardfontsize{\f@size}\BlackKnightOnWhite}}
  \newcommand*\cfss@pawn@@LSBblack  {\raisebox{-0.31ex}{\setboardfontsize{\f@size}\BlackPawnOnWhite}}

\newcommand\usesymfigblack{%
 \def\cfss@figlanguage{@LSBblack}}
\makeatother 


\begin{document}

\usetextfig
\textsymfigsymbol{Q}
\usesymfig
\textsymfigsymbol{Q}
\usesymfigblack
\textsymfigsymbol{Q}


\footnotesize

\usetextfig
\textsymfigsymbol{Q}
\usesymfig
\textsymfigsymbol{Q}
\usesymfigblack
\textsymfigsymbol{Q}

\end{document}

enter image description here

Ulrike Fischer
  • 327,261
  • Very nice! (Is tikz needed here?) – Svend Tveskæg Nov 30 '17 at 21:22
  • 1
    I use tikz to check the baseline (with a \tikz[overlay]\draw[red](0,0)--++(0,5); before the symbols). – Ulrike Fischer Nov 30 '17 at 21:23
  • Would you mind if I update your answer with some more accurate values regarding the baseline issue? (I've used \Huge and zoomed in to 6400 % in Adobe Reader in order to get it as precise as possible.) – Svend Tveskæg Nov 30 '17 at 21:30
  • 1
    Sure if you want. btw: The ex is from the text font. So it can change. It would be probably better to first select the chess font. – Ulrike Fischer Nov 30 '17 at 21:31
  • 1
    I think \newcommand*\cfss@king@@LSBblack {{\setboardfontsize{\f@size}\fontencoding{LSB}\selectfont\raisebox{-0.33ex}{\BlackKingOnWhite}}} would be a better setting. – Ulrike Fischer Nov 30 '17 at 21:39
  • Hmm! Actually, to me it looks like the black king is not as tall as the white counterpart. I haven't compared the other pieces. (If I align at the bottom of the kings, I still get the best result with -0.31ex.) – Svend Tveskæg Nov 30 '17 at 23:35
  • 1
    The two board kings \WhiteKingOnWhite and \BlackKingOnWhite have the same size, but the figure king can be different. – Ulrike Fischer Nov 30 '17 at 23:39
1

There's an annoying issue with the baseline. If they don't line up properly for you, change the value -1.2pt to an appropriate value.

\documentclass{article}
\usepackage{chessfss}

\makeatletter
\def\cfssfixbaseline#1{\raise-1.2pt\hbox{#1}}
\def\useblackfig{\def\cfss@figlanguage{@BLSB}}
\def\usewhitefig{\def\cfss@figlanguage{@WLSB}}
\def\cfss@king@@WLSB{\cfssfixbaseline{\cfss@WhiteKingOnWhite}}
\def\cfss@queen@@WLSB{\cfssfixbaseline{\cfss@WhiteQueenOnWhite}}
\def\cfss@rook@@WLSB{\cfssfixbaseline{\cfss@WhiteRookOnWhite}}
\def\cfss@bishop@@WLSB{\cfssfixbaseline{\cfss@WhiteBishopOnWhite}}
\def\cfss@knight@@WLSB{\cfssfixbaseline{\cfss@WhiteKnightOnWhite}}
\def\cfss@pawn@@WLSB{\cfssfixbaseline{\cfss@WhitePawnOnWhite}}
\def\cfss@king@@BLSB{\cfssfixbaseline{\cfss@BlackKingOnWhite}}
\def\cfss@queen@@BLSB{\cfssfixbaseline{\cfss@BlackQueenOnWhite}}
\def\cfss@rook@@BLSB{\cfssfixbaseline{\cfss@BlackRookOnWhite}}
\def\cfss@bishop@@BLSB{\cfssfixbaseline{\cfss@BlackBishopOnWhite}}
\def\cfss@knight@@BLSB{\cfssfixbaseline{\cfss@BlackKnightOnWhite}}
\def\cfss@pawn@@BLSB{\cfssfixbaseline{\cfss@BlackPawnOnWhite}}
\makeatother

\begin{document}
\textsymfigsymbol{K}
\usewhitefig
\textsymfigsymbol{K}
\useblackfig
\textsymfigsymbol{p}
\textsymfigsymbol{N}
\usewhitefig
\textsymfigsymbol{R}
\usetextfig
\textsymfigsymbol{R}
\end{document} 
Hood Chatham
  • 5,467
0

I prefer a closed command instead of constantly typing in various switch commands.
In other words: a command that recognizes which symbol is wanted based on upper and lower case, just like you can do with board-input in xskak.sty or chessboard.sty.

So I have as a concoction of here

\def\FirstArgX{text}
\newcommand\skaksymb[2][]{\begingroup%
\def\SecondArgX{#1}%
\ifx\FirstArgX\SecondArgX \usetextfig\textsymfigsymbol{#2}\else%
\if\isuppercase{#2}\textsymfigsymbol{#2}%  \usewhitefig
\else%
\useblackfig\textsymfigsymbol{#2}\fi\fi%
\endgroup}

crafted. (Hint: I didn't get the \skaksymb command to still have the same name as the old one \textsymfigsymbol.)

enter image description here

\documentclass[12pt]{article}
\usepackage[margin=15mm]{geometry}
\usepackage[most]{tcolorbox}

\usepackage{chessfss} \usepackage{xskak} \usepackage{chessboard} \setchessboard{showmover=false}

%https://tex.stackexchange.com/questions/403947/chess-notation-switch-between-color-and-notation-style \makeatletter \def\cfssfixbaseline#1{\raisebox{-0.31ex}{\setboardfontsize{\f@size}#1}} \def\useblackfig{\def\cfss@figlanguage{@BLSB}} \def\usewhitefig{\def\cfss@figlanguage{@WLSB}} \def\cfss@king@@WLSB{\cfssfixbaseline{\cfss@WhiteKingOnWhite}} \def\cfss@queen@@WLSB{\cfssfixbaseline{\cfss@WhiteQueenOnWhite}} \def\cfss@rook@@WLSB{\cfssfixbaseline{\cfss@WhiteRookOnWhite}} \def\cfss@bishop@@WLSB{\cfssfixbaseline{\cfss@WhiteBishopOnWhite}} \def\cfss@knight@@WLSB{\cfssfixbaseline{\cfss@WhiteKnightOnWhite}} \def\cfss@pawn@@WLSB{\cfssfixbaseline{\cfss@WhitePawnOnWhite}} \def\cfss@king@@BLSB{\cfssfixbaseline{\cfss@BlackKingOnWhite}} \def\cfss@queen@@BLSB{\cfssfixbaseline{\cfss@BlackQueenOnWhite}} \def\cfss@rook@@BLSB{\cfssfixbaseline{\cfss@BlackRookOnWhite}} \def\cfss@bishop@@BLSB{\cfssfixbaseline{\cfss@BlackBishopOnWhite}} \def\cfss@knight@@BLSB{\cfssfixbaseline{\cfss@BlackKnightOnWhite}} \def\cfss@pawn@@BLSB{\cfssfixbaseline{\cfss@BlackPawnOnWhite}} % % https://tex.stackexchange.com/a/312066/46023 \def\instring#1#2{TT\fi\begingroup \edef\x{\endgroup\noexpand\in@{#1}{#2}}\x\ifin@} % \def\isuppercase#1{% \instring{#1}{ABCDEFGHIJKLMNOPRSTUVYZ}% }% \makeatother

\def\FirstArgX{text} \newcommand\skaksymb[2][]{\begingroup% \def\SecondArgX{#1}% \ifx\FirstArgX\SecondArgX \usetextfig\textsymfigsymbol{#2}\else% \if\isuppercase{#2}\textsymfigsymbol{#2}% \usewhitefig \else% \useblackfig\textsymfigsymbol{#2}\fi\fi% \endgroup}

\begin{document} \section{Old} \textsymfigsymbol{K}, \textsymfigsymbol{k}, \begingroup \usewhitefig\textsymfigsymbol{K} \useblackfig\textsymfigsymbol{p},
\textsymfigsymbol{N} \usewhitefig\textsymfigsymbol{R}, \usetextfig\textsymfigsymbol{R} \endgroup

\section{New} \begin{tcblisting}{notitle, sidebyside, boxrule=0.4pt} \skaksymb{K}, \skaksymb{k}, \skaksymb[text]{K} \end{tcblisting}

\section{In Text} ABC\skaksymb{K}abc\skaksymb{k}, \skaksymb[text]{k}

{\Huge ABC\skaksymb{K}abc\skaksymb{k}, \skaksymb[text]{k} }

{\footnotesize ABC\skaksymb{K}abc\skaksymb{k}, \skaksymb[text]{k}}

\section{In chess-annotation} \newchessgame[id=MyGame] \hidemoves{1.e4 e5 2. Nf3 Nc6 3. Bb5 Nf6 4. O-O Nxe4 5.Bxc6 bxc6 6. Kh1 Rg8 } %\printchessgame[id=MyGame, style=styleCx]

\xskaknewstyleitem[% template=UF,% a predefined style item beforewhite={\usewhitefig}, beforeblack={\useblackfig}, afterblack=\color{black}\hspace{1.25ex} ]{myitems}

\xskakaddtostyle[% font=\normalfont,% <--- he wants something here.... styleitem=myitems ]{test} %\printchessgame[id=MyGame, style=test]

\begin{tcbitemize}[sharp corners, raster equal height=rows, colback=white, raster column skip=0mm, boxrule=1.2pt, boxsep=1ex, ] \tcbitem[left=0pt] \chessboard[] \tcbitem[] \printchessgame[id=MyGame, style=test] \end{tcbitemize} \end{document}

cis
  • 8,073
  • 1
  • 16
  • 45