After receiving a nice answer to a previous question, I got enthousiastic and tried to create a macro \sum such that \sum<1+2+3> would be expanded into 6.
My idea was to work recursively, using the parsing functionality of \def. For instance, the following code outputs "7+6+5"
\documentclass{article} \def\sumtestX<#1+#2>{\ifx\empty#2{#1}\else{\sumtestX<#2>+#1 }\fi} \def\sumtest<#1>{\sumtestX<#1+\empty>} \begin{document} \sumtest<5+6+7> \end{document} So one would expect that turning the "+" into a real "sum" would calculate the actual sum. Nevertheless, the following code doe not work.
\documentclass{article} \def\sum#1+#2{\the\numexpr#1+#2\relax} \def\sumtestX<#1+#2>{\ifx\empty#2{#1}\else{\sum\sumtestX<#2>+#1 }\fi} \def\sumtest<#1>{\sumtestX<#1+\empty>} \begin{document} \sumtest<5+6+7> \end{document} "Missing number, treated as zero" !? What's wrong?