The following is a command that does basic arithmetic with nine variables.
\documentclass{article}
\usepackage{xfp}
\newcommand\functesta[9]{
\edef\myvara{#1}
\edef\myvarb{#2}
\edef\myvarc{#3}
\edef\myvard{#4}
\edef\myvare{#5}
\edef\myvarf{#6}
\edef\myvarg{#7}
\edef\myvarh{#8}
\edef\myvari{#9}
$\inteval{\myvara + \myvarb - \myvarc + \myvard - \myvare + \myvarf - \myvarg + \myvarh - \myvari}$
}
\begin{document}
\functesta{1}{2}{3}{4}{5}{6}{7}{8}{100}
\end{document}
-94
I tried shrinking the nine lines of definition into one for loop but it didn't work. My intention was that as a loop iterates through 1 to 9, it would expand \alphalph{\iteration} first, which would be combined with \myvarx to become \myvarxa, \myvarxb, ..., \myvarxi. In the same way #\iteration would expand to #1 to #9. However I probably got the syntax wrong.
\documentclass{article}
\usepackage{xfp}
\usepackage{pgffor}
\usepackage{alphalph}
\newcommand\functestb[9]{
\foreach \iteration in {1,...,9} {
\edef\expandafter\myvarx\alphalph{\iteration}{#\iteration}
}
$\inteval{\myvarxa + \myvarxb - \myvarxc + \myvarxd - \myvarxe + \myvarxf - \myvarxg + \myvarxh - \myvarxi}$
}
\begin{document}
\functestb{1}{2}{3}{4}{5}{6}{7}{8}{100}
\end{document}
! Illegal parameter number in definition of \functestb.
Then I replaced #\iteration with a constant to see if I got the rest of the code right. Nope. What is the right way to achieve what I want? The reason I am not directly accessing #1 to #9 is because I will write a more complex command in which the nine numbers given need to be saved and changed multiple times. I am open to alternatives such as passing a list as a parameter or generating a list inside the command if it is possible to do so in LaTeX.
\documentclass{article}
\usepackage{xfp}
\usepackage{pgffor}
\usepackage{alphalph}
\newcommand\functestb[9]{
\foreach \iteration in {1,...,9} {
\edef\expandafter\myvarx\alphalph{\iteration}{17}
}
$\inteval{\myvarxa + \myvarxb - \myvarxc + \myvarxd - \myvarxe + \myvarxf - \myvarxg + \myvarxh - \myvarxi}$
}
\begin{document}
\functestb{1}{2}{3}{4}{5}{6}{7}{8}{100}
\end{document}
! Undefined control sequence.

