\documentclass[a4paper]{article}
\usepackage{etoolbox}
\newcommand{\bigseqx}[3]{{#1_{#2}%
\count255=\numexpr#2\relax
\whileboolexpr{ test {\ifnumcomp{\count255}{<}{\numexpr#3\relax}}}
{\advance\count255 by 1 ,#1_{\number\count255 }}%
}}
\begin{document}
$\bigseqx{x}{3}{7}$
\end{document}
Some explanations. We use the \whileboolexpr
macro of etoolbox (there are other packages that offer similar functionality); it takes two arguments: the first one is a test introduced by the test
keyword, followed by the actual test, so we'll execute the code in the second argument as long as the test evaluates as true. But before starting this loop, we typeset the first element of the sequence and set a temporary counter to the second argument to \bigseqx
(the first one is the symbol for the variable). The code increments the counter and typesets a comma and the next subscripted variable. The test evaluates as false when the counter becomes equal to the third argument.
We set the temporary counter to a value computed by \numexpr
and use again \numexpr
for comparing the counter to the third argument, so input such as
\bigseqx{x}{\value{cnt}}{\value{cnt}+9}
(where cnt
is a LaTeX counter) is valid; \numexpr\value{cnt}+9\relax
evaluates the expression (and the \relax
token is swallowed because it's simply a terminator for the numeric expression).
Note: at the moment I wrote the answer I wasn't using expl3
.
It's even shorter with expl3
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\bigseqx}{mmm}
{
#1\sb{#2}
\int_step_inline:nnnn { #2+1 } { 1 } { #3 }
{
, #1\sb{##1}
}
}
\ExplSyntaxOff
\begin{document}
$\bigseqx{x}{3}{7}$
\end{document}
The idea is the same as above, but the working should be clearer: we print the first element, then a comma and the next element until we're finished. The key point is \int_step_inline:nnnn
that takes as arguments the starting point, the step, the final point and the action to perform, in which we can refer to the current value by #1
(it's ##1
because \int_step_inline:nnnn
is used in a definition). Each of the first three arguments can be an integer expression using any of the math facilities of expl3
.