# Tagging an equation with a tikz duck

I would like to label and equation with a tikz duck from the tikzducks package and refer back to it later, like so:

The obvious solution:

\usepackage{tikz}
\usepackage{tikzducks}
\usepackage{amsmath}

\section*{Question 1}
\begin{enumerate}[(a)]
\item

$a^{2} + b^{2} = c^{2} \tag{\begin{tikzpicture}[scale=0.2] \duck \end{tikzpicture}} \label{C}$

From equation $$\eqref{C}$$, $b^{2} = c^{2} - a^{2}$.

\end{enumerate}

gives me the error: TeX capacity exceeded, sorry [input stack size=5000]. However when I put the duck elsewhere in the image, I do not get this error, the document compiles and I get to see my duck (quack)!

(I might add that it doesn't matter whether or not the tikzpicture environment is placed inside math mode or not.)

I can't seem to find a way to stop this error from happening.

Thanks for looking at my question.

• Please extend your example to something that ought to compile. There is no document class, no document env. Also $$\eqref{C}$$, does not make any sense. What are you trying to do here? – daleif Mar 31 at 8:18
• I have no issues once I added something that supports \begin{enumerate}[(a)] – daleif Mar 31 at 8:22
• Sorry I am a new user, should I copy and paste my whole preamble or just enough so that it complies? – Damian Lin Mar 31 at 8:37
• This is a good guide: tex.meta.stackexchange.com/questions/228/…, you should always seek to provide something that others can just copy and test as is without having to add something. What you post should also be self contained (no images or files we don't have access to, one can always use the images that comes with the mwe package, see CTAN). It should also be minimal, thus only the package that are relevant for your problem. – daleif Mar 31 at 8:52
• Thanks for the help, I will read this for next time I post. The comment below solved my problem when I use xparse instead. – Damian Lin Mar 31 at 9:21

\documentclass{article}
\usepackage{tikz}
\usepackage{tikzducks}
\usepackage{amsmath}
\usepackage{xparse}
\usepackage{enumerate}
\NewDocumentCommand\ducktag{}
{%
\begin{tikzpicture}[scale=0.2]
\duck
\end{tikzpicture}%
}
\begin{document}
\section*{Question 1}
\begin{enumerate}[(a)]
\item

$a^{2} + b^{2} = c^{2} \tag{\ducktag} \label{C}$

From equation \eqref{C}, $b^{2} = c^{2} - a^{2}$.

\end{enumerate}

\end{document}

You could also add an argument for options:

\documentclass{article}
\usepackage{tikz}
\usepackage{tikzducks}
\usepackage{amsmath}
\usepackage{xparse}
\usepackage{enumerate}
\NewDocumentCommand\ducktag{m}
{%
\begin{tikzpicture}[scale=0.2]
\duck[#1]
\end{tikzpicture}%
}
\begin{document}
\section*{Question 1}
\begin{enumerate}[(a)]
\item

$a^{2} + b^{2} = c^{2} \tag{\ducktag{}} \label{B}$

From equation \eqref{C}, $b^{2} = c^{2} - a^{2}$.

\item

$a^{2} + b^{2} = c^{2} \tag{\ducktag{body=blue}} \label{C}$

From equation \eqref{C}, $b^{2} = c^{2} - a^{2}$.

\item

$a^{2} + b^{2} = c^{2} \tag{\ducktag{body=red}} \label{D}$

From equation \eqref{B}, \eqref{C} and \eqref{D} $b^{2} = c^{2} - a^{2}$.
\end{enumerate}

\end{document}

• Paulo will be so proud – daleif Mar 31 at 8:36
• Somehow this fixes things. Thanks. – Damian Lin Mar 31 at 9:20
• @DamianLin if you want to refer to a tag, it has to be written to the aux-file. And this means that the command must be "robust". \NewDocumentCommand creates such robust commands. – Ulrike Fischer Mar 31 at 9:22
• @daleif oh, you are right, it works then too, I corrected the enumerate error later, after I created already the robust command (but I think it is a good idea anyway not to put large bunches of code inside \tag). – Ulrike Fischer Mar 31 at 9:31
• THIS IS AWESOME – Paulo Cereda Mar 31 at 9:35