Skip to content

Commit

Permalink
Trac #31153: Fix latex of elements of multivariate polynomial quotien…
Browse files Browse the repository at this point in the history
…t ring

Following an initial report by Ask Sage user "Road" at

- [https://ask.sagemath.org/question/54375 Ask Sage question 54375]

Define a polynomial ring and its generators:
{{{
sage: R = PolynomialRing(QQ, 'a, b, c')
sage: a, b, c = R.gens()
}}}
The generators display well:
{{{
sage: latex(a)  # good
a
}}}
Now define a quotient of that ring modulo an ideal:
{{{
sage: I = R.ideal(a**2 + a + 1)
sage: S = R.quotient(I, names=R.variable_names()).fraction_field()
sage: a, b, c = S.gens()
}}}
The generators display poorly:
{{{
sage: latex(a)  # should be same as above
\text{\texttt{a}}
}}}

Adding a `_latex_` method in `sage/rings/quotient_ring_element.py`
addresses the issue.

This is done in this ticket.

URL: https://trac.sagemath.org/31153
Reported by: slelievre
Ticket author(s): Frédéric Chapoton
Reviewer(s): Samuel Lelièvre
  • Loading branch information
Release Manager committed Jun 12, 2022
2 parents b36c11c + 56ee208 commit 28f70e0
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/sage/rings/quotient_ring_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,31 @@ def _repr_(self):
with localvars(R, P.variable_names(), normalize=False):
return str(self.__rep)

def _latex_(self):
"""
Return the LaTeX representation as a string.
EXAMPLES::
sage: R = PolynomialRing(QQ, 'a, b, c')
sage: a = R.gen(0)
sage: I = R.ideal(a**2 + a + 1)
sage: S = R.quotient(I, names=R.variable_names())
sage: a = S.gen(0)
sage: latex(a)
a
"""
from sage.structure.parent_gens import localvars
P = self.parent()
R = P.cover_ring()
# see _repr_ above for the idea
try:
P.variable_names()
except ValueError:
return self.__rep._latex_()
with localvars(R, P.variable_names(), normalize=False):
return self.__rep._latex_()

def __pari__(self):
"""
The Pari representation of this quotient element.
Expand Down

0 comments on commit 28f70e0

Please sign in to comment.