Repository: sympy/sympy

Issue:
LaTex printing of Cycle
Currently
```
>>> from sympy.combinatorics.permutations import Cycle
>>> latex(Cycle(1, 2))
'\\left \\{ 1 : 2, \\quad 2 : 1\\right \\}'
```
That's something of latex for dictionary(`dict`). The LaTex should give the latex representation of `(1 2)`. i.e `latex(Cycle(1, 2))` should return the latex representation of `(1 2)`.

In IPython Notebook
```
>>> init_printing(use_unicode=True)
>>> Cycle(1, 2)
{0:0,1:2,2:1}
```
You can also see the discussion [here](https://github.com/sympy/sympy/pull/10183#issuecomment-162313211) on PR #10183 . Changes should be made to file `printing/latex.py`(mentioned by jksuom) This will be an "easy to fix" issue.

Discussion:
jksuom: I have not studied how this would appear on screen or paper, but does the ``\thinspace`` (``\,``) suffice to separate the numbers visually? Perhaps you could also test with ``\:`` or ``\;`` (``\medspace`` or ``\thickspace``).
gxyd: > does the \thinspace (\,) suffice to separate the numbers visually

Yes i think it does.
Here are the few tests [sympy1.pdf](https://github.com/sympy/sympy/files/62229/sympy1.pdf) 
In order with "/,"   ,   "/:"    and  "/;"   respectively.
jksuom: I am not quite convinced by these examples that involve only single digits. What would happen with two-digit numbers? (The line with ``\medspace`` looks also reasonable.)
gxyd: Here are some screenshots. I don't think my `LaTex` installation supports `\medspace` or `thickspace`. I tried with spacings mentioned on [this answer](http://tex.stackexchange.com/a/74354/88362) .
![screen_sympy_printing](https://cloud.githubusercontent.com/assets/7712241/11813250/55cc1410-a366-11e5-80f0-401c5b327001.png)

I think i like the `\enspace` printing. Since it ensures the adequate spacing.

jksuom: ``\enspace`` looks about twice the size of ``\medmuskip`` (given by ``\:`` or ``\>``) on my screen. It seems to me that it is more than adequate. Perhaps ``\medmuskip`` or ``\thickmuskip`` would suffice.
gxyd: I don't know how the `\thickmuskip` looks on printing(seems like my `LaTex`distribution does not support it). Though i have changed it to `\thickmuskip`. Plese have a look.
jksuom: ``\thinmuskip`` (thin math space), ``\medmuskip`` (medium math space) and ``\thickmuskip`` (thick math space) denote the *size* of the skip (they do not create it). They are defined in the TeXbook as follows.
``\thinskip=3mu``
``\medskip=4mu plus 2mu minus 4mu``
``\thickskip=5mu plus 5mu``
Here ``mu`` (math unit) is a unit of length depending on the font in use. (I think that it is usually one eighteenth of ``\em`` that is the size of the letter "m" in the font. The size of ``\enskip`` is one half ``\em``.)
``\medskip`` can stretch of shrink to adjust for the available space. It can vanish altogether. Hence it may be preferable to use ``\thickskip``.

These spaces do not appear explicitly in latex text. Instead, they are invoked by the commands ``\,``, ``\>`` and ``\;`` that are defined as follows (``\mskip`` will create the space).
``\def\,{\mskip\thinskip}``
``\def\>{\mskip\medskip}``
``\def\;{\mskip\thickskip}``

gxyd: Thanks for the detailed explanation. I am learning `LaTex` as well these days, though currently only know a few basics. I didn't knew these wide variety of horizontal space commands.
Though for the PR, i think is understood you comment and have made the changes. I think they also work ok on my system.
jksuom: Looks good. +1

Patch:
diff --git a/sympy/printing/latex.py b/sympy/printing/latex.py
index add4e9535a..041d395729 100644
--- a/sympy/printing/latex.py
+++ b/sympy/printing/latex.py
@@ -280,6 +280,19 @@ def _print_Add(self, expr, order=None):
 
         return tex
 
+    def _print_Cycle(self, expr):
+        from sympy.combinatorics.permutations import Permutation, Cycle
+        if str(expr) == '()':
+            return r"\left( \right)"
+        expr_perm = Permutation(expr).cyclic_form
+        term_tex = ''
+        for i in expr_perm:
+            term_tex += str(i).replace(',', r"\;")
+        term_tex = term_tex.replace('[', r"\left( ")
+        term_tex = term_tex.replace(']', r"\right)")
+        return term_tex
+
+    _print_Permutation = _print_Cycle
 
     def _print_Float(self, expr):
         # Based off of that in StrPrinter


Test patch:
diff --git a/sympy/printing/tests/test_latex.py b/sympy/printing/tests/test_latex.py
index f50b103c5e..eae99555e5 100644
--- a/sympy/printing/tests/test_latex.py
+++ b/sympy/printing/tests/test_latex.py
@@ -28,6 +28,7 @@
 from sympy.logic.boolalg import And, Or, Xor
 from sympy.core.trace import Tr
 from sympy.core.compatibility import range
+from sympy.combinatorics.permutations import Cycle, Permutation
 
 x, y, z, t, a, b = symbols('x y z t a b')
 k, m, n = symbols('k m n', integer=True)
@@ -128,6 +129,18 @@ def test_latex_builtins():
     assert latex(false) == r'\mathrm{False}'
 
 
+def test_latex_cycle():
+    assert latex(Cycle(1, 2, 4)) == r"\left( 1\; 2\; 4\right)"
+    assert latex(Cycle(1, 2)(4, 5, 6)) == r"\left( 1\; 2\right)\left( 4\; 5\; 6\right)"
+    assert latex(Cycle()) == r"\left( \right)"
+
+
+def test_latex_permutation():
+    assert latex(Permutation(1, 2, 4)) == r"\left( 1\; 2\; 4\right)"
+    assert latex(Permutation(1, 2)(4, 5, 6)) == r"\left( 1\; 2\right)\left( 4\; 5\; 6\right)"
+    assert latex(Permutation()) == r"\left( \right)"
+
+
 def test_latex_Float():
     assert latex(Float(1.0e100)) == r"1.0 \cdot 10^{100}"
     assert latex(Float(1.0e-100)) == r"1.0 \cdot 10^{-100}"