4

I was drawing my set of dice, like the following code:

\documentclass{article}
\usepackage   {ifthen}
\usepackage   {tikz}

\tikzset% {% pics/die/.style={% code={% \begin{scope}[x=1ex,y=1ex] \draw[line width=0.15ex,rounded corners=0.3ex] (-0.75,-0.75) rectangle (0.75,0.75); \ifthenelse{#1 > 3} {% \fill (-0.4, 0.4) circle (0.15); % top left dot \fill ( 0.4,-0.4) circle (0.15); % bottom right dot }{}% do nothing \ifthenelse{#1 > 1} {% \fill ( 0.4, 0.4) circle (0.15); % top right dot \fill (-0.4,-0.4) circle (0.15); % bottom left dot }{} \ifthenelse{#1 = 6} {% \fill (-0.4,0) circle (0.15); % center left dot \fill ( 0.4,0) circle (0.15); % center right dot }{} \ifthenelse{#1 = 1 \OR #1 = 3 \OR #1 = 5}{\fill (0,0) circle (0.15);}{} % center dot \end{scope} }} }

\begin{document} \huge

\foreach\i in {1,...,6}{\tikz \pic[red] {die={\i}};,}

Snake Eyes: \tikz\pic {die={1}}; \tikz\pic {die={1}};

Fever Five: \tikz\pic {die={4}}; \tikz\pic {die={1}}; \end{document}

enter image description here

My question is whether it would be possible to assign a character to each die so that you could select it as text in the pdf. I want, for example, to select the 'Fever Five: [die 4] [die 1]' line in the pdf, and copy-paste in another document as 'Fever Five: 4 1'.

I know that there are unicode characters for this purpose, and probably many packages that can do the same, but I want to do it this way (if possible).

Juan Castaño
  • 28,426
  • You might be interested in the accsup package. See e.g. https://tex.stackexchange.com/a/41688/82917 – campa Jul 10 '21 at 10:10
  • @campa, it looks promising, but if I write \BeginAccSupp{ActualText={1}} \tikz \pic {die={1}}; \EndAccSupp{} I can't select the die in the generated pdf. It works with \BeginAccSupp{ActualText={1}}2\EndAccSupp{} though. It probably accepts only text? – Juan Castaño Jul 10 '21 at 10:40

1 Answers1

4

What about using a trick?

Write transparent but copiable text behind your dice.

\documentclass{article}
\usepackage{ifthen}
\usepackage{tikz}
\usepackage{transparent}

\tikzset% {% pics/die/.style={% code={% \begin{scope}[x=1ex,y=1ex] \draw[line width=0.15ex,rounded corners=0.3ex] (-0.75,-0.75) rectangle (0.75,0.75); \ifthenelse{#1 > 3} {% \fill (-0.4, 0.4) circle (0.15); % top left dot \fill ( 0.4,-0.4) circle (0.15); % bottom right dot }{}% do nothing \ifthenelse{#1 > 1} {% \fill ( 0.4, 0.4) circle (0.15); % top right dot \fill (-0.4,-0.4) circle (0.15); % bottom left dot }{} \ifthenelse{#1 = 6} {% \fill (-0.4,0) circle (0.15); % center left dot \fill ( 0.4,0) circle (0.15); % center right dot }{} \ifthenelse{#1 = 1 \OR #1 = 3 \OR #1 = 5}{\fill (0,0) circle (0.15);}{} % center dot \end{scope} }} }

\newlength{\lungnum} \newcommand{\dado}[2][black]{\settowidth{\lungnum}{#2}\texttransparent{0}{#2}\hspace{-\lungnum}\tikz{\pic[#1] {die={#2}};}}

\begin{document} \huge

\foreach\i in {1,...,6}{\dado[red]{\i},}

Snake Eyes: \dado{1} \dado{1}

Fever Five: \dado{4} \dado{1}

\end{document}

Copy-pasting the resulting pdf:

enter image description here

You get:

1 2 3 4 5 6
Snake Eyes: 1 1
Fever Five: 4 1

As Juan suggested, it works also using hidden nodes with transparent text (opacity=0). In this case, you don't even have to load transparent package:

\documentclass{article}
\usepackage{ifthen}
\usepackage{tikz}

\tikzset% {% pics/die/.style={% code={% \begin{scope}[x=1ex,y=1ex] \draw[line width=0.15ex,rounded corners=0.3ex] (-0.75,-0.75) rectangle (0.75,0.75); \ifthenelse{#1 > 3} {% \fill (-0.4, 0.4) circle (0.15); % top left dot \fill ( 0.4,-0.4) circle (0.15); % bottom right dot }{}% do nothing \ifthenelse{#1 > 1} {% \fill ( 0.4, 0.4) circle (0.15); % top right dot \fill (-0.4,-0.4) circle (0.15); % bottom left dot }{} \ifthenelse{#1 = 6} {% \fill (-0.4,0) circle (0.15); % center left dot \fill ( 0.4,0) circle (0.15); % center right dot }{} \ifthenelse{#1 = 1 \OR #1 = 3 \OR #1 = 5}{\fill (0,0) circle (0.15);}{} % center dot \end{scope} }} }

\newlength{\lungnum} \newcommand{\dado}[2][black]{\tikz{\node[opacity=0,inner sep=0cm]{#2};\pic[#1] {die={#2}};}}

\begin{document} \huge

\foreach\i in {1,...,6}{\dado[red]{\i},}

Snake Eyes: \dado{1} \dado{1}

Fever Five: \dado{4} \dado{1}

\end{document}

Obviously, you can insert the node with opacity=0 directly in your pic and don't change anything of the rest of your code:

\documentclass{article}
\usepackage   {ifthen}
\usepackage   {tikz}

\tikzset% {% pics/die/.style={% code={% \begin{scope}[x=1ex,y=1ex] \node[opacity=0,inner sep=0cm]{#1}; \draw[line width=0.15ex,rounded corners=0.3ex] (-0.75,-0.75) rectangle (0.75,0.75); \ifthenelse{#1 > 3} {% \fill (-0.4, 0.4) circle (0.15); % top left dot \fill ( 0.4,-0.4) circle (0.15); % bottom right dot }{}% do nothing \ifthenelse{#1 > 1} {% \fill ( 0.4, 0.4) circle (0.15); % top right dot \fill (-0.4,-0.4) circle (0.15); % bottom left dot }{} \ifthenelse{#1 = 6} {% \fill (-0.4,0) circle (0.15); % center left dot \fill ( 0.4,0) circle (0.15); % center right dot }{} \ifthenelse{#1 = 1 \OR #1 = 3 \OR #1 = 5}{\fill (0,0) circle (0.15);}{} % center dot \end{scope} }} }

\begin{document} \huge

\foreach\i in {1,...,6}{\tikz \pic[red] {die={\i}};,}

Snake Eyes: \tikz\pic {die={1}}; \tikz\pic {die={1}};

Fever Five: \tikz\pic {die={4}}; \tikz\pic {die={1}}; \end{document}

CarLaTeX
  • 62,716