# Revision history [back]

Hello, Sage community. I was able to adapt @Juanjo's answer, but then I did some incantation (which I don't completely understand) that generalized his method. The only problem is that I had to modify the code in the file sage.misc.latex.latex. Here I describe what I did.

First of all, I made a copy of the file I just mentioned, and added a small modification of part of your code. Here is the patch:

@@ -36,6 +36,7 @@
from sage.misc.sage_ostools import have_program
from sage.misc.temporary_file import tmp_dir

@@ -36,6 +36,7 @@
from sage.misc.sage_ostools import have_program
from sage.misc.temporary_file import tmp_dir

+from sage.all import RR, CC
EMBEDDED_MODE = False

@@ -921,6 +922,10 @@
sage: latex((x,2), combine_all=True)
x 2
"""
+        if x in RR:
+            return LatexExpr(r'\num{' + str(x) + '}')
+        elif x in CC:
+            return LatexExpr(r'\num{' + str(x.real_part()) + '+' + str(x.imag_part()) + 'i}')
if has_latex_attr(x):
return LatexExpr(x._latex_())
try:


I saved this as LaTeX.py., then I made an import:

from LaTeX import latex


And here is the part I don't understand:

sage.misc.latex.latex = latex


This last line makes my new latex() function work on matrices, tuples, list, etc. automatically. (Why?)