17

I would like to use a dice symbol such as those defined in Andrew Swann's answer, given to Dice symbols for digits up to 9, inside a math equation.

For instance, to model the set of results after a throw, I would like to write :

$$ \Omega = \{1, 2, 3, 4, 5, 6\} $$

Where each number is replaced by the corresponding dice symbol.

1
  • 5
    So why don't you do it then? \[ \Omega = \drawdie{0}, \drawdie{1}, \drawdie{3}... \]etc.
    – percusse
    Commented May 15, 2018 at 14:29

2 Answers 2

33

(31 Jan 2024: Updated the answer to mention that one more package -- fontawesome5 -- is listed in the Comprehensive LaTeX Symbol List.)

(29 June 2021: Updated the answer to mention that two more packages -- ifsym and utfsym -- provide macros that let users draw dice.)

According to the current (3 Jan 2024) edition of the Comprehensive LaTeX Symbol List, there are 6 packages that provide macros to draw dice: epsdice, hhcount, stix, ifsym, utfsym, and fontawesome5.

  • The first 5 packages let users draw black-on-white die symbols; in contrast, the fontawesome5 package provides macros to draw white-on-black die symbols.

  • Unfortunately, the customdice package, which is introduced in @PeterRowlett's answer, is not mentioned in the "Comprehensive LaTeX Symbol List" document.

Here's an example that makes use of the epsdice package.

enter image description here

\documentclass{article}
\usepackage{epsdice}
\begin{document}
\[
\Omega=\{ \epsdice{1}, \epsdice{2}, \epsdice{3}, 
          \epsdice{4}, \epsdice{5}, \epsdice{6} \}
\]
\end{document}

Addendum to address the OP's follow-up query: To align the die symbols on the math axis, you could encase them in \vcenter{\hbox{...}} "wrappers".

enter image description here

\documentclass{article}
\usepackage{epsdice}
\newcommand\vcdice[1]{\vcenter{\hbox{\epsdice{#1}}}}
\begin{document}
\[
\Omega=\{ \vcdice{1}, \vcdice{2}, \vcdice{3}, 
          \vcdice{4}, \vcdice{5}, \vcdice{6} 
       \}
\]
\end{document}

2nd addendum: If you're free to use LuaLaTeX, you could use a Lua for loop to generate all 6 die symbols programmatically. This functionality may not seem like a big deal if just 6 symbols need to be generated. Naturally, it's a lot more relevant for use cases that involve a dozen or more calls to the same macro.

% !TEX program = lualatex
\documentclass{article}
\usepackage{epsdice}
\newcommand\vcdice[1]{\vcenter{\hbox{\epsdice{#1}}}}
\begin{document}
\[
  \Omega = \{ 
     \directlua{ for i=1,6 do 
                    tex.sprint ( "\\vcdice{" .. i .. "}" ) 
                    if i<6 then tex.sprint "," end
                 end }
            \}
\]
\end{document}
1
  • 1
    I have contacted the maintainer of the Comprehensive LaTeX Symbol List to make him aware of customdice. I'm not sure whether it will be included because it uses TikZ rather than a font and because it is so customisable it is capable of drawing very many dice face variants. We'll see! Commented Feb 1 at 19:19
7

I recently wrote a dice package customdice that can do this.

The command to draw standard dice is \dice{n}. The content inside the {...} looks to me like it is sitting below the line, because it is in line with the surrounding text and the {...} part is below the line. In the customdice package, I provided a command \setdicebaseline{} which can be increased from its default of 0.02 to lower the drawing. Via trial and error, I came to think 0.2 looked okay. This is demonstrated below.

\documentclass{article}
\usepackage{customdice}
\begin{document}
    \[ \Omega =  \{\dice{1},\dice{2},\dice{3},\dice{4},\dice{5},\dice{6}\} \]
    \setdicebaseline{0.2}
    \[ \Omega =  \{\dice{1},\dice{2},\dice{3},\dice{4},\dice{5},\dice{6}\} \] 
\end{document}

This produces output like this

omega = { dice faces showing 1 to 6 dots}

There are various options within the package to customise the size and colour of the dice faces.

You would need to \setdicebaseline{0.02} if you later want to use \dice inline with regular text.

Actually, I would probably prefer to reduce the amount of code needed to produce the equation by writing a little loop in a command I've called \drawdice, like this.

\documentclass{article}
\usepackage{customdice}
\newcounter{num_dice}
\newcommand{\drawdice}[1]{%
    % count the items
    \foreach \i in {#1}{%
        \setcounter{num_dice}{\i}
    }%
    % draw a dice for each
    \foreach \i in {#1}{%
        \dice{\i}%
        \ifnum\i<\value{num_dice}% include a comma if it's not the last one
            ,%
        \fi%
    }
}
\begin{document}
    \setdicebaseline{0.2}
    
    \[ \Omega = \{\drawdice{1,2,3,4,5,6}\}  \]
    
    \[ \Omega = \{\drawdice{1,3,5,6,8}\}  \]
    
    \[ \Omega = \{\drawdice{2,4,6}\}  \]
    
    \[ \Omega = \{\drawdice{6}\}  \]
\end{document}

Which produces

Various omegas with different numbers of dice

3
  • 2
    This is very nice! It is unrelated, but you should use \[...\] rather than $$...$$.
    – Vincent
    Commented Aug 11, 2022 at 14:33
  • Yes agreed, and I usually do. Here I thought it was best to follow the lead of the OP and not complicate my answer. Commented Aug 11, 2022 at 17:21
  • I see my answer has been edited by @egreg to change $$...$$ to \[...\]! I would use \[...\] myself; as I said in a previous comment my approach here was to follow the lead of the OP on something where one approach is preferable but not required. Still, I don't mind really. Commented Feb 1 at 19:07

You must log in to answer this question.

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