I've been trying to modify the solution here into a LaTeX3 command that takes a variable length comma separated list of numbers and an optional argument (a unit) and prints the square root of the sum of the square of each number (along with the unit, if given).
\sumofsquares{2,3,-4}[m/s]
should give
but \sumofsquares{3,-4}[m/s]
should give
I've Googled for LaTeX3 examples but the ones I've found (documentation for xparse
and expl3
) don't contain any examples. The differences between lists and sequences mystifies me.
Best Answer
Here's an option using sequences, it could probably be made a little more compact as the code from the two helper macros is almost identical.
I'm not an expert so take my advice with a grain of salt but I would just stick with using
sequences
. They require an extra line of code here and there, but the additional options that they provide are well worth it.Here's a slightly shorter (and less clear) example using
clist
s. The same method could have been used to shorten the code above.