This is not a timely answer, and I see there are already two (!) pgffor answers, one of them also using pgfkeys, but I want to suggest a more compact alternative construction along those lines.
\documentclass{article}
\usepackage{pgfkeys,pgffor,amsmath}
\pgfkeys{
/sequence/.is family, /sequence,
default/.style = {
start at/.initial = 1,
through/.initial = 1,
index/.initial = n,
variable/.initial = a,
},
utility/end sequence/.code = {${}\dots+\pgfkeysalso{variable}_{\pgfkeysalso{index}}$},
utility/loop/.code = {$\pgfkeysalso{variable}_{#1}+$},
utility/do prefix/.style =
{utility/loop/.list =
{\pgfkeysvalueof{/sequence/start at},...,\pgfkeysvalueof{/sequence/through}}
},
}
\newcommand\Sequence[1][]{%
\pgfkeys{/sequence, default, #1, utility/do prefix, utility/end sequence}%
}
\begin{document}
\Sequence
\Sequence[through = 3]
\Sequence[index = m]
\Sequence[variable = x]
\Sequence[start at = 0]
\Sequence[start at = -2, through = 3, variable = A^2, index = k]
\end{document}
I use the pgfkeys handler .list to do the looping; this avoids having to write any explicit code at all. For the unfamiliar: <key>/.list = {<list of values>} simply calls <key> = <value> repeatedly for each <value> in <list of values>, and uses the \foreach syntax for ranges (actually, it uses \foreach internally).
Some experimentation with \pgfkeysalso and \pgfkeysvalueof showed that just writing \pgfkeysalso{variable} (for example) was sufficient to get the value of /sequence/variable typeset, but not in an expandable way. \pgfkeysvalueof is expandable, and the list in \foreach needs to be expandable, hence the awkward change of style there.
My \Sequence also takes key-value arguments rather than possibly-unclear braced arguments and provides a default that (in my professional opinion) most mathematicians would consider the reasonable one. Of course, you can just change default/.style to what you think is reasonable.
...be also printed like shown or all terms without the dots? – Martin Scharrer Apr 01 '11 at 15:12