I need to randomly change which symbol is attached to a particular command every time I compile my script.
I had hoped that this would be possible using the pgffor package, as in the minimal example below (where I am trying to redefine \add each time I compile):
\documentclass{article}
\usepackage{fdsymbol}
\usepackage{pgffor}
\newcommand{\add}{\medtriangleright}
\pgfmathsetseed{\number\pdfrandomseed}
\begin{document}
\pgfmathdeclarerandomlist{choices}{{\renewcommand{\add}{\pm}}{\renewcommand{\add}{+}}{\renewcommand{\add}{\cdot}}}
\foreach\x in {1}{
\pgfmathrandomitem{\choice}{choices}
\choice\space
}
$$5\add4$$
\end{document}
However this doesn't work. This is strange as this precise code works fine when I try to generate a random number from a list:
\documentclass{article}
\usepackage{fdsymbol}
\usepackage{pgffor}
\newcommand{\add}{\medtriangleright}
\pgfmathsetseed{\number\pdfrandomseed}
\begin{document}
\pgfmathdeclarerandomlist{choices}{{1}{2}{3}}
\foreach\x in {1}{
\pgfmathrandomitem{\choice}{choices}
\choice\space
}
$$5\add4$$
\end{document}
Any ideas what I'm doing wrong here? Thanks in advance.


\foreachloop? It doesn't seem to do anything in your example. – David Purton Oct 27 '18 at 11:59\[ …\]instead of$$ … $$for display maths. See https://tex.stackexchange.com/q/503/87678 – David Purton Oct 27 '18 at 12:07\foreachbit was because I was editing some other code where it was needed and didn't spot the redundancy before posting. Sorry for the confusion. – Matthew Oct 27 '18 at 20:07