Add _repr_latex_ methods for IPython prettyprint
[linpy.git] / pypol / polyhedra.py
index e745d7d..6b5f9ab 100644 (file)
@@ -182,14 +182,27 @@ class Polyhedron(Domain):
         else:
             strings = []
             for equality in self.equalities:
-                strings.append('0 == {}'.format(equality))
+                strings.append('Eq({}, 0)'.format(equality))
             for inequality in self.inequalities:
-                strings.append('0 <= {}'.format(inequality))
+                strings.append('Ge({}, 0)'.format(inequality))
             if len(strings) == 1:
                 return strings[0]
             else:
                 return 'And({})'.format(', '.join(strings))
 
+    def _repr_latex_(self):
+        if self.isempty():
+            return '$\\emptyset$'
+        elif self.isuniverse():
+            return '$\\Omega$'
+        else:
+            strings = []
+            for equality in self.equalities:
+                strings.append('{} = 0'.format(equality._repr_latex_().strip('$')))
+            for inequality in self.inequalities:
+                strings.append('{} \\ge 0'.format(inequality._repr_latex_().strip('$')))
+            return '${}$'.format(' \\wedge '.join(strings))
+
     @classmethod
     def fromsympy(cls, expr):
         domain = Domain.fromsympy(expr)