Permutation cycle notation

Here's a command that uses \; by default, but you can select another separator as you wish; for instance, I frequently use no separator when the set is “small” (up to 9, you see it in the second example):

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\cycle}{ O{\;} m }
 {
  (
  \alec_cycle:nn { #1 } { #2 }
  )
 }

\seq_new:N \l_alec_cycle_seq
\cs_new_protected:Npn \alec_cycle:nn #1 #2
 {
  \seq_set_split:Nnn \l_alec_cycle_seq { , } { #2 }
  \seq_use:Nn \l_alec_cycle_seq { #1 }
 }
\ExplSyntaxOff

\begin{document}
$\cycle{1,2,3}$

$\cycle[]{1,2,3}$

$\cycle[\quad]{1,2,3}$

$\cycle[,]{1,2,3}$

$\cycle[;]{1,2,3}$
\end{document}

enter image description here

Don't use $$ in LaTeX, see Why is \[ ... \] preferable to $$ ... $$?

Tags:

Spacing