I'm typesetting some group theory notes, and a significant amount of it is cycles, i.e. \left(1\,2\,3\right). Is there a way of defining a command which takes a arbitrary number of arguments so I can write \cycle{1}{2}{3}?

2 Answers 2


You can use a comma-separated list to define your cycle:

enter image description here

\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
  \setcounter{totalcount}{0}% Reset total count
  \renewcommand*{\do}[1]{\stepcounter{totalcount}}% Reconfigure count
  \docsvlist{#1}% Count number of items
  \setcounter{listcount}{0}% Reset current item count
  \renewcommand*{\do}[1]{% Reconfigure item \do
    \stepcounter{listcount}% Next item
    ##1\ifnum\value{listcount}<\value{totalcount}\,\fi% Print item
  \left(\docsvlist{#1}\right)% Process list
\[ \cycle{1} \quad \cycle{1,2,3} \quad \cycle{1,1,2,3,5,8,13} \]

The command \do is redefined twice inside \cycle. The first time is for counting the number of items supplied, while the second time is for printing all the items.


A comma separated list notation is really recommended.


\NewDocumentCommand{\cycle}{m}{\cycle_main:n {#1}}

\seq_new:N \l_cycle_body_seq
\cs_new:Npn \cycle_main:n #1
  \seq_set_split:Nnn \l_cycle_body_seq {,} { #1 }
  \seq_pop_right:NN \l_cycle_body_seq \l_tmpa_tl
  \seq_map_inline:Nn \l_cycle_body_seq { ##1 \, }
  \tl_use:N \l_tmpa_tl

If really \left and \right are needed, which I don't believe as the argument should always be a list of numbers, then change the definition of \cycle into

\NewDocumentCommand{\cycle}{ s O{} m }
  \cycle_main:n { #3 }

that will allow a commonly used "fence" notation:

  • \cycle{1,2,3} for normal size parentheses
  • \cicle[\big]{1,2,3} for larger parentheses (any size prescribing command can be used
  • \cycle*{1,2,3} to enclose into \left( and \right).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.