Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Fix LaTeX display of continuous maps with SymPy expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
egourgoulhon committed Oct 27, 2017
1 parent 5e2da17 commit 92e508b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
2 changes: 0 additions & 2 deletions src/sage/manifolds/chart_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,6 @@ def display(self):
"""
from sage.tensor.modules.format_utilities import FormattedExpansion
from sage.misc.latex import latex
curr = self._calc_method._current
expr = self.expr(curr)
if (curr == 'SR' and
Expand Down Expand Up @@ -684,7 +683,6 @@ def __call__(self, *coords, **options):
xx = [x._sympy_() for x in self._chart._xx]
co = [calc._tranf['sympy'](c) for c in coords]
substitutions = dict(zip(xx, co))
# print("self._express: {}".format(self._express))
resu = self.expr(curr).subs(substitutions)
if 'simplify' in options:
if options['simplify']:
Expand Down
27 changes: 22 additions & 5 deletions src/sage/manifolds/continuous_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,22 @@ def display(self, chart1=None, chart2=None):
on U: (x, y) |--> (X, Y, Z) = (2*x/(x^2 + y^2 + 1), 2*y/(x^2 + y^2 + 1), (x^2 + y^2 - 1)/(x^2 + y^2 + 1))
on V: (u, v) |--> (X, Y, Z) = (2*u/(u^2 + v^2 + 1), 2*v/(u^2 + v^2 + 1), -(u^2 + v^2 - 1)/(u^2 + v^2 + 1))
Display when SymPy is the symbolic engine::
sage: M.set_calculus_method('sympy')
sage: N.set_calculus_method('sympy')
sage: Phi.display(c_xy, c_cart)
Phi: S^2 --> R^3
on U: (x, y) |--> (X, Y, Z) = (2*x/(x**2 + y**2 + 1),
2*y/(x**2 + y**2 + 1), (x**2 + y**2 - 1)/(x**2 + y**2 + 1))
sage: latex(Phi.display(c_xy, c_cart))
\begin{array}{llcl} \Phi:& S^2 & \longrightarrow & \RR^3
\\ \mbox{on}\ U : & \left(x, y\right) & \longmapsto
& \left(X, Y, Z\right) = \left(\frac{2 x}{x^{2} + y^{2} + 1},
\frac{2 y}{x^{2} + y^{2} + 1},
\frac{x^{2} + y^{2} - 1}{x^{2} + y^{2} + 1}\right)
\end{array}
"""
from sage.misc.latex import latex
from sage.tensor.modules.format_utilities import FormattedExpansion
Expand All @@ -986,7 +1002,8 @@ def _display_expression(self, chart1, chart2, result):
"""
from sage.misc.latex import latex
try:
expression = self.expr(chart1, chart2)
coord_func = self.coord_functions(chart1, chart2)
expression = coord_func.expr()
coords1 = chart1[:]
if len(coords1) == 1:
coords1 = coords1[0]
Expand All @@ -1005,21 +1022,21 @@ def _display_expression(self, chart1, chart2, result):
if chart2 == chart1:
if len(expression) == 1:
result._txt += repr(expression[0]) + "\n"
result._latex += latex(expression[0]) + r"\\"
result._latex += latex(coord_func[0]) + r"\\"
else:
result._txt += repr(expression) + "\n"
result._latex += latex(expression) + r"\\"
result._latex += latex(coord_func) + r"\\"
else:
if len(expression) == 1:
result._txt += repr(coords2[0]) + " = " + \
repr(expression[0]) + "\n"
result._latex += latex(coords2[0]) + " = " + \
latex(expression[0]) + r"\\"
latex(coord_func[0]) + r"\\"
else:
result._txt += repr(coords2) + " = " + \
repr(expression) + "\n"
result._latex += latex(coords2) + " = " + \
latex(expression) + r"\\"
latex(coord_func) + r"\\"
except (TypeError, ValueError):
pass

Expand Down

0 comments on commit 92e508b

Please sign in to comment.