9

How do you nicely denote a permutation via cycle notation? Ie, the cycle

\[1 \mapsto 2 \mapsto 3 \mapsto 1\]

can be done by something like:

\[ (1\quad2\quad3) \]

using \quad, but that seems like a bit too much spacing.

Can I do something better?

edit: Wasn't aware of \; -- that works well.

  • There is a permute package which you can use. – DJP Oct 1 '13 at 1:16
  • I suggest using \[<content>\] instead of $$<content>$$. – azetina Oct 1 '13 at 1:17
  • Maybe \quad is too much and \[(a_1\ a_2\ a_3\ \ldots\ a_k)\] would then translate into \[(1\ 2\ 3)\]. – azetina Oct 1 '13 at 1:24
  • Perhaps $\aoverbrace[L1R]{a_1\ a_2\ \cdots\ a_k}$ with abraces. – Werner Oct 1 '13 at 1:52
  • For math spacing, you could try \; which is not quite as much as a quad (and \, for finer spacing). – Alex Nelson Oct 1 '13 at 4:31
8

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 $$ ... $$?

1

Old post, but this has been bothering me so I threw something together that I don't completely understand. In particular, I don't get why two curly braces ("{{") are needed to open and close the definition -- I guess something to do with the nested definition. I was inspired by egreg's answer, but I don't understand the expl3 (?) stuff and anyway it seems way too complicated. Fortunately egreg himself has an alternative in this answer. FYI, I shortened the function name and I prefer spaces instead of commas when entering the source ( \cyc{1 2 3} instead of \cyc{1,2,3} ).

\documentclass[a4paper]{article}
\usepackage{xparse}
\begin{document}

\newif\iffirstitem
\firstitemtrue

% \cyc[optional joiner]{space separated list}
% write list in permutation cycle notation with joiner between
% elements, defaulting to \;
\NewDocumentCommand \cyc { O{\;} >{\SplitList{ }} m }
    {{%
        \NewDocumentCommand{\processfoo}{ m }
            {
                \iffirstitem
                    \firstitemfalse
                \else
                    #1
                \fi
                ##1
            }
        (\ProcessList{#2}{\processfoo})
        \firstitemtrue
    }}

$\cyc[]{1 2 3}$

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

$\cyc{1 2 3}$

$\cyc[\quad]{1 2 3}$

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

$\cyc[;]{1 2 3}$

\end{document}
1

Trivial with the listofitems parser.

\documentclass{article}
\usepackage{listofitems}
\newcommand\cycle[2][\,]{%
  \readlist\thecycle{#2}%
  (\foreachitem\i\in\thecycle{\ifnum\icnt=1\else#1\fi\i})%
}
\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

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.