1

My command \angles defined with \def will not give the same result. I would like to define this command with expansion at definition time, so using \edef. The MWE shows that \def only compiles, but \edef bugs.

What to do to get \edef works so that \angles will always return the same result ? Any help would be appreciated.

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\setlength\parindent{0pt}

\begin{document}

\def\na{ \fpeval{ randint(2,8) } } \def\angles {\foreach \k in {0,...,\na}{ \fpeval{45(\k)} }} % works %\edef\listcoords{\foreach \k in {0,...,\na}{ \fpeval{45(\k)} }} % bugs

\angles\ % those gives different results \angles\ % because of \def \angles\ % instead of \edef

\end{document}

  • 1
    you can use \fpeval in an \edef, as it is expandable, but you can't use \foreach. Something like \def\listcoords{}\foreach \k in {0,...,\na}{ \xdef\listcoords{\listcoords\fpeval{45*(\k)} }} would work, but generally you should perhaps at first try to understand expansion better before throwing \edef on all sort of things. See e.g. https://tex.stackexchange.com/a/66168/2388 – Ulrike Fischer Feb 26 '23 at 18:19
  • Thank you @Ulrike, that's right that i need to understand expansion better, which is not a small challenge! – mathteacher Feb 26 '23 at 18:57

0 Answers0