Is there a way to run a command on a range of consecutive integers (say, 11, 12, 13, 14, 15), specifying only the first and last numbers (11 and 15)? Basically I'm looking for the general LaTeX equivalent of tikz
's \foreach \x in {11,…,15}
.
In the MWE below (using etoolbox
), \forcsvlist\mycommand{11,12,13,14,15}
correctly runs \mycommand
on each of the four inputs, and \myrange{11}{15}
indeed expands to 11,12,13,14,15
. But putting them together \forcsvlist\mycommand{\myrange{11}{15}}
doesn't work. I think it comes down to order of expansion, which is way over my head.
\documentclass{article}
\usepackage{amsmath, etoolbox}
\newcommand\mycommand[1]{\boxed{#1} }
\newcounter{mycounter}
\newcommand\myrange[2]{
\defcounter{mycounter}{#1}
\themycounter%
\whileboolexpr
{test {\ifnumless{\themycounter}{#2}}}
{\stepcounter{mycounter},\themycounter}
}
\begin{document}
\forcsvlist\mycommand{11,12,13,14,15}
does not equal
\forcsvlist\mycommand{\myrange{11}{15}}
\end{document}
I've looked at Loop Multi-Contingency using etoolbox, Print all elements of a working array created with etoolbox package, and Remove extra curly braces, but couldn't figure out how to apply them to this situation.
\myrange
macro -- this can't be expandable. There might be more issues, but I can't check right now