You're reading: Travels in a Mathematical World

nimsticks: LaTeX package for drawing Nim sticks and games

A while ago on this blog I shared a LaTeX macro I had written for drawing games of Nim. I have now taken the plunge and written this into a LaTeX package called nimsticks. (Why? What do you do to relax on a lazy Sunday morning?)

Here is the description of the nimsticks package:

This LaTeX package provides commands \drawnimstick to draw a single nim stick and \nimgame which represents games of multi-pile Nim. Nim sticks are drawn with a little random wobble so they look ‘thrown together’ and not too regular.

What this does it allows commands such as \nimgame{5,3,4} which renders like this:

Three Nim heaps: 5 sticks, 3 sticks and 4 sticks

To use this, you should just be able to install the package.

  • MiKTeX installs packages as it needs them. nimsticks has been added to the package directory for MiKTeX, so it should be sufficient to compile a LaTeX document which includes \usepackage{nimsticks} and MiKTeX will install the package for you.
  • TeX Live, by contrast, installs packages via tlmgr. You should be able to update your packages using tlmgr update --all. I had a problem with my manual TeX Live 2020 installation where sudo did not see tlmgr, which I fixed in a way I describe in this answer on askubuntu.
  • Failing all that, you can download nimsticks.sty and put it in the same folder as your LaTeX file, but much better to install it properly.

To check your installation (or to trigger it in MiKTeX), here is an example LaTeX document you could use:

\documentclass{article}
\usepackage{nimsticks}
\begin{document}
Here is a game of Nim: \nimgame{2,3,5,7,11}
\end{document}

Note on Overleaf: I investigated and it seems Overleaf is currently using TeX Live 2019 and doesn’t routinely update packages, so if you want to use nimsticks in Overleaf you’ll have to put nimsticks.sty in your Overleaf project alongside the main LaTeX file.

To write this package, I followed the instructions given by Matthew Scroggs in his post ‘realhats: Writing a $\LaTeX$ Package‘. Not that the work of this package is anything like as righteous and essential as realhats, of course.

nimsticks on the web:

One Response to “nimsticks: LaTeX package for drawing Nim sticks and games”

(will not be published)

$\LaTeX$: You can use LaTeX in your comments. e.g. $ e^{\pi i} $ for inline maths; \[ e^{\pi i} \] for display-mode (on its own line) maths.

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>