9

I want to put chess symbols inline in my document. I know that, using skak, I can produce nice looking inline symbols with commands like \symking, etc. However, these are only white, and I need white and black pieces. The skak package also provides commands like \WhiteKingOnWhite and \BlackKingOnWhite, which look nice, but are way too big. I cannot find a way to resize them (I tried using the built-in \small command, as well as packages like smaller and relzise). I also looked at using commands like \Pisymbol{fselch}{x}, where x is an integer, from a package I found called bartel-chess-fonts, but it looks like this isn't included with TeXLive, and I don't want to mess with installing additional packages. Lastly, I tried \char"xxxx, where xxxx is the unicode specifier corresponding to the desired piece, but I get an error ! Bad character code (9812) (not sure if this is relevant, but 9812 is the HTML code for the white king, which is the piece whose unicode representation I was trying to use when I got the error). What else can I try?

An acceptable answer may consist of one of the following:

  1. A method for resizing the skak symbols given by \ColorPieceOnWhite,
  2. A suggestion of another package included in TeXLive which can give me inline chess pieces,
  3. A solution to the ! Bad character code (9812) error,

or something else which can give me the result I am looking for.

Minimal Working Example:

\documentclass{article}
\usepackage{skak}

\begin{document}

This king \WhiteKingOnWhite is way too big.
This king {\small\WhiteKingOnWhite} won't resize.
This king \symking is only available in white.
%This unicode king $\char"2654$ throws an error when uncommented.

\end{document}
2

4 Answers 4

9

Scale the big sizes (to take on the vertical footprint of "Xg").

\documentclass{article}
\usepackage{skak,scalerel}
\begin{document}
\scalerel*{\WhiteKingOnWhite}{Xg} and \scalerel*{\BlackKingOnWhite}{Xg}
\end{document}

enter image description here

2
  • That worked! Out of curiosity, is it important that it be "Xg?"
    – The Ledge
    Commented Jan 3, 2021 at 15:38
  • 2
    @TheLedge No. It can be anything that has a vertical footprint. I use Xg when I want to maximize the extent, without exceeding the line height. You could even go larger with \strut, or smaller with simply X. Commented Jan 3, 2021 at 16:45
7

I'm not sure if this answer your question, but using XeTeX or LuaTeX including chess symbols (range U+2654-U+265F) is as easy as copy-pasting them. Obviously you'll need a font with proper support (I chose DejaVu Sans):

\documentclass{standalone}
\usepackage{fontspec}
\newfontfamily{\chessfont}{DejaVu Sans}
\begin{document}
{%
\chessfont%
\char"265A %♚
\char"265B %♛
\char"265C %♜
\char"265D %♝
\char"265E %♞
\char"265F %♟︎
}
\end{document}

enter image description here

2
  • I get an error saying that fontspec is not compatible with pdflatex, which is what I use. Do you know if there is something similar for LaTeX?
    – The Ledge
    Commented Jan 3, 2021 at 15:35
  • 1
    See Ulrike's answer. Unfortunately pdfTeX has a limited font repertoire
    – user226564
    Commented Jan 3, 2021 at 15:52
6

I know only of one font prepared for pdflatex which provides black figurines, Berlin. But it is not in texlive (due to licence reasons) only on ctan (in the enpassant package) and in miktex.

You can change the size of the board font with \setboardfontsize:

\documentclass{article}
\usepackage{chessfss}
\begin{document}
{\setfigfontfamily{berlin}
 \figfont KQRBNP \fontshape{bl}\selectfont KQRBNP}

\bigskip

\BlackKingOnWhite \setboardfontsize{10pt} \BlackKingOnWhite

\end{document}

enter image description here

As an alternative you could create pictures of the various figurines (e.g. by using lualatex, standalone and one of the open type fonts which has the symbols), and then use them with a faked font encoding:

\documentclass{article}
\usepackage{chessfss,graphicx}

\makeatletter 
\DeclareFontEncoding{LSFI}{}{}
\DeclareFontFamily{LSFI}{skaknew}{}
\DeclareFontSubstitution{LSFI}{skaknew}{m}{n}
\DeclareFontShape{LSFI}{skaknew}{m}{n}{<-> SkakNew-Figurine}{}

\DeclareTextCommand\cfss@symrook  {LSFI}{\includegraphics[height=1em,page=1]{example-image-duck}}{}
\DeclareTextCommand\cfss@symknight {LSFI}{\includegraphics[height=1em,page=2]{example-image-duck}}
\DeclareTextCommand\cfss@symbishop {LSFI}{\includegraphics[height=1em,page=3]{example-image-duck}}
\DeclareTextCommand\cfss@symqueen  {LSFI}{\includegraphics[height=1em,page=4]{example-image-duck}}
\DeclareTextCommand\cfss@symking   {LSFI}{\includegraphics[height=1em,page=5]{example-image-duck}}
\DeclareTextCommand\cfss@sympawn   {LSFI}{\includegraphics[height=1em,page=6]{example-image-duck}}

\newcommand\LSFIchess{\def\cfss@figfontencoding{LSFI}}

\makeatother

\usepackage[T1]{fontenc}
\begin{document}
{\LSFIchess\symking\symqueen\symrook\symbishop\symknight\sympawn}

\symqueen \symking\symqueen\symrook\symbishop\symknight\sympawn

\LARGE

{\LSFIchess\symking\symqueen\symrook\symbishop\symknight\sympawn}

\symqueen \symking\symqueen\symrook\symbishop\symknight\sympawn

\end{document}

enter image description here

3

There is also the skaknew font that provides black pieces. It is included in TeX Live/on CTAN. The pieces are encoded as latin letters after a font switch. The white pieces are uppercase and the corresponding black piece is the same letter lower case.

The standard position is a bit above the baseline (because the pieces are intended to be placed on a board), you can lower that with \raisebox from the graphicx package if required.

Example:

\documentclass{article}
\usepackage[skaknew]{skak}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\font\skndia=SkakNew-DiagramT
\begin{document}
Above the baseline: \bgroup\skndia K\egroup\ and \bgroup\skndia k\egroup

All black pieces: \bgroup\skndia bknpqr\egroup

A bit lower: \raisebox{-2pt}{\bgroup\skndia K\egroup} and \raisebox{-2pt}{\bgroup\skndia k\egroup}

All black pieces: \raisebox{-2pt}{\bgroup\skndia bknpqr\egroup}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .