Repository: sympy/sympy
Pull request: Resolves RecursionError in latex representation
fixes #13559. It was due to factor of `1/1`  
```python
expr = parse_expr('5/1', evaluate=False)
expr.args
```
it gives `(5 , 1/1)` , which was not handled properly in latex conversion . So everytime an expression was divided by 1 , it resulted in RecursionError

Problem statement:
LaTeX representation raises RecursionError
LaTeX representation of an expression that has division by 1 causes `RecursionError`. SymPy version: 1.1.1.

Code to reproduce the bug:
```python
from sympy import latex
from sympy.parsing.sympy_parser import parse_expr

expr = parse_expr('2/1', evaluate=False)
latex(expr)
```
Output:
```
...

~/.virtualenvs/sympy/lib/python3.5/site-packages/sympy/printing/printer.py in _print(self, expr, *args, **kwargs)
    255                 printmethod = '_print_' + cls.__name__
    256                 if hasattr(self, printmethod):
--> 257                     return getattr(self, printmethod)(expr, *args, **kwargs)
    258             # Unknown object, fall back to the emptyPrinter.
    259             return self.emptyPrinter(expr)

~/.virtualenvs/sympy/lib/python3.5/site-packages/sympy/printing/latex.py in _print_Pow(self, expr)
    466         elif expr.exp.is_Rational and expr.exp.is_negative and expr.base.is_commutative:
    467             # Things like 1/x
--> 468             return self._print_Mul(expr)
    469         else:
    470             if expr.base.is_Function:

~/.virtualenvs/sympy/lib/python3.5/site-packages/sympy/printing/latex.py in _print_Mul(self, expr)
    396             # use the original expression here, since fraction() may have
    397             # altered it when producing numer and denom
--> 398             tex += convert(expr)
    399         else:
    400             snumer = convert(numer)

~/.virtualenvs/sympy/lib/python3.5/site-packages/sympy/printing/latex.py in convert(expr)
    366         def convert(expr):
    367             if not expr.is_Mul:
--> 368                 return str(self._print(expr))
    369             else:
    370                 _tex = last_term_tex = ""

... last 4 frames repeated, from the frame below ...

~/.virtualenvs/sympy/lib/python3.5/site-packages/sympy/printing/printer.py in _print(self, expr, *args, **kwargs)
    255                 printmethod = '_print_' + cls.__name__
    256                 if hasattr(self, printmethod):
--> 257                     return getattr(self, printmethod)(expr, *args, **kwargs)
    258             # Unknown object, fall back to the emptyPrinter.
    259             return self.emptyPrinter(expr)

RecursionError: maximum recursion depth exceeded in comparison
```

Hints from issue discussion:

Commit message: added tests for changes in latex

Patch to review:
diff --git a/sympy/printing/latex.py b/sympy/printing/latex.py
index 51c1e67f2a1e..dab13173fbb7 100644
--- a/sympy/printing/latex.py
+++ b/sympy/printing/latex.py
@@ -372,6 +372,7 @@ def _print_Gradient(self, expr):
         return r"\nabla\cdot %s" % self.parenthesize(func, PRECEDENCE['Mul'])
 
     def _print_Mul(self, expr):
+        from sympy.parsing.sympy_parser import parse_expr
         include_parens = False
         if _coeff_isneg(expr):
             expr = -expr
@@ -415,12 +416,9 @@ def convert(expr):
                     _tex += term_tex
                     last_term_tex = term_tex
                 return _tex
+        one_by_one =  parse_expr('1/1', evaluate=False)
 
-        if denom is S.One:
-            # use the original expression here, since fraction() may have
-            # altered it when producing numer and denom
-            tex += convert(expr)
-        else:
+        if not denom is S.One or one_by_one in expr.args:
             snumer = convert(numer)
             sdenom = convert(denom)
             ldenom = len(sdenom.split())
@@ -459,6 +457,11 @@ def convert(expr):
             else:
                 tex += r"\frac{%s}{%s}" % (snumer, sdenom)
 
+        elif denom is S.One:
+            # use the original expression here, since fraction() may have
+            # altered it when producing numer and denom
+            tex += convert(expr)
+
         if include_parens:
             tex += ")"
         return tex
diff --git a/sympy/printing/tests/test_latex.py b/sympy/printing/tests/test_latex.py
index 17196cb5d375..52ccacd10ace 100644
--- a/sympy/printing/tests/test_latex.py
+++ b/sympy/printing/tests/test_latex.py
@@ -1629,6 +1629,12 @@ def test_issue_12886():
     assert latex(m__1**2 + l__1**2) == r'\left(l^{1}\right)^{2} + \left(m^{1}\right)^{2}'
 
 
+def test_issue_13559():
+    from sympy.parsing.sympy_parser import parse_expr
+    expr = parse_expr('5/1', evaluate=False)
+    assert latex(expr) == r"\frac{5}{1}"
+
+
 def test_latex_UnevaluatedExpr():
     x = symbols("x")
     he = UnevaluatedExpr(1/x)


Code review comments:
diff_hunk: @@ -415,12 +416,9 @@ def convert(expr):
                     _tex += term_tex
                     last_term_tex = term_tex
                 return _tex
+        one_by_one =  parse_expr('1/1', evaluate=False)
path: sympy/printing/latex.py
text: @user1:
You can do `Pow(1, -1, evaluate=False)`.