Repository: sympy/sympy

Issue:
implicit_multiplication_application transformation in parse_expr incorrectly handles method
Example

```py
>>> from sympy.parsing.sympy_parser import standard_transformations,\
... implicit_multiplication_application, parse_expr
>>> transformations = (standard_transformations +
...     (implicit_multiplication_application,))
>>> parse_expr('(exp(x) / (1 + exp(2x))).subs(exp(x), u)', transformations=transformations)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "./sympy/parsing/sympy_parser.py", line 1008, in parse_expr
    return eval_expr(code, local_dict, global_dict)
  File "./sympy/parsing/sympy_parser.py", line 903, in eval_expr
    code, global_dict, local_dict)  # take local objects in preference
  File "<string>", line 1, in <module>
TypeError: can't multiply sequence by non-int of type 'method'
```

Putting a print statement in `eval_expr` (side note, parse_expr ought to have better error reporting so this isn't necessary), it is trying to evaluate the expression

```
(exp (Symbol ('x' ))/(Integer (1 )+exp (Integer (2 )*Symbol ('x' )))).subs *(exp (Symbol ('x' )),Symbol ('u' ))
```

This used to work. 

This is an example on SymPy Gamma. See https://github.com/sympy/sympy_gamma/issues/172.

Discussion:

Patch:
diff --git a/sympy/assumptions/assume.py b/sympy/assumptions/assume.py
index 4c2aa41120..41000afb34 100644
--- a/sympy/assumptions/assume.py
+++ b/sympy/assumptions/assume.py
@@ -6,7 +6,9 @@
 from sympy.core.symbol import Str
 from sympy.core.sympify import _sympify
 from sympy.logic.boolalg import Boolean, false, true
-from sympy.multipledispatch.dispatcher import Dispatcher, str_signature
+from sympy.multipledispatch.dispatcher import (
+    Dispatcher, MDNotImplementedError, str_signature
+)
 from sympy.utilities.exceptions import SymPyDeprecationWarning
 from sympy.utilities.iterables import is_sequence
 from sympy.utilities.source import get_class
@@ -363,11 +365,16 @@ def eval(self, args, assumptions=True):
 
         This uses only direct resolution methods, not logical inference.
         """
+        types = tuple(type(a) for a in args)
         result = None
-        try:
-            result = self.handler(*args, assumptions=assumptions)
-        except NotImplementedError:
-            pass
+        for func in self.handler.dispatch_iter(*types):
+            try:
+                result = func(*args, assumptions)
+            except MDNotImplementedError:
+                continue
+            else:
+                if result is not None:
+                    return result
         return result
 
 
diff --git a/sympy/assumptions/handlers/ntheory.py b/sympy/assumptions/handlers/ntheory.py
index 6294fe4dd9..eb2a7a1dd0 100644
--- a/sympy/assumptions/handlers/ntheory.py
+++ b/sympy/assumptions/handlers/ntheory.py
@@ -4,13 +4,11 @@
 
 from sympy.assumptions import Q, ask
 from sympy.core import Add, Basic, Expr, Float, Mul, Pow, S
-from sympy.core.numbers import (ImaginaryUnit, Infinity, Integer, NaN,
-    NegativeInfinity, NumberSymbol, Rational)
+from sympy.core.numbers import (ImaginaryUnit, Infinity, Integer, NegativeInfinity,
+    NumberSymbol, Rational)
 from sympy.functions import Abs, im, re
 from sympy.ntheory import isprime
 
-from sympy.multipledispatch import MDNotImplementedError
-
 from ..predicates.ntheory import (PrimePredicate, CompositePredicate,
     EvenPredicate, OddPredicate)
 
@@ -33,10 +31,7 @@ def _PrimePredicate_number(expr, assumptions):
 
 @PrimePredicate.register(Expr)
 def _(expr, assumptions):
-    ret = expr.is_prime
-    if ret is None:
-        raise MDNotImplementedError
-    return ret
+    return expr.is_prime
 
 @PrimePredicate.register(Basic)
 def _(expr, assumptions):
@@ -69,7 +64,7 @@ def _(expr, assumptions):
 def _(expr, assumptions):
     return isprime(expr)
 
-@PrimePredicate.register_many(Rational, Infinity, NaN, NegativeInfinity, ImaginaryUnit)
+@PrimePredicate.register_many(Rational, Infinity, NegativeInfinity, ImaginaryUnit)
 def _(expr, assumptions):
     return False
 
@@ -86,10 +81,7 @@ def _(expr, assumptions):
 
 @CompositePredicate.register(Expr)
 def _(expr, assumptions):
-    ret = expr.is_composite
-    if ret is None:
-        raise MDNotImplementedError
-    return ret
+    return expr.is_composite
 
 @CompositePredicate.register(Basic)
 def _(expr, assumptions):
@@ -110,10 +102,6 @@ def _(expr, assumptions):
     else:
         return _positive
 
-@CompositePredicate.register(NaN)
-def _(expr, assumptions):
-    return False
-
 
 # EvenPredicate
 
@@ -131,10 +119,7 @@ def _EvenPredicate_number(expr, assumptions):
 
 @EvenPredicate.register(Expr)
 def _(expr, assumptions):
-    ret = expr.is_even
-    if ret is None:
-        raise MDNotImplementedError
-    return ret
+    return expr.is_even
 
 @EvenPredicate.register(Basic)
 def _(expr, assumptions):
@@ -219,7 +204,7 @@ def _(expr, assumptions):
 def _(expr, assumptions):
     return not bool(expr.p & 1)
 
-@EvenPredicate.register_many(Rational, Infinity, NaN, NegativeInfinity, ImaginaryUnit)
+@EvenPredicate.register_many(Rational, Infinity, NegativeInfinity, ImaginaryUnit)
 def _(expr, assumptions):
     return False
 
@@ -247,10 +232,7 @@ def _(expr, assumptions):
 
 @OddPredicate.register(Expr)
 def _(expr, assumptions):
-    ret = expr.is_odd
-    if ret is None:
-        raise MDNotImplementedError
-    return ret
+    return expr.is_odd
 
 @OddPredicate.register(Basic)
 def _(expr, assumptions):
@@ -261,7 +243,3 @@ def _(expr, assumptions):
             return None
         return not _even
     return _integer
-
-@OddPredicate.register(NaN)
-def _(expr, assumptions):
-    return False
diff --git a/sympy/assumptions/handlers/order.py b/sympy/assumptions/handlers/order.py
index e2821afba7..98611aee5c 100644
--- a/sympy/assumptions/handlers/order.py
+++ b/sympy/assumptions/handlers/order.py
@@ -10,8 +10,6 @@
 from sympy.matrices import Determinant, Trace
 from sympy.matrices.expressions.matexpr import MatrixElement
 
-from sympy.multipledispatch import MDNotImplementedError
-
 from ..predicates.order import (NegativePredicate, NonNegativePredicate,
     NonZeroPredicate, ZeroPredicate, NonPositivePredicate, PositivePredicate)
 
@@ -44,10 +42,7 @@ def _(expr, assumptions):
 
 @NegativePredicate.register(Expr)
 def _(expr, assumptions):
-    ret = expr.is_negative
-    if ret is None:
-        raise MDNotImplementedError
-    return ret
+    return expr.is_negative
 
 @NegativePredicate.register(Add)
 def _(expr, assumptions):
@@ -113,7 +108,7 @@ def _(expr, assumptions):
         if ask(Q.odd(expr.exp), assumptions):
             return ask(Q.negative(expr.base), assumptions)
 
-@NegativePredicate.register_many(Abs, ImaginaryUnit, NaN)
+@NegativePredicate.register_many(Abs, ImaginaryUnit)
 def _(expr, assumptions):
     return False
 
@@ -121,7 +116,6 @@ def _(expr, assumptions):
 def _(expr, assumptions):
     if ask(Q.real(expr.exp), assumptions):
         return False
-    raise MDNotImplementedError
 
 
 # NonNegativePredicate
@@ -137,24 +131,14 @@ def _(expr, assumptions):
 
 @NonNegativePredicate.register(Expr)
 def _(expr, assumptions):
-    ret = expr.is_nonnegative
-    if ret is None:
-        raise MDNotImplementedError
-    return ret
-
-@NonNegativePredicate.register(NaN)
-def _(expr, assumptions):
-    return False
+    return expr.is_nonnegative
 
 
 # NonZeroPredicate
 
 @NonZeroPredicate.register(Expr)
 def _(expr, assumptions):
-    ret = expr.is_nonzero
-    if ret is None:
-        raise MDNotImplementedError
-    return ret
+    return expr.is_nonzero
 
 @NonZeroPredicate.register(Basic)
 def _(expr, assumptions):
@@ -200,10 +184,7 @@ def _(expr, assumptions):
 
 @ZeroPredicate.register(Expr)
 def _(expr, assumptions):
-    ret = expr.is_zero
-    if ret is None:
-        raise MDNotImplementedError
-    return ret
+    return expr.is_zero
 
 @ZeroPredicate.register(Basic)
 def _(expr, assumptions):
@@ -215,19 +196,12 @@ def _(expr, assumptions):
     # TODO: This should be deducible from the nonzero handler
     return fuzzy_or(ask(Q.zero(arg), assumptions) for arg in expr.args)
 
-@ZeroPredicate.register(NaN)
-def _(expr, assumptions):
-    return False
-
 
 # NonPositivePredicate
 
 @NonPositivePredicate.register(Expr)
 def _(expr, assumptions):
-    ret = expr.is_nonpositive
-    if ret is None:
-        raise MDNotImplementedError
-    return ret
+    return expr.is_nonpositive
 
 @NonPositivePredicate.register(Basic)
 def _(expr, assumptions):
@@ -238,10 +212,6 @@ def _(expr, assumptions):
         else:
             return notpositive
 
-@NonPositivePredicate.register(NaN)
-def _(expr, assumptions):
-    return False
-
 
 # PositivePredicate
 
@@ -266,10 +236,7 @@ def _PositivePredicate_number(expr, assumptions):
 
 @PositivePredicate.register(Expr)
 def _(expr, assumptions):
-    ret = expr.is_positive
-    if ret is None:
-        raise MDNotImplementedError
-    return ret
+    return expr.is_positive
 
 @PositivePredicate.register(Basic)
 def _(expr, assumptions):
@@ -400,7 +367,3 @@ def _(expr, assumptions):
 @PositivePredicate.register(acot)
 def _(expr, assumptions):
     return ask(Q.real(expr.args[0]), assumptions)
-
-@PositivePredicate.register(NaN)
-def _(expr, assumptions):
-    return False
diff --git a/sympy/assumptions/handlers/sets.py b/sympy/assumptions/handlers/sets.py
index b33bb624fb..7dc1cfc5a1 100644
--- a/sympy/assumptions/handlers/sets.py
+++ b/sympy/assumptions/handlers/sets.py
@@ -14,8 +14,6 @@
 from sympy.matrices import Determinant, MatrixBase, Trace
 from sympy.matrices.expressions.matexpr import MatrixElement
 
-from sympy.multipledispatch import MDNotImplementedError
-
 from .common import test_closed_group
 from ..predicates.sets import (IntegerPredicate, RationalPredicate,
     IrrationalPredicate, RealPredicate, ExtendedRealPredicate,
@@ -46,10 +44,7 @@ def _(expr, assumptions):
 
 @IntegerPredicate.register(Expr)
 def _(expr, assumptions):
-    ret = expr.is_integer
-    if ret is None:
-        raise MDNotImplementedError
-    return ret
+    return expr.is_integer
 
 @IntegerPredicate.register_many(Add, Pow)
 def _(expr, assumptions):
@@ -116,10 +111,7 @@ def _(expr, assumptions):
 
 @RationalPredicate.register(Expr)
 def _(expr, assumptions):
-    ret = expr.is_rational
-    if ret is None:
-        raise MDNotImplementedError
-    return ret
+    return expr.is_rational
 
 @RationalPredicate.register_many(Add, Mul)
 def _(expr, assumptions):
@@ -185,10 +177,7 @@ def _(expr, assumptions):
 
 @IrrationalPredicate.register(Expr)
 def _(expr, assumptions):
-    ret = expr.is_irrational
-    if ret is None:
-        raise MDNotImplementedError
-    return ret
+    return expr.is_irrational
 
 @IrrationalPredicate.register(Basic)
 def _(expr, assumptions):
@@ -224,10 +213,7 @@ def _(expr, assumptions):
 
 @RealPredicate.register(Expr)
 def _(expr, assumptions):
-    ret = expr.is_real
-    if ret is None:
-        raise MDNotImplementedError
-    return ret
+    return expr.is_real
 
 @RealPredicate.register(Add)
 def _(expr, assumptions):
@@ -381,7 +367,7 @@ def _(expr, assumptions):
     * Hermitian + !Hermitian -> !Hermitian
     """
     if expr.is_number:
-        raise MDNotImplementedError
+        return None
     return test_closed_group(expr, assumptions, Q.hermitian)
 
 @HermitianPredicate.register(Mul)
@@ -394,7 +380,7 @@ def _(expr, assumptions):
     * Antihermitian*Antihermitian -> Hermitian
     """
     if expr.is_number:
-        raise MDNotImplementedError
+        return None
     nccount = 0
     result = True
     for arg in expr.args:
@@ -415,27 +401,24 @@ def _(expr, assumptions):
     * Hermitian**Integer -> Hermitian
     """
     if expr.is_number:
-        raise MDNotImplementedError
+        return None
     if expr.base == E:
         if ask(Q.hermitian(expr.exp), assumptions):
             return True
-        raise MDNotImplementedError
+        return
     if ask(Q.hermitian(expr.base), assumptions):
         if ask(Q.integer(expr.exp), assumptions):
             return True
-    raise MDNotImplementedError
 
 @HermitianPredicate.register_many(cos, sin)
 def _(expr, assumptions):
     if ask(Q.hermitian(expr.args[0]), assumptions):
         return True
-    raise MDNotImplementedError
 
 @HermitianPredicate.register(exp)
 def _(expr, assumptions):
     if ask(Q.hermitian(expr.exp), assumptions):
         return True
-    raise MDNotImplementedError
 
 @HermitianPredicate.register(MatrixBase)
 def _(mat, assumptions):
@@ -448,8 +431,6 @@ def _(mat, assumptions):
                 ret_val = None
             if cond == False:
                 return False
-    if ret_val is None:
-        raise MDNotImplementedError
     return ret_val
 
 
@@ -466,10 +447,7 @@ def _(expr, assumptions):
 
 @ComplexPredicate.register(Expr)
 def _(expr, assumptions):
-    ret = expr.is_complex
-    if ret is None:
-        raise MDNotImplementedError
-    return ret
+    return expr.is_complex
 
 @ComplexPredicate.register_many(Add, Mul)
 def _(expr, assumptions):
@@ -507,10 +485,7 @@ def _(expr, assumptions):
 
 @ImaginaryPredicate.register(Expr)
 def _(expr, assumptions):
-    ret = expr.is_imaginary
-    if ret is None:
-        raise MDNotImplementedError
-    return ret
+    return expr.is_imaginary
 
 @ImaginaryPredicate.register(Add)
 def _(expr, assumptions):
@@ -659,7 +634,7 @@ def _(expr, assumptions):
     * Antihermitian + !Antihermitian -> !Antihermitian
     """
     if expr.is_number:
-        raise MDNotImplementedError
+        return None
     return test_closed_group(expr, assumptions, Q.antihermitian)
 
 @AntihermitianPredicate.register(Mul)
@@ -672,7 +647,7 @@ def _(expr, assumptions):
     * Antihermitian*Antihermitian -> !Antihermitian
     """
     if expr.is_number:
-        raise MDNotImplementedError
+        return None
     nccount = 0
     result = False
     for arg in expr.args:
@@ -695,7 +670,7 @@ def _(expr, assumptions):
     * Antihermitian**Odd  -> Antihermitian
     """
     if expr.is_number:
-        raise MDNotImplementedError
+        return None
     if ask(Q.hermitian(expr.base), assumptions):
         if ask(Q.integer(expr.exp), assumptions):
             return False
@@ -704,7 +679,6 @@ def _(expr, assumptions):
             return False
         elif ask(Q.odd(expr.exp), assumptions):
             return True
-    raise MDNotImplementedError
 
 @AntihermitianPredicate.register(MatrixBase)
 def _(mat, assumptions):
@@ -717,8 +691,6 @@ def _(mat, assumptions):
                 ret_val = None
             if cond == False:
                 return False
-    if ret_val is None:
-        raise MDNotImplementedError
     return ret_val
 
 
diff --git a/sympy/parsing/sympy_parser.py b/sympy/parsing/sympy_parser.py
index 2ed52175c9..37dce99cc4 100644
--- a/sympy/parsing/sympy_parser.py
+++ b/sympy/parsing/sympy_parser.py
@@ -208,8 +208,16 @@ def _implicit_multiplication(tokens, local_dict, global_dict):
 
     """
     result = []
+    skip = False
     for tok, nextTok in zip(tokens, tokens[1:]):
         result.append(tok)
+        if skip:
+            skip = False
+            continue
+        if tok[0] == OP and tok[1] == '.' and nextTok[0] == NAME:
+            # Dotted name. Do not do implicit multiplication
+            skip = True
+            continue
         if (isinstance(tok, AppliedFunction) and
               isinstance(nextTok, AppliedFunction)):
             result.append((OP, '*'))
@@ -900,7 +908,6 @@ def eval_expr(code, local_dict, global_dict):
     """
     expr = eval(
         code, global_dict, local_dict)  # take local objects in preference
-
     return expr
 
 
@@ -1004,7 +1011,10 @@ def parse_expr(s, local_dict=None, transformations=standard_transformations,
     if not evaluate:
         code = compile(evaluateFalse(code), '<string>', 'eval')
 
-    return eval_expr(code, local_dict, global_dict)
+    try:
+        return eval_expr(code, local_dict, global_dict)
+    except Exception as e:
+        raise e from ValueError(f"Error from parse_expr with transformed code: {code!r}")
 
 
 def evaluateFalse(s):
diff --git a/sympy/polys/matrices/domainmatrix.py b/sympy/polys/matrices/domainmatrix.py
index c9e673885e..da316f5980 100644
--- a/sympy/polys/matrices/domainmatrix.py
+++ b/sympy/polys/matrices/domainmatrix.py
@@ -213,22 +213,6 @@ def charpoly(self):
     def eye(cls, n, domain):
         return cls.from_rep(DDM.eye(n, domain))
 
-    @classmethod
-    def zeros(cls, shape, domain):
-        """Returns a zero DomainMatrix of size shape, belonging to the specified domain
-
-        Examples
-        ========
-
-        >>> from sympy.polys.matrices import DomainMatrix
-        >>> from sympy import QQ
-        >>> DomainMatrix.zeros((2, 3), QQ)
-        DomainMatrix([[0, 0, 0], [0, 0, 0]], (2, 3), QQ)
-
-        """
-
-        return cls.from_rep(DDM.zeros(shape, domain))
-
     def __eq__(A, B):
         """A == B"""
         if not isinstance(B, DomainMatrix):
diff --git a/sympy/solvers/solveset.py b/sympy/solvers/solveset.py
index 34fa8f03bf..a7a98ac95f 100644
--- a/sympy/solvers/solveset.py
+++ b/sympy/solvers/solveset.py
@@ -1536,8 +1536,8 @@ def _solve_exponential(lhs, rhs, symbol, domain):
     a_term = a.as_independent(symbol)[1]
     b_term = b.as_independent(symbol)[1]
 
-    a_base, a_exp = a_term.as_base_exp()
-    b_base, b_exp = b_term.as_base_exp()
+    a_base, a_exp = a_term.base, a_term.exp
+    b_base, b_exp = b_term.base, b_term.exp
 
     from sympy.functions.elementary.complexes import im
 
@@ -3223,9 +3223,9 @@ def _solve_using_known_values(result, solver):
     new_result_complex, solve_call2, cnd_call2 = _solve_using_known_values(
         old_result, solveset_complex)
 
-    # If total_solveset_call is equal to total_conditionset
-    # then solveset failed to solve all of the equations.
-    # In this case we return a ConditionSet here.
+    # when `total_solveset_call` is equals to `total_conditionset`
+    # means solvest fails to solve all the eq.
+    # return conditionset in this case
     total_conditionset += (cnd_call1 + cnd_call2)
     total_solveset_call += (solve_call1 + solve_call2)
 


Test patch:
diff --git a/sympy/parsing/tests/test_implicit_multiplication_application.py b/sympy/parsing/tests/test_implicit_multiplication_application.py
index f07567c7c3..becf942f86 100644
--- a/sympy/parsing/tests/test_implicit_multiplication_application.py
+++ b/sympy/parsing/tests/test_implicit_multiplication_application.py
@@ -183,3 +183,15 @@ def test_all_implicit_steps():
         implicit = parse_expr(case, transformations=transformations2)
         normal = parse_expr(cases[case], transformations=transformations)
         assert(implicit == normal)
+
+
+def test_no_methods_implicit_multiplication():
+    # Issue 21020
+    u = sympy.Symbol('u')
+    transformations = standard_transformations + \
+                      (implicit_multiplication,)
+    expr = parse_expr('x.is_polynomial(x)', transformations=transformations)
+    assert expr == True
+    expr = parse_expr('(exp(x) / (1 + exp(2x))).subs(exp(x), u)',
+                      transformations=transformations)
+    assert expr == u/(u**2 + 1)
diff --git a/sympy/parsing/tests/test_latex.py b/sympy/parsing/tests/test_latex.py
index f7122af1da..314cd2d959 100644
--- a/sympy/parsing/tests/test_latex.py
+++ b/sympy/parsing/tests/test_latex.py
@@ -74,172 +74,172 @@ def test_import():
 
 # These LaTeX strings should parse to the corresponding SymPy expression
 GOOD_PAIRS = [
-    (r"0", 0),
-    (r"1", 1),
-    (r"-3.14", _Mul(-1, 3.14)),
-    (r"(-7.13)(1.5)", _Mul(_Mul(-1, 7.13), 1.5)),
-    (r"x", x),
-    (r"2x", 2*x),
-    (r"x^2", x**2),
-    (r"x^{3 + 1}", x**_Add(3, 1)),
-    (r"-c", -c),
-    (r"a \cdot b", a * b),
-    (r"a / b", a / b),
-    (r"a \div b", a / b),
-    (r"a + b", a + b),
-    (r"a + b - a", _Add(a+b, -a)),
-    (r"a^2 + b^2 = c^2", Eq(a**2 + b**2, c**2)),
-    (r"(x + y) z", _Mul(_Add(x, y), z)),
-    (r"\left(x + y\right) z", _Mul(_Add(x, y), z)),
-    (r"\left( x + y\right ) z", _Mul(_Add(x, y), z)),
-    (r"\left(  x + y\right ) z", _Mul(_Add(x, y), z)),
-    (r"\left[x + y\right] z", _Mul(_Add(x, y), z)),
-    (r"\left\{x + y\right\} z", _Mul(_Add(x, y), z)),
-    (r"1+1", _Add(1, 1)),
-    (r"0+1", _Add(0, 1)),
-    (r"1*2", _Mul(1, 2)),
-    (r"0*1", _Mul(0, 1)),
-    (r"x = y", Eq(x, y)),
-    (r"x \neq y", Ne(x, y)),
-    (r"x < y", Lt(x, y)),
-    (r"x > y", Gt(x, y)),
-    (r"x \leq y", Le(x, y)),
-    (r"x \geq y", Ge(x, y)),
-    (r"x \le y", Le(x, y)),
-    (r"x \ge y", Ge(x, y)),
-    (r"\lfloor x \rfloor", floor(x)),
-    (r"\lceil x \rceil", ceiling(x)),
-    (r"\langle x |", Bra('x')),
-    (r"| x \rangle", Ket('x')),
-    (r"\sin \theta", sin(theta)),
-    (r"\sin(\theta)", sin(theta)),
-    (r"\sin^{-1} a", asin(a)),
-    (r"\sin a \cos b", _Mul(sin(a), cos(b))),
-    (r"\sin \cos \theta", sin(cos(theta))),
-    (r"\sin(\cos \theta)", sin(cos(theta))),
-    (r"\frac{a}{b}", a / b),
-    (r"\frac{a + b}{c}", _Mul(a + b, _Pow(c, -1))),
-    (r"\frac{7}{3}", _Mul(7, _Pow(3, -1))),
-    (r"(\csc x)(\sec y)", csc(x)*sec(y)),
-    (r"\lim_{x \to 3} a", Limit(a, x, 3)),
-    (r"\lim_{x \rightarrow 3} a", Limit(a, x, 3)),
-    (r"\lim_{x \Rightarrow 3} a", Limit(a, x, 3)),
-    (r"\lim_{x \longrightarrow 3} a", Limit(a, x, 3)),
-    (r"\lim_{x \Longrightarrow 3} a", Limit(a, x, 3)),
-    (r"\lim_{x \to 3^{+}} a", Limit(a, x, 3, dir='+')),
-    (r"\lim_{x \to 3^{-}} a", Limit(a, x, 3, dir='-')),
-    (r"\infty", oo),
-    (r"\lim_{x \to \infty} \frac{1}{x}", Limit(_Pow(x, -1), x, oo)),
-    (r"\frac{d}{dx} x", Derivative(x, x)),
-    (r"\frac{d}{dt} x", Derivative(x, t)),
-    (r"f(x)", f(x)),
-    (r"f(x, y)", f(x, y)),
-    (r"f(x, y, z)", f(x, y, z)),
-    (r"\frac{d f(x)}{dx}", Derivative(f(x), x)),
-    (r"\frac{d\theta(x)}{dx}", Derivative(Function('theta')(x), x)),
-    (r"x \neq y", Unequality(x, y)),
-    (r"|x|", _Abs(x)),
-    (r"||x||", _Abs(Abs(x))),
-    (r"|x||y|", _Abs(x)*_Abs(y)),
-    (r"||x||y||", _Abs(_Abs(x)*_Abs(y))),
-    (r"\pi^{|xy|}", Symbol('pi')**_Abs(x*y)),
-    (r"\int x dx", Integral(x, x)),
-    (r"\int x d\theta", Integral(x, theta)),
-    (r"\int (x^2 - y)dx", Integral(x**2 - y, x)),
-    (r"\int x + a dx", Integral(_Add(x, a), x)),
-    (r"\int da", Integral(1, a)),
-    (r"\int_0^7 dx", Integral(1, (x, 0, 7))),
-    (r"\int_a^b x dx", Integral(x, (x, a, b))),
-    (r"\int^b_a x dx", Integral(x, (x, a, b))),
-    (r"\int_{a}^b x dx", Integral(x, (x, a, b))),
-    (r"\int^{b}_a x dx", Integral(x, (x, a, b))),
-    (r"\int_{a}^{b} x dx", Integral(x, (x, a, b))),
-    (r"\int^{b}_{a} x dx", Integral(x, (x, a, b))),
-    (r"\int_{f(a)}^{f(b)} f(z) dz", Integral(f(z), (z, f(a), f(b)))),
-    (r"\int (x+a)", Integral(_Add(x, a), x)),
-    (r"\int a + b + c dx", Integral(_Add(_Add(a, b), c), x)),
-    (r"\int \frac{dz}{z}", Integral(Pow(z, -1), z)),
-    (r"\int \frac{3 dz}{z}", Integral(3*Pow(z, -1), z)),
-    (r"\int \frac{1}{x} dx", Integral(Pow(x, -1), x)),
-    (r"\int \frac{1}{a} + \frac{1}{b} dx",
+    ("0", 0),
+    ("1", 1),
+    ("-3.14", _Mul(-1, 3.14)),
+    ("(-7.13)(1.5)", _Mul(_Mul(-1, 7.13), 1.5)),
+    ("x", x),
+    ("2x", 2*x),
+    ("x^2", x**2),
+    ("x^{3 + 1}", x**_Add(3, 1)),
+    ("-c", -c),
+    ("a \\cdot b", a * b),
+    ("a / b", a / b),
+    ("a \\div b", a / b),
+    ("a + b", a + b),
+    ("a + b - a", _Add(a+b, -a)),
+    ("a^2 + b^2 = c^2", Eq(a**2 + b**2, c**2)),
+    ("(x + y) z", _Mul(_Add(x, y), z)),
+    ("\\left(x + y\\right) z", _Mul(_Add(x, y), z)),
+    ("\\left( x + y\\right ) z", _Mul(_Add(x, y), z)),
+    ("\\left(  x + y\\right ) z", _Mul(_Add(x, y), z)),
+    ("\\left[x + y\\right] z", _Mul(_Add(x, y), z)),
+    ("\\left\\{x + y\\right\\} z", _Mul(_Add(x, y), z)),
+    ("1+1", _Add(1, 1)),
+    ("0+1", _Add(0, 1)),
+    ("1*2", _Mul(1, 2)),
+    ("0*1", _Mul(0, 1)),
+    ("x = y", Eq(x, y)),
+    ("x \\neq y", Ne(x, y)),
+    ("x < y", Lt(x, y)),
+    ("x > y", Gt(x, y)),
+    ("x \\leq y", Le(x, y)),
+    ("x \\geq y", Ge(x, y)),
+    ("x \\le y", Le(x, y)),
+    ("x \\ge y", Ge(x, y)),
+    ("\\lfloor x \\rfloor", floor(x)),
+    ("\\lceil x \\rceil", ceiling(x)),
+    ("\\langle x |", Bra('x')),
+    ("| x \\rangle", Ket('x')),
+    ("\\sin \\theta", sin(theta)),
+    ("\\sin(\\theta)", sin(theta)),
+    ("\\sin^{-1} a", asin(a)),
+    ("\\sin a \\cos b", _Mul(sin(a), cos(b))),
+    ("\\sin \\cos \\theta", sin(cos(theta))),
+    ("\\sin(\\cos \\theta)", sin(cos(theta))),
+    ("\\frac{a}{b}", a / b),
+    ("\\frac{a + b}{c}", _Mul(a + b, _Pow(c, -1))),
+    ("\\frac{7}{3}", _Mul(7, _Pow(3, -1))),
+    ("(\\csc x)(\\sec y)", csc(x)*sec(y)),
+    ("\\lim_{x \\to 3} a", Limit(a, x, 3)),
+    ("\\lim_{x \\rightarrow 3} a", Limit(a, x, 3)),
+    ("\\lim_{x \\Rightarrow 3} a", Limit(a, x, 3)),
+    ("\\lim_{x \\longrightarrow 3} a", Limit(a, x, 3)),
+    ("\\lim_{x \\Longrightarrow 3} a", Limit(a, x, 3)),
+    ("\\lim_{x \\to 3^{+}} a", Limit(a, x, 3, dir='+')),
+    ("\\lim_{x \\to 3^{-}} a", Limit(a, x, 3, dir='-')),
+    ("\\infty", oo),
+    ("\\lim_{x \\to \\infty} \\frac{1}{x}", Limit(_Pow(x, -1), x, oo)),
+    ("\\frac{d}{dx} x", Derivative(x, x)),
+    ("\\frac{d}{dt} x", Derivative(x, t)),
+    ("f(x)", f(x)),
+    ("f(x, y)", f(x, y)),
+    ("f(x, y, z)", f(x, y, z)),
+    ("\\frac{d f(x)}{dx}", Derivative(f(x), x)),
+    ("\\frac{d\\theta(x)}{dx}", Derivative(Function('theta')(x), x)),
+    ("x \\neq y", Unequality(x, y)),
+    ("|x|", _Abs(x)),
+    ("||x||", _Abs(Abs(x))),
+    ("|x||y|", _Abs(x)*_Abs(y)),
+    ("||x||y||", _Abs(_Abs(x)*_Abs(y))),
+    ("\\pi^{|xy|}", Symbol('pi')**_Abs(x*y)),
+    ("\\int x dx", Integral(x, x)),
+    ("\\int x d\\theta", Integral(x, theta)),
+    ("\\int (x^2 - y)dx", Integral(x**2 - y, x)),
+    ("\\int x + a dx", Integral(_Add(x, a), x)),
+    ("\\int da", Integral(1, a)),
+    ("\\int_0^7 dx", Integral(1, (x, 0, 7))),
+    ("\\int_a^b x dx", Integral(x, (x, a, b))),
+    ("\\int^b_a x dx", Integral(x, (x, a, b))),
+    ("\\int_{a}^b x dx", Integral(x, (x, a, b))),
+    ("\\int^{b}_a x dx", Integral(x, (x, a, b))),
+    ("\\int_{a}^{b} x dx", Integral(x, (x, a, b))),
+    ("\\int^{b}_{a} x dx", Integral(x, (x, a, b))),
+    ("\\int_{f(a)}^{f(b)} f(z) dz", Integral(f(z), (z, f(a), f(b)))),
+    ("\\int (x+a)", Integral(_Add(x, a), x)),
+    ("\\int a + b + c dx", Integral(_Add(_Add(a, b), c), x)),
+    ("\\int \\frac{dz}{z}", Integral(Pow(z, -1), z)),
+    ("\\int \\frac{3 dz}{z}", Integral(3*Pow(z, -1), z)),
+    ("\\int \\frac{1}{x} dx", Integral(Pow(x, -1), x)),
+    ("\\int \\frac{1}{a} + \\frac{1}{b} dx",
      Integral(_Add(_Pow(a, -1), Pow(b, -1)), x)),
-    (r"\int \frac{3 \cdot d\theta}{\theta}",
+    ("\\int \\frac{3 \\cdot d\\theta}{\\theta}",
      Integral(3*_Pow(theta, -1), theta)),
-    (r"\int \frac{1}{x} + 1 dx", Integral(_Add(_Pow(x, -1), 1), x)),
-    (r"x_0", Symbol('x_{0}')),
-    (r"x_{1}", Symbol('x_{1}')),
-    (r"x_a", Symbol('x_{a}')),
-    (r"x_{b}", Symbol('x_{b}')),
-    (r"h_\theta", Symbol('h_{theta}')),
-    (r"h_{\theta}", Symbol('h_{theta}')),
-    (r"h_{\theta}(x_0, x_1)",
+    ("\\int \\frac{1}{x} + 1 dx", Integral(_Add(_Pow(x, -1), 1), x)),
+    ("x_0", Symbol('x_{0}')),
+    ("x_{1}", Symbol('x_{1}')),
+    ("x_a", Symbol('x_{a}')),
+    ("x_{b}", Symbol('x_{b}')),
+    ("h_\\theta", Symbol('h_{theta}')),
+    ("h_{\\theta}", Symbol('h_{theta}')),
+    ("h_{\\theta}(x_0, x_1)",
      Function('h_{theta}')(Symbol('x_{0}'), Symbol('x_{1}'))),
-    (r"x!", _factorial(x)),
-    (r"100!", _factorial(100)),
-    (r"\theta!", _factorial(theta)),
-    (r"(x + 1)!", _factorial(_Add(x, 1))),
-    (r"(x!)!", _factorial(_factorial(x))),
-    (r"x!!!", _factorial(_factorial(_factorial(x)))),
-    (r"5!7!", _Mul(_factorial(5), _factorial(7))),
-    (r"\sqrt{x}", sqrt(x)),
-    (r"\sqrt{x + b}", sqrt(_Add(x, b))),
-    (r"\sqrt[3]{\sin x}", root(sin(x), 3)),
-    (r"\sqrt[y]{\sin x}", root(sin(x), y)),
-    (r"\sqrt[\theta]{\sin x}", root(sin(x), theta)),
-    (r"\sqrt{\frac{12}{6}}", _Sqrt(_Mul(12, _Pow(6, -1)))),
+    ("x!", _factorial(x)),
+    ("100!", _factorial(100)),
+    ("\\theta!", _factorial(theta)),
+    ("(x + 1)!", _factorial(_Add(x, 1))),
+    ("(x!)!", _factorial(_factorial(x))),
+    ("x!!!", _factorial(_factorial(_factorial(x)))),
+    ("5!7!", _Mul(_factorial(5), _factorial(7))),
+    ("\\sqrt{x}", sqrt(x)),
+    ("\\sqrt{x + b}", sqrt(_Add(x, b))),
+    ("\\sqrt[3]{\\sin x}", root(sin(x), 3)),
+    ("\\sqrt[y]{\\sin x}", root(sin(x), y)),
+    ("\\sqrt[\\theta]{\\sin x}", root(sin(x), theta)),
+    ("\\sqrt{\\frac{12}{6}}", _Sqrt(_Mul(12, _Pow(6, -1)))),
     (r"\overline{z}", _Conjugate(z)),
     (r"\overline{\overline{z}}", _Conjugate(_Conjugate(z))),
     (r"\overline{x + y}", _Conjugate(_Add(x, y))),
     (r"\overline{x} + \overline{y}", _Conjugate(x) + _Conjugate(y)),
-    (r"x < y", StrictLessThan(x, y)),
-    (r"x \leq y", LessThan(x, y)),
-    (r"x > y", StrictGreaterThan(x, y)),
-    (r"x \geq y", GreaterThan(x, y)),
-    (r"\mathit{x}", Symbol('x')),
-    (r"\mathit{test}", Symbol('test')),
-    (r"\mathit{TEST}", Symbol('TEST')),
-    (r"\mathit{HELLO world}", Symbol('HELLO world')),
-    (r"\sum_{k = 1}^{3} c", Sum(c, (k, 1, 3))),
-    (r"\sum_{k = 1}^3 c", Sum(c, (k, 1, 3))),
-    (r"\sum^{3}_{k = 1} c", Sum(c, (k, 1, 3))),
-    (r"\sum^3_{k = 1} c", Sum(c, (k, 1, 3))),
-    (r"\sum_{k = 1}^{10} k^2", Sum(k**2, (k, 1, 10))),
-    (r"\sum_{n = 0}^{\infty} \frac{1}{n!}",
+    ("x < y", StrictLessThan(x, y)),
+    ("x \\leq y", LessThan(x, y)),
+    ("x > y", StrictGreaterThan(x, y)),
+    ("x \\geq y", GreaterThan(x, y)),
+    ("\\mathit{x}", Symbol('x')),
+    ("\\mathit{test}", Symbol('test')),
+    ("\\mathit{TEST}", Symbol('TEST')),
+    ("\\mathit{HELLO world}", Symbol('HELLO world')),
+    ("\\sum_{k = 1}^{3} c", Sum(c, (k, 1, 3))),
+    ("\\sum_{k = 1}^3 c", Sum(c, (k, 1, 3))),
+    ("\\sum^{3}_{k = 1} c", Sum(c, (k, 1, 3))),
+    ("\\sum^3_{k = 1} c", Sum(c, (k, 1, 3))),
+    ("\\sum_{k = 1}^{10} k^2", Sum(k**2, (k, 1, 10))),
+    ("\\sum_{n = 0}^{\\infty} \\frac{1}{n!}",
      Sum(_Pow(_factorial(n), -1), (n, 0, oo))),
-    (r"\prod_{a = b}^{c} x", Product(x, (a, b, c))),
-    (r"\prod_{a = b}^c x", Product(x, (a, b, c))),
-    (r"\prod^{c}_{a = b} x", Product(x, (a, b, c))),
-    (r"\prod^c_{a = b} x", Product(x, (a, b, c))),
-    (r"\exp x", _exp(x)),
-    (r"\exp(x)", _exp(x)),
-    (r"\ln x", _log(x, E)),
-    (r"\ln xy", _log(x*y, E)),
-    (r"\log x", _log(x, 10)),
-    (r"\log xy", _log(x*y, 10)),
-    (r"\log_{2} x", _log(x, 2)),
-    (r"\log_{a} x", _log(x, a)),
-    (r"\log_{11} x", _log(x, 11)),
-    (r"\log_{a^2} x", _log(x, _Pow(a, 2))),
-    (r"[x]", x),
-    (r"[a + b]", _Add(a, b)),
-    (r"\frac{d}{dx} [ \tan x ]", Derivative(tan(x), x)),
-    (r"\binom{n}{k}", _binomial(n, k)),
-    (r"\tbinom{n}{k}", _binomial(n, k)),
-    (r"\dbinom{n}{k}", _binomial(n, k)),
-    (r"\binom{n}{0}", _binomial(n, 0)),
-    (r"a \, b", _Mul(a, b)),
-    (r"a \thinspace b", _Mul(a, b)),
-    (r"a \: b", _Mul(a, b)),
-    (r"a \medspace b", _Mul(a, b)),
-    (r"a \; b", _Mul(a, b)),
-    (r"a \thickspace b", _Mul(a, b)),
-    (r"a \quad b", _Mul(a, b)),
-    (r"a \qquad b", _Mul(a, b)),
-    (r"a \! b", _Mul(a, b)),
-    (r"a \negthinspace b", _Mul(a, b)),
-    (r"a \negmedspace b", _Mul(a, b)),
-    (r"a \negthickspace b", _Mul(a, b)),
-    (r"\int x \, dx", Integral(x, x)),
+    ("\\prod_{a = b}^{c} x", Product(x, (a, b, c))),
+    ("\\prod_{a = b}^c x", Product(x, (a, b, c))),
+    ("\\prod^{c}_{a = b} x", Product(x, (a, b, c))),
+    ("\\prod^c_{a = b} x", Product(x, (a, b, c))),
+    ("\\exp x", _exp(x)),
+    ("\\exp(x)", _exp(x)),
+    ("\\ln x", _log(x, E)),
+    ("\\ln xy", _log(x*y, E)),
+    ("\\log x", _log(x, 10)),
+    ("\\log xy", _log(x*y, 10)),
+    ("\\log_{2} x", _log(x, 2)),
+    ("\\log_{a} x", _log(x, a)),
+    ("\\log_{11} x", _log(x, 11)),
+    ("\\log_{a^2} x", _log(x, _Pow(a, 2))),
+    ("[x]", x),
+    ("[a + b]", _Add(a, b)),
+    ("\\frac{d}{dx} [ \\tan x ]", Derivative(tan(x), x)),
+    ("\\binom{n}{k}", _binomial(n, k)),
+    ("\\tbinom{n}{k}", _binomial(n, k)),
+    ("\\dbinom{n}{k}", _binomial(n, k)),
+    ("\\binom{n}{0}", _binomial(n, 0)),
+    ("a \\, b", _Mul(a, b)),
+    ("a \\thinspace b", _Mul(a, b)),
+    ("a \\: b", _Mul(a, b)),
+    ("a \\medspace b", _Mul(a, b)),
+    ("a \\; b", _Mul(a, b)),
+    ("a \\thickspace b", _Mul(a, b)),
+    ("a \\quad b", _Mul(a, b)),
+    ("a \\qquad b", _Mul(a, b)),
+    ("a \\! b", _Mul(a, b)),
+    ("a \\negthinspace b", _Mul(a, b)),
+    ("a \\negmedspace b", _Mul(a, b)),
+    ("a \\negthickspace b", _Mul(a, b)),
+    ("\\int x \\, dx", Integral(x, x)),
 ]
 
 def test_parseable():
@@ -249,8 +249,8 @@ def test_parseable():
 
 # At time of migration from latex2sympy, should work but doesn't
 FAILING_PAIRS = [
-    (r"\log_2 x", _log(x, 2)),
-    (r"\log_a x", _log(x, a)),
+    ("\\log_2 x", _log(x, 2)),
+    ("\\log_a x", _log(x, a)),
 ]
 
 def test_failing_parseable():
@@ -261,44 +261,44 @@ def test_failing_parseable():
 
 # These bad LaTeX strings should raise a LaTeXParsingError when parsed
 BAD_STRINGS = [
-    r"(",
-    r")",
-    r"\frac{d}{dx}",
-    r"(\frac{d}{dx})",
-    r"\sqrt{}",
-    r"\sqrt",
-    r"\overline{}",
-    r"\overline",
-    r"{",
-    r"}",
-    r"\mathit{x + y}",
-    r"\mathit{21}",
-    r"\frac{2}{}",
-    r"\frac{}{2}",
-    r"\int",
-    r"!",
-    r"!0",
-    r"_",
-    r"^",
-    r"|",
-    r"||x|",
-    r"()",
-    r"((((((((((((((((()))))))))))))))))",
-    r"-",
-    r"\frac{d}{dx} + \frac{d}{dt}",
-    r"f(x,,y)",
-    r"f(x,y,",
-    r"\sin^x",
-    r"\cos^2",
-    r"@",
-    r"#",
-    r"$",
-    r"%",
-    r"&",
-    r"*",
-    r"" "\\",
-    r"~",
-    r"\frac{(2 + x}{1 - x)}",
+    "(",
+    ")",
+    "\\frac{d}{dx}",
+    "(\\frac{d}{dx})",
+    "\\sqrt{}",
+    "\\sqrt",
+    "\\overline{}",
+    "\\overline",
+    "{",
+    "}",
+    "\\mathit{x + y}",
+    "\\mathit{21}",
+    "\\frac{2}{}",
+    "\\frac{}{2}",
+    "\\int",
+    "!",
+    "!0",
+    "_",
+    "^",
+    "|",
+    "||x|",
+    "()",
+    "((((((((((((((((()))))))))))))))))",
+    "-",
+    "\\frac{d}{dx} + \\frac{d}{dt}",
+    "f(x,,y)",
+    "f(x,y,",
+    "\\sin^x",
+    "\\cos^2",
+    "@",
+    "#",
+    "$",
+    "%",
+    "&",
+    "*",
+    "\\",
+    "~",
+    "\\frac{(2 + x}{1 - x)}",
 ]
 
 def test_not_parseable():
@@ -309,16 +309,16 @@ def test_not_parseable():
 
 # At time of migration from latex2sympy, should fail but doesn't
 FAILING_BAD_STRINGS = [
-    r"\cos 1 \cos",
-    r"f(,",
-    r"f()",
-    r"a \div \div b",
-    r"a \cdot \cdot b",
-    r"a // b",
-    r"a +",
-    r"1.1.1",
-    r"1 +",
-    r"a / b /",
+    "\\cos 1 \\cos",
+    "f(,",
+    "f()",
+    "a \\div \\div b",
+    "a \\cdot \\cdot b",
+    "a // b",
+    "a +",
+    "1.1.1",
+    "1 +",
+    "a / b /",
 ]
 
 @XFAIL
diff --git a/sympy/polys/matrices/tests/test_domainmatrix.py b/sympy/polys/matrices/tests/test_domainmatrix.py
index 7657f9542e..9a99cc5247 100644
--- a/sympy/polys/matrices/tests/test_domainmatrix.py
+++ b/sympy/polys/matrices/tests/test_domainmatrix.py
@@ -434,9 +434,3 @@ def test_DomainMatrix_eye():
     assert A.rep == SDM.eye(3, QQ)
     assert A.shape == (3, 3)
     assert A.domain == QQ
-
-def test_DomainMatrix_zeros():
-    A = DomainMatrix.zeros((1, 2), QQ)
-    assert A.rep == SDM.zeros((1, 2), QQ)
-    assert A.shape == (1, 2)
-    assert A.domain == QQ
diff --git a/sympy/printing/tests/test_latex.py b/sympy/printing/tests/test_latex.py
index 84227a1785..d818e92d1b 100644
--- a/sympy/printing/tests/test_latex.py
+++ b/sympy/printing/tests/test_latex.py
@@ -68,21 +68,21 @@ def test_printmethod():
     class R(Abs):
         def _latex(self, printer):
             return "foo(%s)" % printer._print(self.args[0])
-    assert latex(R(x)) == r"foo(x)"
+    assert latex(R(x)) == "foo(x)"
 
     class R(Abs):
         def _latex(self, printer):
             return "foo"
-    assert latex(R(x)) == r"foo"
+    assert latex(R(x)) == "foo"
 
 
 def test_latex_basic():
-    assert latex(1 + x) == r"x + 1"
-    assert latex(x**2) == r"x^{2}"
-    assert latex(x**(1 + x)) == r"x^{x + 1}"
-    assert latex(x**3 + x + 1 + x**2) == r"x^{3} + x^{2} + x + 1"
+    assert latex(1 + x) == "x + 1"
+    assert latex(x**2) == "x^{2}"
+    assert latex(x**(1 + x)) == "x^{x + 1}"
+    assert latex(x**3 + x + 1 + x**2) == "x^{3} + x^{2} + x + 1"
 
-    assert latex(2*x*y) == r"2 x y"
+    assert latex(2*x*y) == "2 x y"
     assert latex(2*x*y, mul_symbol='dot') == r"2 \cdot x \cdot y"
     assert latex(3*x**2*y, mul_symbol='\\,') == r"3\,x^{2}\,y"
     assert latex(1.5*3**x, mul_symbol='\\,') == r"1.5 \cdot 3^{x}"
@@ -107,13 +107,13 @@ def test_latex_basic():
         r'\frac{2}{3} \frac{5}{7}'
 
     assert latex(1/x) == r"\frac{1}{x}"
-    assert latex(1/x, fold_short_frac=True) == r"1 / x"
+    assert latex(1/x, fold_short_frac=True) == "1 / x"
     assert latex(-S(3)/2) == r"- \frac{3}{2}"
     assert latex(-S(3)/2, fold_short_frac=True) == r"- 3 / 2"
     assert latex(1/x**2) == r"\frac{1}{x^{2}}"
     assert latex(1/(x + y)/2) == r"\frac{1}{2 \left(x + y\right)}"
     assert latex(x/2) == r"\frac{x}{2}"
-    assert latex(x/2, fold_short_frac=True) == r"x / 2"
+    assert latex(x/2, fold_short_frac=True) == "x / 2"
     assert latex((x + y)/(2*x)) == r"\frac{x + y}{2 x}"
     assert latex((x + y)/(2*x), fold_short_frac=True) == \
         r"\left(x + y\right) / 2 x"
@@ -145,7 +145,7 @@ def test_latex_basic():
     assert latex(x**Rational(1, 3), itex=True) == r"\root{3}{x}"
     assert latex(sqrt(x)**3, itex=True) == r"x^{\frac{3}{2}}"
     assert latex(x**Rational(3, 4)) == r"x^{\frac{3}{4}}"
-    assert latex(x**Rational(3, 4), fold_frac_powers=True) == r"x^{3/4}"
+    assert latex(x**Rational(3, 4), fold_frac_powers=True) == "x^{3/4}"
     assert latex((x + 1)**Rational(3, 4)) == \
         r"\left(x + 1\right)^{\frac{3}{4}}"
     assert latex((x + 1)**Rational(3, 4), fold_frac_powers=True) == \
@@ -307,7 +307,7 @@ def test_latex_symbols():
     Gamma, lmbda, rho = symbols('Gamma, lambda, rho')
     tau, Tau, TAU, taU = symbols('tau, Tau, TAU, taU')
     assert latex(tau) == r"\tau"
-    assert latex(Tau) == r"T"
+    assert latex(Tau) == "T"
     assert latex(TAU) == r"\tau"
     assert latex(taU) == r"\tau"
     # Check that all capitalized greek letters are handled explicitly
@@ -342,8 +342,8 @@ def test_latex_symbols_failing():
 
 @_both_exp_pow
 def test_latex_functions():
-    assert latex(exp(x)) == r"e^{x}"
-    assert latex(exp(1) + exp(2)) == r"e + e^{2}"
+    assert latex(exp(x)) == "e^{x}"
+    assert latex(exp(1) + exp(2)) == "e + e^{2}"
 
     f = Function('f')
     assert latex(f(x)) == r'f{\left(x \right)}'
@@ -657,14 +657,14 @@ def test_latex_indexed():
     symbol_latex = latex(Psi_symbol * conjugate(Psi_symbol))
     indexed_latex = latex(Psi_indexed[0] * conjugate(Psi_indexed[0]))
     # \\overline{{\\Psi}_{0}} {\\Psi}_{0}  vs.  \\Psi_{0} \\overline{\\Psi_{0}}
-    assert symbol_latex == r'\Psi_{0} \overline{\Psi_{0}}'
-    assert indexed_latex == r'\overline{{\Psi}_{0}} {\Psi}_{0}'
+    assert symbol_latex == '\\Psi_{0} \\overline{\\Psi_{0}}'
+    assert indexed_latex == '\\overline{{\\Psi}_{0}} {\\Psi}_{0}'
 
     # Symbol('gamma') gives r'\gamma'
-    assert latex(Indexed('x1', Symbol('i'))) == r'{x_{1}}_{i}'
+    assert latex(Indexed('x1', Symbol('i'))) == '{x_{1}}_{i}'
     assert latex(IndexedBase('gamma')) == r'\gamma'
-    assert latex(IndexedBase('a b')) == r'a b'
-    assert latex(IndexedBase('a_b')) == r'a_{b}'
+    assert latex(IndexedBase('a b')) == 'a b'
+    assert latex(IndexedBase('a_b')) == 'a_{b}'
 
 
 def test_latex_derivatives():
@@ -721,7 +721,7 @@ def test_latex_derivatives():
     assert latex(diff(f(x1, x2), x1)) == r'\frac{\partial}{\partial x_{1}} f{\left(x_{1},x_{2} \right)}'
 
     n1 = Symbol('n1')
-    assert latex(diff(f(x), (x, n1))) == r'\frac{d^{n_{1}}}{d x^{n_{1}}} f{\left(x \right)}'
+    assert latex(diff(f(x), (x, n1))) ==  r'\frac{d^{n_{1}}}{d x^{n_{1}}} f{\left(x \right)}'
 
     n2 = Symbol('n2')
     assert latex(diff(f(x), (x, Max(n1, n2)))) == \
@@ -729,7 +729,8 @@ def test_latex_derivatives():
 
 
 def test_latex_subs():
-    assert latex(Subs(x*y, (x, y), (1, 2))) == r'\left. x y \right|_{\substack{ x=1\\ y=2 }}'
+    assert latex(Subs(x*y, (
+        x, y), (1, 2))) == r'\left. x y \right|_{\substack{ x=1\\ y=2 }}'
 
 
 def test_latex_integrals():
@@ -798,7 +799,8 @@ def test_latex_Range():
     assert latex(Range(oo, -2, -2)) == r'\left\{\ldots, 2, 0\right\}'
     assert latex(Range(-2, -oo, -1)) == r'\left\{-2, -3, \ldots\right\}'
     assert latex(Range(-oo, oo)) == r'\left\{\ldots, -1, 0, 1, \ldots\right\}'
-    assert latex(Range(oo, -oo, -1)) == r'\left\{\ldots, 1, 0, -1, \ldots\right\}'
+    assert latex(Range(oo, -oo, -1)) == \
+        r'\left\{\ldots, 1, 0, -1, \ldots\right\}'
 
     a, b, c = symbols('a:c')
     assert latex(Range(a, b, c)) == r'Range\left(a, b, c\right)'
@@ -961,103 +963,103 @@ def test_set_operators_parenthesis():
     P2 = ProductSet(C, D)
 
     assert latex(Intersection(A, U2, evaluate=False)) == \
-        r'\left\{a\right\} \cap ' \
-        r'\left(\left\{c\right\} \cup \left\{d\right\}\right)'
+        '\\left\\{a\\right\\} \\cap ' \
+        '\\left(\\left\\{c\\right\\} \\cup \\left\\{d\\right\\}\\right)'
     assert latex(Intersection(U1, U2, evaluate=False)) == \
-        r'\left(\left\{a\right\} \cup \left\{b\right\}\right) ' \
-        r'\cap \left(\left\{c\right\} \cup \left\{d\right\}\right)'
+        '\\left(\\left\\{a\\right\\} \\cup \\left\\{b\\right\\}\\right) ' \
+        '\\cap \\left(\\left\\{c\\right\\} \\cup \\left\\{d\\right\\}\\right)'
     assert latex(Intersection(C1, C2, evaluate=False)) == \
-        r'\left(\left\{a\right\} \setminus ' \
-        r'\left\{b\right\}\right) \cap \left(\left\{c\right\} ' \
-        r'\setminus \left\{d\right\}\right)'
+        '\\left(\\left\\{a\\right\\} \\setminus ' \
+        '\\left\\{b\\right\\}\\right) \\cap \\left(\\left\\{c\\right\\} ' \
+        '\\setminus \\left\\{d\\right\\}\\right)'
     assert latex(Intersection(D1, D2, evaluate=False)) == \
-        r'\left(\left\{a\right\} \triangle ' \
-        r'\left\{b\right\}\right) \cap \left(\left\{c\right\} ' \
-        r'\triangle \left\{d\right\}\right)'
+        '\\left(\\left\\{a\\right\\} \\triangle ' \
+        '\\left\\{b\\right\\}\\right) \\cap \\left(\\left\\{c\\right\\} ' \
+        '\\triangle \\left\\{d\\right\\}\\right)'
     assert latex(Intersection(P1, P2, evaluate=False)) == \
-        r'\left(\left\{a\right\} \times \left\{b\right\}\right) ' \
-        r'\cap \left(\left\{c\right\} \times ' \
-        r'\left\{d\right\}\right)'
+        '\\left(\\left\\{a\\right\\} \\times \\left\\{b\\right\\}\\right) ' \
+        '\\cap \\left(\\left\\{c\\right\\} \\times ' \
+        '\\left\\{d\\right\\}\\right)'
 
     assert latex(Union(A, I2, evaluate=False)) == \
-        r'\left\{a\right\} \cup ' \
-        r'\left(\left\{c\right\} \cap \left\{d\right\}\right)'
+        '\\left\\{a\\right\\} \\cup ' \
+        '\\left(\\left\\{c\\right\\} \\cap \\left\\{d\\right\\}\\right)'
     assert latex(Union(I1, I2, evaluate=False)) == \
-        r'\left(\left\{a\right\} \cap \left\{b\right\}\right) ' \
-        r'\cup \left(\left\{c\right\} \cap \left\{d\right\}\right)'
+        '\\left(\\left\\{a\\right\\} \\cap ''\\left\\{b\\right\\}\\right) ' \
+        '\\cup \\left(\\left\\{c\\right\\} \\cap \\left\\{d\\right\\}\\right)'
     assert latex(Union(C1, C2, evaluate=False)) == \
-        r'\left(\left\{a\right\} \setminus ' \
-        r'\left\{b\right\}\right) \cup \left(\left\{c\right\} ' \
-        r'\setminus \left\{d\right\}\right)'
+        '\\left(\\left\\{a\\right\\} \\setminus ' \
+        '\\left\\{b\\right\\}\\right) \\cup \\left(\\left\\{c\\right\\} ' \
+        '\\setminus \\left\\{d\\right\\}\\right)'
     assert latex(Union(D1, D2, evaluate=False)) == \
-        r'\left(\left\{a\right\} \triangle ' \
-        r'\left\{b\right\}\right) \cup \left(\left\{c\right\} ' \
-        r'\triangle \left\{d\right\}\right)'
+        '\\left(\\left\\{a\\right\\} \\triangle ' \
+        '\\left\\{b\\right\\}\\right) \\cup \\left(\\left\\{c\\right\\} ' \
+        '\\triangle \\left\\{d\\right\\}\\right)'
     assert latex(Union(P1, P2, evaluate=False)) == \
-        r'\left(\left\{a\right\} \times \left\{b\right\}\right) ' \
-        r'\cup \left(\left\{c\right\} \times ' \
-        r'\left\{d\right\}\right)'
+        '\\left(\\left\\{a\\right\\} \\times \\left\\{b\\right\\}\\right) ' \
+        '\\cup \\left(\\left\\{c\\right\\} \\times ' \
+        '\\left\\{d\\right\\}\\right)'
 
     assert latex(Complement(A, C2, evaluate=False)) == \
-        r'\left\{a\right\} \setminus \left(\left\{c\right\} ' \
-        r'\setminus \left\{d\right\}\right)'
+        '\\left\\{a\\right\\} \\setminus \\left(\\left\\{c\\right\\} ' \
+        '\\setminus \\left\\{d\\right\\}\\right)'
     assert latex(Complement(U1, U2, evaluate=False)) == \
-        r'\left(\left\{a\right\} \cup \left\{b\right\}\right) ' \
-        r'\setminus \left(\left\{c\right\} \cup ' \
-        r'\left\{d\right\}\right)'
+        '\\left(\\left\\{a\\right\\} \\cup \\left\\{b\\right\\}\\right) ' \
+        '\\setminus \\left(\\left\\{c\\right\\} \\cup ' \
+        '\\left\\{d\\right\\}\\right)'
     assert latex(Complement(I1, I2, evaluate=False)) == \
-        r'\left(\left\{a\right\} \cap \left\{b\right\}\right) ' \
-        r'\setminus \left(\left\{c\right\} \cap ' \
-        r'\left\{d\right\}\right)'
+        '\\left(\\left\\{a\\right\\} \\cap \\left\\{b\\right\\}\\right) ' \
+        '\\setminus \\left(\\left\\{c\\right\\} \\cap ' \
+        '\\left\\{d\\right\\}\\right)'
     assert latex(Complement(D1, D2, evaluate=False)) == \
-        r'\left(\left\{a\right\} \triangle ' \
-        r'\left\{b\right\}\right) \setminus ' \
-        r'\left(\left\{c\right\} \triangle \left\{d\right\}\right)'
+        '\\left(\\left\\{a\\right\\} \\triangle ' \
+        '\\left\\{b\\right\\}\\right) \\setminus ' \
+        '\\left(\\left\\{c\\right\\} \\triangle \\left\\{d\\right\\}\\right)'
     assert latex(Complement(P1, P2, evaluate=False)) == \
-        r'\left(\left\{a\right\} \times \left\{b\right\}\right) '\
-        r'\setminus \left(\left\{c\right\} \times '\
-        r'\left\{d\right\}\right)'
+        '\\left(\\left\\{a\\right\\} \\times \\left\\{b\\right\\}\\right) '\
+        '\\setminus \\left(\\left\\{c\\right\\} \\times '\
+        '\\left\\{d\\right\\}\\right)'
 
     assert latex(SymmetricDifference(A, D2, evaluate=False)) == \
-        r'\left\{a\right\} \triangle \left(\left\{c\right\} ' \
-        r'\triangle \left\{d\right\}\right)'
+        '\\left\\{a\\right\\} \\triangle \\left(\\left\\{c\\right\\} ' \
+        '\\triangle \\left\\{d\\right\\}\\right)'
     assert latex(SymmetricDifference(U1, U2, evaluate=False)) == \
-        r'\left(\left\{a\right\} \cup \left\{b\right\}\right) ' \
-        r'\triangle \left(\left\{c\right\} \cup ' \
-        r'\left\{d\right\}\right)'
+        '\\left(\\left\\{a\\right\\} \\cup \\left\\{b\\right\\}\\right) ' \
+        '\\triangle \\left(\\left\\{c\\right\\} \\cup ' \
+        '\\left\\{d\\right\\}\\right)'
     assert latex(SymmetricDifference(I1, I2, evaluate=False)) == \
-        r'\left(\left\{a\right\} \cap \left\{b\right\}\right) ' \
-        r'\triangle \left(\left\{c\right\} \cap ' \
-        r'\left\{d\right\}\right)'
+        '\\left(\\left\\{a\\right\\} \\cap \\left\\{b\\right\\}\\right) ' \
+        '\\triangle \\left(\\left\\{c\\right\\} \\cap ' \
+        '\\left\\{d\\right\\}\\right)'
     assert latex(SymmetricDifference(C1, C2, evaluate=False)) == \
-        r'\left(\left\{a\right\} \setminus ' \
-        r'\left\{b\right\}\right) \triangle ' \
-        r'\left(\left\{c\right\} \setminus \left\{d\right\}\right)'
+        '\\left(\\left\\{a\\right\\} \\setminus ' \
+        '\\left\\{b\\right\\}\\right) \\triangle ' \
+        '\\left(\\left\\{c\\right\\} \\setminus \\left\\{d\\right\\}\\right)'
     assert latex(SymmetricDifference(P1, P2, evaluate=False)) == \
-        r'\left(\left\{a\right\} \times \left\{b\right\}\right) ' \
-        r'\triangle \left(\left\{c\right\} \times ' \
-        r'\left\{d\right\}\right)'
+        '\\left(\\left\\{a\\right\\} \\times \\left\\{b\\right\\}\\right) ' \
+        '\\triangle \\left(\\left\\{c\\right\\} \\times ' \
+        '\\left\\{d\\right\\}\\right)'
 
     # XXX This can be incorrect since cartesian product is not associative
     assert latex(ProductSet(A, P2).flatten()) == \
-        r'\left\{a\right\} \times \left\{c\right\} \times ' \
-        r'\left\{d\right\}'
+        '\\left\\{a\\right\\} \\times \\left\\{c\\right\\} \\times ' \
+        '\\left\\{d\\right\\}'
     assert latex(ProductSet(U1, U2)) == \
-        r'\left(\left\{a\right\} \cup \left\{b\right\}\right) ' \
-        r'\times \left(\left\{c\right\} \cup ' \
-        r'\left\{d\right\}\right)'
+        '\\left(\\left\\{a\\right\\} \\cup \\left\\{b\\right\\}\\right) ' \
+        '\\times \\left(\\left\\{c\\right\\} \\cup ' \
+        '\\left\\{d\\right\\}\\right)'
     assert latex(ProductSet(I1, I2)) == \
-        r'\left(\left\{a\right\} \cap \left\{b\right\}\right) ' \
-        r'\times \left(\left\{c\right\} \cap ' \
-        r'\left\{d\right\}\right)'
+        '\\left(\\left\\{a\\right\\} \\cap \\left\\{b\\right\\}\\right) ' \
+        '\\times \\left(\\left\\{c\\right\\} \\cap ' \
+        '\\left\\{d\\right\\}\\right)'
     assert latex(ProductSet(C1, C2)) == \
-        r'\left(\left\{a\right\} \setminus ' \
-        r'\left\{b\right\}\right) \times \left(\left\{c\right\} ' \
-        r'\setminus \left\{d\right\}\right)'
+        '\\left(\\left\\{a\\right\\} \\setminus ' \
+        '\\left\\{b\\right\\}\\right) \\times \\left(\\left\\{c\\right\\} ' \
+        '\\setminus \\left\\{d\\right\\}\\right)'
     assert latex(ProductSet(D1, D2)) == \
-        r'\left(\left\{a\right\} \triangle ' \
-        r'\left\{b\right\}\right) \times \left(\left\{c\right\} ' \
-        r'\triangle \left\{d\right\}\right)'
+        '\\left(\\left\\{a\\right\\} \\triangle ' \
+        '\\left\\{b\\right\\}\\right) \\times \\left(\\left\\{c\\right\\} ' \
+        '\\triangle \\left\\{d\\right\\}\\right)'
 
 
 def test_latex_Complexes():
@@ -1080,8 +1082,8 @@ def test_latex_ImageSet():
     x = Symbol('x')
     assert latex(ImageSet(Lambda(x, x**2), S.Naturals)) == \
         r"\left\{x^{2}\; \middle|\; x \in \mathbb{N}\right\}"
-
     y = Symbol('y')
+
     imgset = ImageSet(Lambda((x, y), x + y), {1, 2, 3}, {3, 4})
     assert latex(imgset) == \
         r"\left\{x + y\; \middle|\; x \in \left\{1, 2, 3\right\} , y \in \left\{3, 4\right\}\right\}"
@@ -1119,6 +1121,7 @@ def test_latex_sum():
         r"\sum_{x=-2}^{2} x^{2}"
     assert latex(Sum(x**2 + y, (x, -2, 2))) == \
         r"\sum_{x=-2}^{2} \left(x^{2} + y\right)"
+
     assert latex(Sum(x**2 + y, (x, -2, 2))**2) == \
         r"\left(\sum_{x=-2}^{2} \left(x^{2} + y\right)\right)^{2}"
 
@@ -1176,11 +1179,11 @@ def test_issue_3568():
 
 
 def test_latex():
-    assert latex((2*tau)**Rational(7, 2)) == r"8 \sqrt{2} \tau^{\frac{7}{2}}"
+    assert latex((2*tau)**Rational(7, 2)) == "8 \\sqrt{2} \\tau^{\\frac{7}{2}}"
     assert latex((2*mu)**Rational(7, 2), mode='equation*') == \
-        r"\begin{equation*}8 \sqrt{2} \mu^{\frac{7}{2}}\end{equation*}"
+        "\\begin{equation*}8 \\sqrt{2} \\mu^{\\frac{7}{2}}\\end{equation*}"
     assert latex((2*mu)**Rational(7, 2), mode='equation', itex=True) == \
-        r"$$8 \sqrt{2} \mu^{\frac{7}{2}}$$"
+        "$$8 \\sqrt{2} \\mu^{\\frac{7}{2}}$$"
     assert latex([2/x, y]) == r"\left[ \frac{2}{x}, \  y\right]"
 
 
@@ -1200,19 +1203,19 @@ def test_latex_list():
 
 def test_latex_rational():
     # tests issue 3973
-    assert latex(-Rational(1, 2)) == r"- \frac{1}{2}"
-    assert latex(Rational(-1, 2)) == r"- \frac{1}{2}"
-    assert latex(Rational(1, -2)) == r"- \frac{1}{2}"
-    assert latex(-Rational(-1, 2)) == r"\frac{1}{2}"
-    assert latex(-Rational(1, 2)*x) == r"- \frac{x}{2}"
+    assert latex(-Rational(1, 2)) == "- \\frac{1}{2}"
+    assert latex(Rational(-1, 2)) == "- \\frac{1}{2}"
+    assert latex(Rational(1, -2)) == "- \\frac{1}{2}"
+    assert latex(-Rational(-1, 2)) == "\\frac{1}{2}"
+    assert latex(-Rational(1, 2)*x) == "- \\frac{x}{2}"
     assert latex(-Rational(1, 2)*x + Rational(-2, 3)*y) == \
-        r"- \frac{x}{2} - \frac{2 y}{3}"
+        "- \\frac{x}{2} - \\frac{2 y}{3}"
 
 
 def test_latex_inverse():
     # tests issue 4129
-    assert latex(1/x) == r"\frac{1}{x}"
-    assert latex(1/(x + y)) == r"\frac{1}{x + y}"
+    assert latex(1/x) == "\\frac{1}{x}"
+    assert latex(1/(x + y)) == "\\frac{1}{x + y}"
 
 
 def test_latex_DiracDelta():
@@ -1250,13 +1253,13 @@ def test_latex_LeviCivita():
 
 def test_mode():
     expr = x + y
-    assert latex(expr) == r'x + y'
-    assert latex(expr, mode='plain') == r'x + y'
-    assert latex(expr, mode='inline') == r'$x + y$'
+    assert latex(expr) == 'x + y'
+    assert latex(expr, mode='plain') == 'x + y'
+    assert latex(expr, mode='inline') == '$x + y$'
     assert latex(
-        expr, mode='equation*') == r'\begin{equation*}x + y\end{equation*}'
+        expr, mode='equation*') == '\\begin{equation*}x + y\\end{equation*}'
     assert latex(
-        expr, mode='equation') == r'\begin{equation}x + y\end{equation}'
+        expr, mode='equation') == '\\begin{equation}x + y\\end{equation}'
     raises(ValueError, lambda: latex(expr, mode='foo'))
 
 
@@ -1272,14 +1275,14 @@ def test_latex_mathieu():
 
 def test_latex_Piecewise():
     p = Piecewise((x, x < 1), (x**2, True))
-    assert latex(p) == r"\begin{cases} x & \text{for}\: x < 1 \\x^{2} &" \
-                       r" \text{otherwise} \end{cases}"
+    assert latex(p) == "\\begin{cases} x & \\text{for}\\: x < 1 \\\\x^{2} &" \
+                       " \\text{otherwise} \\end{cases}"
     assert latex(p, itex=True) == \
-        r"\begin{cases} x & \text{for}\: x \lt 1 \\x^{2} &" \
-        r" \text{otherwise} \end{cases}"
+        "\\begin{cases} x & \\text{for}\\: x \\lt 1 \\\\x^{2} &" \
+        " \\text{otherwise} \\end{cases}"
     p = Piecewise((x, x < 0), (0, x >= 0))
-    assert latex(p) == r'\begin{cases} x & \text{for}\: x < 0 \\0 &' \
-                       r' \text{otherwise} \end{cases}'
+    assert latex(p) == '\\begin{cases} x & \\text{for}\\: x < 0 \\\\0 &' \
+                       ' \\text{otherwise} \\end{cases}'
     A, B = symbols("A B", commutative=False)
     p = Piecewise((A**2, Eq(A, B)), (A*B, True))
     s = r"\begin{cases} A^{2} & \text{for}\: A = B \\A B & \text{otherwise} \end{cases}"
@@ -1287,8 +1290,8 @@ def test_latex_Piecewise():
     assert latex(A*p) == r"A \left(%s\right)" % s
     assert latex(p*A) == r"\left(%s\right) A" % s
     assert latex(Piecewise((x, x < 1), (x**2, x < 2))) == \
-        r'\begin{cases} x & ' \
-        r'\text{for}\: x < 1 \\x^{2} & \text{for}\: x < 2 \end{cases}'
+        '\\begin{cases} x & ' \
+        '\\text{for}\\: x < 1 \\\\x^{2} & \\text{for}\\: x < 2 \\end{cases}'
 
 
 def test_latex_Matrix():
@@ -1304,7 +1307,6 @@ def test_latex_Matrix():
         r'\left[\begin{bmatrix}x + 1 & y\\y & x - 1\end{bmatrix}\right]'
     assert latex(M, mat_delim=None, mat_str='bmatrix') == \
         r'\begin{bmatrix}x + 1 & y\\y & x - 1\end{bmatrix}'
-
     M2 = Matrix(1, 11, range(11))
     assert latex(M2) == \
         r'\left[\begin{array}{ccccccccccc}' \
@@ -1337,7 +1339,7 @@ def test_latex_NDimArray():
         # Basic: scalar array
         M = ArrayType(x)
 
-        assert latex(M) == r"x"
+        assert latex(M) == "x"
 
         M = ArrayType([[1 / x, y], [z, w]])
         M1 = ArrayType([1 / x, y, z])
@@ -1346,9 +1348,9 @@ def test_latex_NDimArray():
         M3 = tensorproduct(M, M)
 
         assert latex(M) == \
-            r'\left[\begin{matrix}\frac{1}{x} & y\\z & w\end{matrix}\right]'
+            '\\left[\\begin{matrix}\\frac{1}{x} & y\\\\z & w\\end{matrix}\\right]'
         assert latex(M1) == \
-            r"\left[\begin{matrix}\frac{1}{x} & y & z\end{matrix}\right]"
+            "\\left[\\begin{matrix}\\frac{1}{x} & y & z\\end{matrix}\\right]"
         assert latex(M2) == \
             r"\left[\begin{matrix}" \
             r"\left[\begin{matrix}\frac{1}{x^{2}} & \frac{y}{x}\\\frac{z}{x} & \frac{w}{x}\end{matrix}\right] & " \
@@ -1376,12 +1378,12 @@ def test_latex_NDimArray():
 
 
 def test_latex_mul_symbol():
-    assert latex(4*4**x, mul_symbol='times') == r"4 \times 4^{x}"
-    assert latex(4*4**x, mul_symbol='dot') == r"4 \cdot 4^{x}"
+    assert latex(4*4**x, mul_symbol='times') == "4 \\times 4^{x}"
+    assert latex(4*4**x, mul_symbol='dot') == "4 \\cdot 4^{x}"
     assert latex(4*4**x, mul_symbol='ldot') == r"4 \,.\, 4^{x}"
 
-    assert latex(4*x, mul_symbol='times') == r"4 \times x"
-    assert latex(4*x, mul_symbol='dot') == r"4 \cdot x"
+    assert latex(4*x, mul_symbol='times') == "4 \\times x"
+    assert latex(4*x, mul_symbol='dot') == "4 \\cdot x"
     assert latex(4*x, mul_symbol='ldot') == r"4 \,.\, x"
 
 
@@ -1417,37 +1419,40 @@ def test_latex_issue_4576():
 def test_latex_pow_fraction():
     x = Symbol('x')
     # Testing exp
-    assert r'e^{-x}' in latex(exp(-x)/2).replace(' ', '')  # Remove Whitespace
+    assert 'e^{-x}' in latex(exp(-x)/2).replace(' ', '')  # Remove Whitespace
 
     # Testing e^{-x} in case future changes alter behavior of muls or fracs
     # In particular current output is \frac{1}{2}e^{- x} but perhaps this will
     # change to \frac{e^{-x}}{2}
 
     # Testing general, non-exp, power
-    assert r'3^{-x}' in latex(3**-x/2).replace(' ', '')
+    assert '3^{-x}' in latex(3**-x/2).replace(' ', '')
 
 
 def test_noncommutative():
     A, B, C = symbols('A,B,C', commutative=False)
 
-    assert latex(A*B*C**-1) == r"A B C^{-1}"
-    assert latex(C**-1*A*B) == r"C^{-1} A B"
-    assert latex(A*C**-1*B) == r"A C^{-1} B"
+    assert latex(A*B*C**-1) == "A B C^{-1}"
+    assert latex(C**-1*A*B) == "C^{-1} A B"
+    assert latex(A*C**-1*B) == "A C^{-1} B"
 
 
 def test_latex_order():
     expr = x**3 + x**2*y + y**4 + 3*x*y**3
 
-    assert latex(expr, order='lex') == r"x^{3} + x^{2} y + 3 x y^{3} + y^{4}"
+    assert latex(expr, order='lex') == "x^{3} + x^{2} y + 3 x y^{3} + y^{4}"
     assert latex(
-        expr, order='rev-lex') == r"y^{4} + 3 x y^{3} + x^{2} y + x^{3}"
-    assert latex(expr, order='none') == r"x^{3} + y^{4} + y x^{2} + 3 x y^{3}"
+        expr, order='rev-lex') == "y^{4} + 3 x y^{3} + x^{2} y + x^{3}"
+    assert latex(expr, order='none') == "x^{3} + y^{4} + y x^{2} + 3 x y^{3}"
 
 
 def test_latex_Lambda():
-    assert latex(Lambda(x, x + 1)) == r"\left( x \mapsto x + 1 \right)"
-    assert latex(Lambda((x, y), x + 1)) == r"\left( \left( x, \  y\right) \mapsto x + 1 \right)"
-    assert latex(Lambda(x, x)) == r"\left( x \mapsto x \right)"
+    assert latex(Lambda(x, x + 1)) == \
+        r"\left( x \mapsto x + 1 \right)"
+    assert latex(Lambda((x, y), x + 1)) == \
+        r"\left( \left( x, \  y\right) \mapsto x + 1 \right)"
+    assert latex(Lambda(x, x)) == \
+        r"\left( x \mapsto x \right)"
 
 def test_latex_PolyElement():
     Ruv, u, v = ring("u,v", ZZ)
@@ -1510,15 +1515,15 @@ def test_latex_Poly():
 
 def test_latex_Poly_order():
     assert latex(Poly([a, 1, b, 2, c, 3], x)) == \
-        r'\operatorname{Poly}{\left( a x^{5} + x^{4} + b x^{3} + 2 x^{2} + c'\
-        r' x + 3, x, domain=\mathbb{Z}\left[a, b, c\right] \right)}'
+        '\\operatorname{Poly}{\\left( a x^{5} + x^{4} + b x^{3} + 2 x^{2} + c'\
+        ' x + 3, x, domain=\\mathbb{Z}\\left[a, b, c\\right] \\right)}'
     assert latex(Poly([a, 1, b+c, 2, 3], x)) == \
-        r'\operatorname{Poly}{\left( a x^{4} + x^{3} + \left(b + c\right) '\
-        r'x^{2} + 2 x + 3, x, domain=\mathbb{Z}\left[a, b, c\right] \right)}'
+        '\\operatorname{Poly}{\\left( a x^{4} + x^{3} + \\left(b + c\\right) '\
+        'x^{2} + 2 x + 3, x, domain=\\mathbb{Z}\\left[a, b, c\\right] \\right)}'
     assert latex(Poly(a*x**3 + x**2*y - x*y - c*y**3 - b*x*y**2 + y - a*x + b,
                       (x, y))) == \
-        r'\operatorname{Poly}{\left( a x^{3} + x^{2}y -  b xy^{2} - xy -  '\
-        r'a x -  c y^{3} + y + b, x, y, domain=\mathbb{Z}\left[a, b, c\right] \right)}'
+        '\\operatorname{Poly}{\\left( a x^{3} + x^{2}y -  b xy^{2} - xy -  '\
+        'a x -  c y^{3} + y + b, x, y, domain=\\mathbb{Z}\\left[a, b, c\\right] \\right)}'
 
 
 def test_latex_ComplexRootOf():
@@ -1574,11 +1579,11 @@ def test_lamda():
 def test_custom_symbol_names():
     x = Symbol('x')
     y = Symbol('y')
-    assert latex(x) == r"x"
-    assert latex(x, symbol_names={x: "x_i"}) == r"x_i"
-    assert latex(x + y, symbol_names={x: "x_i"}) == r"x_i + y"
-    assert latex(x**2, symbol_names={x: "x_i"}) == r"x_i^{2}"
-    assert latex(x + y, symbol_names={x: "x_i", y: "y_j"}) == r"x_i + y_j"
+    assert latex(x) == "x"
+    assert latex(x, symbol_names={x: "x_i"}) == "x_i"
+    assert latex(x + y, symbol_names={x: "x_i"}) == "x_i + y"
+    assert latex(x**2, symbol_names={x: "x_i"}) == "x_i^{2}"
+    assert latex(x + y, symbol_names={x: "x_i", y: "y_j"}) == "x_i + y_j"
 
 
 def test_matAdd():
@@ -1587,10 +1592,10 @@ def test_matAdd():
     C = MatrixSymbol('C', 5, 5)
     B = MatrixSymbol('B', 5, 5)
     l = LatexPrinter()
-    assert l._print(C - 2*B) in [r'- 2 B + C', r'C -2 B']
-    assert l._print(C + 2*B) in [r'2 B + C', r'C + 2 B']
-    assert l._print(B - 2*C) in [r'B - 2 C', r'- 2 C + B']
-    assert l._print(B + 2*C) in [r'B + 2 C', r'2 C + B']
+    assert l._print(C - 2*B) in ['- 2 B + C', 'C -2 B']
+    assert l._print(C + 2*B) in ['2 B + C', 'C + 2 B']
+    assert l._print(B - 2*C) in ['B - 2 C', '- 2 C + B']
+    assert l._print(B + 2*C) in ['B + 2 C', '2 C + B']
 
 
 def test_matMul():
@@ -1600,10 +1605,10 @@ def test_matMul():
     B = MatrixSymbol('B', 5, 5)
     x = Symbol('x')
     lp = LatexPrinter()
-    assert lp._print_MatMul(2*A) == r'2 A'
-    assert lp._print_MatMul(2*x*A) == r'2 x A'
-    assert lp._print_MatMul(-2*A) == r'- 2 A'
-    assert lp._print_MatMul(1.5*A) == r'1.5 A'
+    assert lp._print_MatMul(2*A) == '2 A'
+    assert lp._print_MatMul(2*x*A) == '2 x A'
+    assert lp._print_MatMul(-2*A) == '- 2 A'
+    assert lp._print_MatMul(1.5*A) == '1.5 A'
     assert lp._print_MatMul(sqrt(2)*A) == r'\sqrt{2} A'
     assert lp._print_MatMul(-sqrt(2)*A) == r'- \sqrt{2} A'
     assert lp._print_MatMul(2*sqrt(2)*x*A) == r'2 \sqrt{2} x A'
@@ -1727,10 +1732,10 @@ def test_categories():
 
     K1 = Category("K1")
 
-    assert latex(A1) == r"A_{1}"
-    assert latex(f1) == r"f_{1}:A_{1}\rightarrow A_{2}"
-    assert latex(id_A1) == r"id:A_{1}\rightarrow A_{1}"
-    assert latex(f2*f1) == r"f_{2}\circ f_{1}:A_{1}\rightarrow A_{3}"
+    assert latex(A1) == "A_{1}"
+    assert latex(f1) == "f_{1}:A_{1}\\rightarrow A_{2}"
+    assert latex(id_A1) == "id:A_{1}\\rightarrow A_{1}"
+    assert latex(f2*f1) == "f_{2}\\circ f_{1}:A_{1}\\rightarrow A_{3}"
 
     assert latex(K1) == r"\mathbf{K_{1}}"
 
@@ -1764,10 +1769,10 @@ def test_categories():
     d = Diagram([f, g])
     grid = DiagramGrid(d)
 
-    assert latex(grid) == r"\begin{array}{cc}" + "\n" \
-        r"A & B \\" + "\n" \
-        r" & C " + "\n" \
-        r"\end{array}" + "\n"
+    assert latex(grid) == "\\begin{array}{cc}\n" \
+        "A & B \\\\\n" \
+        " & C \n" \
+        "\\end{array}\n"
 
 
 def test_Modules():
@@ -1844,10 +1849,14 @@ def test_Transpose():
     assert latex(Transpose(X)) == r'X^{T}'
     assert latex(Transpose(X + Y)) == r'\left(X + Y\right)^{T}'
 
-    assert latex(Transpose(HadamardPower(X, 2))) == r'\left(X^{\circ {2}}\right)^{T}'
-    assert latex(HadamardPower(Transpose(X), 2)) == r'\left(X^{T}\right)^{\circ {2}}'
-    assert latex(Transpose(MatPow(X, 2))) == r'\left(X^{2}\right)^{T}'
-    assert latex(MatPow(Transpose(X), 2)) == r'\left(X^{T}\right)^{2}'
+    assert latex(Transpose(HadamardPower(X, 2))) == \
+        r'\left(X^{\circ {2}}\right)^{T}'
+    assert latex(HadamardPower(Transpose(X), 2)) == \
+        r'\left(X^{T}\right)^{\circ {2}}'
+    assert latex(Transpose(MatPow(X, 2))) == \
+        r'\left(X^{2}\right)^{T}'
+    assert latex(MatPow(Transpose(X), 2)) == \
+        r'\left(X^{T}\right)^{2}'
 
 
 def test_Hadamard():
@@ -1905,18 +1914,18 @@ def test_boolean_args_order():
     syms = symbols('a:f')
 
     expr = And(*syms)
-    assert latex(expr) == r'a \wedge b \wedge c \wedge d \wedge e \wedge f'
+    assert latex(expr) == 'a \\wedge b \\wedge c \\wedge d \\wedge e \\wedge f'
 
     expr = Or(*syms)
-    assert latex(expr) == r'a \vee b \vee c \vee d \vee e \vee f'
+    assert latex(expr) == 'a \\vee b \\vee c \\vee d \\vee e \\vee f'
 
     expr = Equivalent(*syms)
     assert latex(expr) == \
-        r'a \Leftrightarrow b \Leftrightarrow c \Leftrightarrow d \Leftrightarrow e \Leftrightarrow f'
+        'a \\Leftrightarrow b \\Leftrightarrow c \\Leftrightarrow d \\Leftrightarrow e \\Leftrightarrow f'
 
     expr = Xor(*syms)
     assert latex(expr) == \
-        r'a \veebar b \veebar c \veebar d \veebar e \veebar f'
+        'a \\veebar b \\veebar c \\veebar d \\veebar e \\veebar f'
 
 
 def test_imaginary():
@@ -1958,13 +1967,13 @@ def test_latex_greek_functions():
 
 def test_translate():
     s = 'Alpha'
-    assert translate(s) == r'A'
+    assert translate(s) == 'A'
     s = 'Beta'
-    assert translate(s) == r'B'
+    assert translate(s) == 'B'
     s = 'Eta'
-    assert translate(s) == r'H'
+    assert translate(s) == 'H'
     s = 'omicron'
-    assert translate(s) == r'o'
+    assert translate(s) == 'o'
     s = 'Pi'
     assert translate(s) == r'\Pi'
     s = 'pi'
@@ -1976,7 +1985,7 @@ def test_translate():
 def test_other_symbols():
     from sympy.printing.latex import other_symbols
     for s in other_symbols:
-        assert latex(symbols(s)) == r"" "\\" + s
+        assert latex(symbols(s)) == "\\"+s
 
 
 def test_modifiers():
@@ -2096,12 +2105,12 @@ def test_greek_symbols():
 
 
 def test_fancyset_symbols():
-    assert latex(S.Rationals) == r'\mathbb{Q}'
-    assert latex(S.Naturals) == r'\mathbb{N}'
-    assert latex(S.Naturals0) == r'\mathbb{N}_0'
-    assert latex(S.Integers) == r'\mathbb{Z}'
-    assert latex(S.Reals) == r'\mathbb{R}'
-    assert latex(S.Complexes) == r'\mathbb{C}'
+    assert latex(S.Rationals) == '\\mathbb{Q}'
+    assert latex(S.Naturals) == '\\mathbb{N}'
+    assert latex(S.Naturals0) == '\\mathbb{N}_0'
+    assert latex(S.Integers) == '\\mathbb{Z}'
+    assert latex(S.Reals) == '\\mathbb{R}'
+    assert latex(S.Complexes) == '\\mathbb{C}'
 
 
 @XFAIL
@@ -2172,11 +2181,11 @@ def test_issue_15439():
 
 
 def test_issue_2934():
-    assert latex(Symbol(r'\frac{a_1}{b_1}')) == r'\frac{a_1}{b_1}'
+    assert latex(Symbol(r'\frac{a_1}{b_1}')) == '\\frac{a_1}{b_1}'
 
 
 def test_issue_10489():
-    latexSymbolWithBrace = r'C_{x_{0}}'
+    latexSymbolWithBrace = 'C_{x_{0}}'
     s = Symbol(latexSymbolWithBrace)
     assert latex(s) == latexSymbolWithBrace
     assert latex(cos(s)) == r'\cos{\left(C_{x_{0}} \right)}'
@@ -2249,11 +2258,11 @@ def test_Series_printing():
     tf2 = TransferFunction(x - y, x + y, y)
     tf3 = TransferFunction(t*x**2 - t**w*x + w, t - y, y)
     assert latex(Series(tf1, tf2)) == \
-        r'\left(\frac{x y^{2} - z}{- t^{3} + y^{3}}\right) \left(\frac{x - y}{x + y}\right)'
+        '\\left(\\frac{x y^{2} - z}{- t^{3} + y^{3}}\\right) \\left(\\frac{x - y}{x + y}\\right)'
     assert latex(Series(tf1, tf2, tf3)) == \
-        r'\left(\frac{x y^{2} - z}{- t^{3} + y^{3}}\right) \left(\frac{x - y}{x + y}\right) \left(\frac{t x^{2} - t^{w} x + w}{t - y}\right)'
+        '\\left(\\frac{x y^{2} - z}{- t^{3} + y^{3}}\\right) \\left(\\frac{x - y}{x + y}\\right) \\left(\\frac{t x^{2} - t^{w} x + w}{t - y}\\right)'
     assert latex(Series(-tf2, tf1)) == \
-        r'\left(\frac{- x + y}{x + y}\right) \left(\frac{x y^{2} - z}{- t^{3} + y^{3}}\right)'
+        '\\left(\\frac{- x + y}{x + y}\\right) \\left(\\frac{x y^{2} - z}{- t^{3} + y^{3}}\\right)'
 
 
 def test_TransferFunction_printing():
@@ -2269,25 +2278,25 @@ def test_Parallel_printing():
     tf1 = TransferFunction(x*y**2 - z, y**3 - t**3, y)
     tf2 = TransferFunction(x - y, x + y, y)
     assert latex(Parallel(tf1, tf2)) == \
-        r'\left(\frac{x y^{2} - z}{- t^{3} + y^{3}}\right) \left(\frac{x - y}{x + y}\right)'
+        '\\left(\\frac{x y^{2} - z}{- t^{3} + y^{3}}\\right) \\left(\\frac{x - y}{x + y}\\right)'
     assert latex(Parallel(-tf2, tf1)) == \
-        r'\left(\frac{- x + y}{x + y}\right) \left(\frac{x y^{2} - z}{- t^{3} + y^{3}}\right)'
+        '\\left(\\frac{- x + y}{x + y}\\right) \\left(\\frac{x y^{2} - z}{- t^{3} + y^{3}}\\right)'
 
 
 def test_Feedback_printing():
     tf1 = TransferFunction(p, p + x, p)
     tf2 = TransferFunction(-s + p, p + s, p)
     assert latex(Feedback(tf1, tf2)) == \
-        r'\frac{\frac{p}{p + x}}{\left(1 \cdot 1^{-1}\right) \left(\left(\frac{p}{p + x}\right) \left(\frac{p - s}{p + s}\right)\right)}'
+        '\\frac{\\frac{p}{p + x}}{\\left(1 \\cdot 1^{-1}\\right) \\left(\\left(\\frac{p}{p + x}\\right) \\left(\\frac{p - s}{p + s}\\right)\\right)}'
     assert latex(Feedback(tf1*tf2, TransferFunction(1, 1, p))) == \
-        r'\frac{\left(\frac{p}{p + x}\right) \left(\frac{p - s}{p + s}\right)}{\left(1 \cdot 1^{-1}\right) \left(\left(\frac{p}{p + x}\right) \left(\frac{p - s}{p + s}\right)\right)}'
+        '\\frac{\\left(\\frac{p}{p + x}\\right) \\left(\\frac{p - s}{p + s}\\right)}{\\left(1 \\cdot 1^{-1}\\right) \\left(\\left(\\frac{p}{p + x}\\right) \\left(\\frac{p - s}{p + s}\\right)\\right)}'
 
 
 def test_Quaternion_latex_printing():
     q = Quaternion(x, y, z, t)
-    assert latex(q) == r"x + y i + z j + t k"
+    assert latex(q) == "x + y i + z j + t k"
     q = Quaternion(x, y, z, x*t)
-    assert latex(q) == r"x + y i + z j + t x k"
+    assert latex(q) == "x + y i + z j + t x k"
     q = Quaternion(x, y, z, x + t)
     assert latex(q) == r"x + y i + z j + \left(t + x\right) k"
 
@@ -2329,71 +2338,71 @@ def test_latex_printer_tensor():
     H = TensorHead("H", [L, L])
     K = TensorHead("K", [L, L, L, L])
 
-    assert latex(i) == r"{}^{i}"
-    assert latex(-i) == r"{}_{i}"
+    assert latex(i) == "{}^{i}"
+    assert latex(-i) == "{}_{i}"
 
     expr = A(i)
-    assert latex(expr) == r"A{}^{i}"
+    assert latex(expr) == "A{}^{i}"
 
     expr = A(i0)
-    assert latex(expr) == r"A{}^{i_{0}}"
+    assert latex(expr) == "A{}^{i_{0}}"
 
     expr = A(-i)
-    assert latex(expr) == r"A{}_{i}"
+    assert latex(expr) == "A{}_{i}"
 
     expr = -3*A(i)
     assert latex(expr) == r"-3A{}^{i}"
 
     expr = K(i, j, -k, -i0)
-    assert latex(expr) == r"K{}^{ij}{}_{ki_{0}}"
+    assert latex(expr) == "K{}^{ij}{}_{ki_{0}}"
 
     expr = K(i, -j, -k, i0)
-    assert latex(expr) == r"K{}^{i}{}_{jk}{}^{i_{0}}"
+    assert latex(expr) == "K{}^{i}{}_{jk}{}^{i_{0}}"
 
     expr = K(i, -j, k, -i0)
-    assert latex(expr) == r"K{}^{i}{}_{j}{}^{k}{}_{i_{0}}"
+    assert latex(expr) == "K{}^{i}{}_{j}{}^{k}{}_{i_{0}}"
 
     expr = H(i, -j)
-    assert latex(expr) == r"H{}^{i}{}_{j}"
+    assert latex(expr) == "H{}^{i}{}_{j}"
 
     expr = H(i, j)
-    assert latex(expr) == r"H{}^{ij}"
+    assert latex(expr) == "H{}^{ij}"
 
     expr = H(-i, -j)
-    assert latex(expr) == r"H{}_{ij}"
+    assert latex(expr) == "H{}_{ij}"
 
     expr = (1+x)*A(i)
     assert latex(expr) == r"\left(x + 1\right)A{}^{i}"
 
     expr = H(i, -i)
-    assert latex(expr) == r"H{}^{L_{0}}{}_{L_{0}}"
+    assert latex(expr) == "H{}^{L_{0}}{}_{L_{0}}"
 
     expr = H(i, -j)*A(j)*B(k)
-    assert latex(expr) == r"H{}^{i}{}_{L_{0}}A{}^{L_{0}}B{}^{k}"
+    assert latex(expr) == "H{}^{i}{}_{L_{0}}A{}^{L_{0}}B{}^{k}"
 
     expr = A(i) + 3*B(i)
-    assert latex(expr) == r"3B{}^{i} + A{}^{i}"
+    assert latex(expr) == "3B{}^{i} + A{}^{i}"
 
     # Test ``TensorElement``:
     from sympy.tensor.tensor import TensorElement
 
     expr = TensorElement(K(i, j, k, l), {i: 3, k: 2})
-    assert latex(expr) == r'K{}^{i=3,j,k=2,l}'
+    assert latex(expr) == 'K{}^{i=3,j,k=2,l}'
 
     expr = TensorElement(K(i, j, k, l), {i: 3})
-    assert latex(expr) == r'K{}^{i=3,jkl}'
+    assert latex(expr) == 'K{}^{i=3,jkl}'
 
     expr = TensorElement(K(i, -j, k, l), {i: 3, k: 2})
-    assert latex(expr) == r'K{}^{i=3}{}_{j}{}^{k=2,l}'
+    assert latex(expr) == 'K{}^{i=3}{}_{j}{}^{k=2,l}'
 
     expr = TensorElement(K(i, -j, k, -l), {i: 3, k: 2})
-    assert latex(expr) == r'K{}^{i=3}{}_{j}{}^{k=2}{}_{l}'
+    assert latex(expr) == 'K{}^{i=3}{}_{j}{}^{k=2}{}_{l}'
 
     expr = TensorElement(K(i, j, -k, -l), {i: 3, -k: 2})
-    assert latex(expr) == r'K{}^{i=3,j}{}_{k=2,l}'
+    assert latex(expr) == 'K{}^{i=3,j}{}_{k=2,l}'
 
     expr = TensorElement(K(i, j, -k, -l), {i: 3})
-    assert latex(expr) == r'K{}^{i=3,j}{}_{kl}'
+    assert latex(expr) == 'K{}^{i=3,j}{}_{kl}'
 
     expr = PartialDerivative(A(i), A(i))
     assert latex(expr) == r"\frac{\partial}{\partial {A{}^{L_{0}}}}{A{}^{L_{0}}}"
@@ -2415,49 +2424,49 @@ def test_multiline_latex():
     a, b, c, d, e, f = symbols('a b c d e f')
     expr = -a + 2*b -3*c +4*d -5*e
     expected = r"\begin{eqnarray}" + "\n"\
-        r"f & = &- a \nonumber\\" + "\n"\
-        r"& & + 2 b \nonumber\\" + "\n"\
-        r"& & - 3 c \nonumber\\" + "\n"\
-        r"& & + 4 d \nonumber\\" + "\n"\
-        r"& & - 5 e " + "\n"\
-        r"\end{eqnarray}"
+    r"f & = &- a \nonumber\\" + "\n"\
+    r"& & + 2 b \nonumber\\" + "\n"\
+    r"& & - 3 c \nonumber\\" + "\n"\
+    r"& & + 4 d \nonumber\\" + "\n"\
+    r"& & - 5 e " + "\n"\
+    r"\end{eqnarray}"
     assert multiline_latex(f, expr, environment="eqnarray") == expected
 
     expected2 = r'\begin{eqnarray}' + '\n'\
-        r'f & = &- a + 2 b \nonumber\\' + '\n'\
-        r'& & - 3 c + 4 d \nonumber\\' + '\n'\
-        r'& & - 5 e ' + '\n'\
-        r'\end{eqnarray}'
+    r'f & = &- a + 2 b \nonumber\\' + '\n'\
+    r'& & - 3 c + 4 d \nonumber\\' + '\n'\
+    r'& & - 5 e ' + '\n'\
+    r'\end{eqnarray}'
 
     assert multiline_latex(f, expr, 2, environment="eqnarray") == expected2
 
     expected3 = r'\begin{eqnarray}' + '\n'\
-        r'f & = &- a + 2 b - 3 c \nonumber\\'+ '\n'\
-        r'& & + 4 d - 5 e ' + '\n'\
-        r'\end{eqnarray}'
+    r'f & = &- a + 2 b - 3 c \nonumber\\'+ '\n'\
+    r'& & + 4 d - 5 e ' + '\n'\
+    r'\end{eqnarray}'
 
     assert multiline_latex(f, expr, 3, environment="eqnarray") == expected3
 
     expected3dots = r'\begin{eqnarray}' + '\n'\
-        r'f & = &- a + 2 b - 3 c \dots\nonumber\\'+ '\n'\
-        r'& & + 4 d - 5 e ' + '\n'\
-        r'\end{eqnarray}'
+    r'f & = &- a + 2 b - 3 c \dots\nonumber\\'+ '\n'\
+    r'& & + 4 d - 5 e ' + '\n'\
+    r'\end{eqnarray}'
 
     assert multiline_latex(f, expr, 3, environment="eqnarray", use_dots=True) == expected3dots
 
     expected3align = r'\begin{align*}' + '\n'\
-        r'f = &- a + 2 b - 3 c \\'+ '\n'\
-        r'& + 4 d - 5 e ' + '\n'\
-        r'\end{align*}'
+    r'f = &- a + 2 b - 3 c \\'+ '\n'\
+    r'& + 4 d - 5 e ' + '\n'\
+    r'\end{align*}'
 
     assert multiline_latex(f, expr, 3) == expected3align
     assert multiline_latex(f, expr, 3, environment='align*') == expected3align
 
     expected2ieee = r'\begin{IEEEeqnarray}{rCl}' + '\n'\
-        r'f & = &- a + 2 b \nonumber\\' + '\n'\
-        r'& & - 3 c + 4 d \nonumber\\' + '\n'\
-        r'& & - 5 e ' + '\n'\
-        r'\end{IEEEeqnarray}'
+    r'f & = &- a + 2 b \nonumber\\' + '\n'\
+    r'& & - 3 c + 4 d \nonumber\\' + '\n'\
+    r'& & - 5 e ' + '\n'\
+    r'\end{IEEEeqnarray}'
 
     assert multiline_latex(f, expr, 2, environment="IEEEeqnarray") == expected2ieee
 
@@ -2551,19 +2560,19 @@ def test_PermutationMatrix():
 
 
 def test_imaginary_unit():
-    assert latex(1 + I) == r'1 + i'
-    assert latex(1 + I, imaginary_unit='i') == r'1 + i'
-    assert latex(1 + I, imaginary_unit='j') == r'1 + j'
-    assert latex(1 + I, imaginary_unit='foo') == r'1 + foo'
-    assert latex(I, imaginary_unit="ti") == r'\text{i}'
-    assert latex(I, imaginary_unit="tj") == r'\text{j}'
+    assert latex(1 + I) == '1 + i'
+    assert latex(1 + I, imaginary_unit='i') == '1 + i'
+    assert latex(1 + I, imaginary_unit='j') == '1 + j'
+    assert latex(1 + I, imaginary_unit='foo') == '1 + foo'
+    assert latex(I, imaginary_unit="ti") == '\\text{i}'
+    assert latex(I, imaginary_unit="tj") == '\\text{j}'
 
 
 def test_text_re_im():
-    assert latex(im(x), gothic_re_im=True) == r'\Im{\left(x\right)}'
-    assert latex(im(x), gothic_re_im=False) == r'\operatorname{im}{\left(x\right)}'
-    assert latex(re(x), gothic_re_im=True) == r'\Re{\left(x\right)}'
-    assert latex(re(x), gothic_re_im=False) == r'\operatorname{re}{\left(x\right)}'
+    assert latex(im(x), gothic_re_im=True) ==  r'\Im{\left(x\right)}'
+    assert latex(im(x), gothic_re_im=False) ==  r'\operatorname{im}{\left(x\right)}'
+    assert latex(re(x), gothic_re_im=True) ==  r'\Re{\left(x\right)}'
+    assert latex(re(x), gothic_re_im=False) ==  r'\operatorname{re}{\left(x\right)}'
 
 
 def test_latex_diffgeom():
@@ -2577,7 +2586,7 @@ def test_latex_diffgeom():
     rect = CoordSystem('rect', p, [x, y])
     assert latex(rect) == r'\text{rect}^{\text{P}}_{\text{M}}'
     b = BaseScalarField(rect, 0)
-    assert latex(b) == r'\mathbf{x}'
+    assert latex(b) ==  r'\mathbf{x}'
 
     g = Function('g')
     s_field = g(R2.x, R2.y)
@@ -2620,26 +2629,26 @@ def test_latex_decimal_separator():
     assert(latex((1, 2.3, 4.6)) == r'\left( 1, \  2.3, \  4.6\right)')
     assert(latex((1,)) == r'\left( 1,\right)')
 
-    assert(latex(Mul(3.4,5.3), decimal_separator = 'comma') == r'18{,}02')
-    assert(latex(3.4*5.3, decimal_separator = 'comma') == r'18{,}02')
+    assert(latex(Mul(3.4,5.3), decimal_separator = 'comma') ==r'18{,}02')
+    assert(latex(3.4*5.3, decimal_separator = 'comma')==r'18{,}02')
     x = symbols('x')
     y = symbols('y')
     z = symbols('z')
-    assert(latex(x*5.3 + 2**y**3.4 + 4.5 + z, decimal_separator = 'comma') == r'2^{y^{3{,}4}} + 5{,}3 x + z + 4{,}5')
+    assert(latex(x*5.3 + 2**y**3.4 + 4.5 + z, decimal_separator = 'comma')== r'2^{y^{3{,}4}} + 5{,}3 x + z + 4{,}5')
 
     assert(latex(0.987, decimal_separator='comma') == r'0{,}987')
-    assert(latex(S(0.987), decimal_separator='comma') == r'0{,}987')
-    assert(latex(.3, decimal_separator='comma') == r'0{,}3')
-    assert(latex(S(.3), decimal_separator='comma') == r'0{,}3')
+    assert(latex(S(0.987), decimal_separator='comma')== r'0{,}987')
+    assert(latex(.3, decimal_separator='comma')== r'0{,}3')
+    assert(latex(S(.3), decimal_separator='comma')== r'0{,}3')
 
 
-    assert(latex(5.8*10**(-7), decimal_separator='comma') == r'5{,}8 \cdot 10^{-7}')
-    assert(latex(S(5.7)*10**(-7), decimal_separator='comma') == r'5{,}7 \cdot 10^{-7}')
-    assert(latex(S(5.7*10**(-7)), decimal_separator='comma') == r'5{,}7 \cdot 10^{-7}')
+    assert(latex(5.8*10**(-7), decimal_separator='comma') ==r'5{,}8 \cdot 10^{-7}')
+    assert(latex(S(5.7)*10**(-7), decimal_separator='comma')==r'5{,}7 \cdot 10^{-7}')
+    assert(latex(S(5.7*10**(-7)), decimal_separator='comma')==r'5{,}7 \cdot 10^{-7}')
 
     x = symbols('x')
-    assert(latex(1.2*x+3.4, decimal_separator='comma') == r'1{,}2 x + 3{,}4')
-    assert(latex(FiniteSet(1, 2.3, 4.5), decimal_separator='period') == r'\left\{1, 2.3, 4.5\right\}')
+    assert(latex(1.2*x+3.4, decimal_separator='comma')==r'1{,}2 x + 3{,}4')
+    assert(latex(FiniteSet(1, 2.3, 4.5), decimal_separator='period')==r'\left\{1, 2.3, 4.5\right\}')
 
     # Error Handling tests
     raises(ValueError, lambda: latex([1,2.3,4.5], decimal_separator='non_existing_decimal_separator_in_list'))
@@ -2648,7 +2657,7 @@ def test_latex_decimal_separator():
 
 def test_Str():
     from sympy.core.symbol import Str
-    assert str(Str('x')) == r'x'
+    assert str(Str('x')) == 'x'
 
 def test_latex_escape():
     assert latex_escape(r"~^\&%$#_{}") == "".join([
@@ -2679,22 +2688,22 @@ def test_global_settings():
     import inspect
 
     # settings should be visible in the signature of `latex`
-    assert inspect.signature(latex).parameters['imaginary_unit'].default == r'i'
-    assert latex(I) == r'i'
+    assert inspect.signature(latex).parameters['imaginary_unit'].default == 'i'
+    assert latex(I) == 'i'
     try:
         # but changing the defaults...
         LatexPrinter.set_global_settings(imaginary_unit='j')
         # ... should change the signature
-        assert inspect.signature(latex).parameters['imaginary_unit'].default == r'j'
-        assert latex(I) == r'j'
+        assert inspect.signature(latex).parameters['imaginary_unit'].default == 'j'
+        assert latex(I) == 'j'
     finally:
         # there's no public API to undo this, but we need to make sure we do
         # so as not to impact other tests
         del LatexPrinter._global_settings['imaginary_unit']
 
     # check we really did undo it
-    assert inspect.signature(latex).parameters['imaginary_unit'].default == r'i'
-    assert latex(I) == r'i'
+    assert inspect.signature(latex).parameters['imaginary_unit'].default == 'i'
+    assert latex(I) == 'i'
 
 def test_pickleable():
     # this tests that the _PrintFunction instance is pickleable
diff --git a/sympy/solvers/tests/test_solveset.py b/sympy/solvers/tests/test_solveset.py
index 22c8c94b5f..c19fbdb5ed 100644
--- a/sympy/solvers/tests/test_solveset.py
+++ b/sympy/solvers/tests/test_solveset.py
@@ -2116,7 +2116,6 @@ def test_exponential_real():
     e7 = 4**(x + 1) + 4**(x + 2) + 4**(x - 1) - 3**(x + 2) - 3**(x + 3)
     e8 = -9*exp(-2*x + 5) + 4*exp(3*x + 1)
     e9 = 2**x + 4**x + 8**x - 84
-    e10 = 29*2**(x + 1)*615**(x) - 123*2726**(x)
 
     assert solveset(e1, x, S.Reals) == FiniteSet(
         -3*log(2)/(-2*log(3) + log(2)))
@@ -2129,7 +2128,6 @@ def test_exponential_real():
     assert solveset(e7, x, S.Reals) == FiniteSet(2)
     assert solveset(e8, x, S.Reals) == FiniteSet(-2*log(2)/5 + 2*log(3)/5 + Rational(4, 5))
     assert solveset(e9, x, S.Reals) == FiniteSet(2)
-    assert solveset(e10,x, S.Reals) == FiniteSet((-log(29) - log(2) + log(123))/(-log(2726) + log(2) + log(615)))
 
     assert solveset_real(-9*exp(-2*x + 5) + 2**(x + 1), x) == FiniteSet(
         -((-5 - 2*log(3) + log(2))/(log(2) + 2)))
@@ -2203,7 +2201,6 @@ def test_expo_conditionset():
 
 def test_exponential_symbols():
     x, y, z = symbols('x y z', positive=True)
-    xr, zr = symbols('xr, zr', real=True)
 
     assert solveset(z**x - y, x, S.Reals) == Intersection(
         S.Reals, FiniteSet(log(y)/log(z)))
@@ -2218,11 +2215,8 @@ def test_exponential_symbols():
     assert solveset(x**x, x, Interval.Lopen(0,oo)).dummy_eq(
         ConditionSet(w, Eq(w**w, 0), Interval.open(0, oo)))
     assert solveset(x**y - 1, y, S.Reals) == FiniteSet(0)
-    assert solveset(exp(x/y)*exp(-z/y) - 2, y, S.Reals) == \
-    Complement(ConditionSet(y, Eq(im(x)/y, 0) & Eq(im(z)/y, 0), \
-    Complement(Intersection(FiniteSet((x - z)/log(2)), S.Reals), FiniteSet(0))), FiniteSet(0))
-    assert solveset(exp(xr/y)*exp(-zr/y) - 2, y, S.Reals) == \
-        Complement(FiniteSet((xr - zr)/log(2)), FiniteSet(0))
+    assert solveset(exp(x/y)*exp(-z/y) - 2, y, S.Reals) == FiniteSet(
+        (x - z)/log(2)) - FiniteSet(0)
 
     assert solveset(a**x - b**x, x).dummy_eq(ConditionSet(
         w, Ne(a, 0) & Ne(b, 0), FiniteSet(0)))