Skip to content

Commit d1dfc46

Browse files
fchapotonmantepse
andauthored
Update src/sage/misc/latex.py
by using join at the end Co-authored-by: Martin Rubey <[email protected]>
1 parent 8f8792f commit d1dfc46

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/sage/misc/latex.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2165,7 +2165,35 @@ def repr_lincomb(symbols, coeffs):
21652165
\text{\texttt{x}} + 2\text{\texttt{y}}
21662166
"""
21672167
from sage.rings.cc import CC
2168+
terms = []
2169+
for c, sym in zip(coeffs, symbols):
2170+
if c == 0:
2171+
continue
2172+
if c == 1:
2173+
coeff = ""
2174+
elif c == -1:
2175+
coeff = "-"
2176+
else:
2177+
coeff = coeff_repr(c)
2178+
2179+
b = latex(sym)
2180+
# this is a hack: i want to say that if the symbol happens to
2181+
# be a number, then we should put a multiplication sign in
2182+
try:
2183+
if sym in CC and coeff not in ("", "-"):
2184+
term = f"{coeff}\\cdot {b}"
2185+
else:
2186+
term = f"{coeff}{b}"
2187+
except Exception:
2188+
term = f"{coeff}{b}"
2189+
2190+
terms.append(term)
2191+
2192+
if not terms:
2193+
return "0"
21682194

2195+
s = " + ".join(terms)
2196+
return s.replace("+ -", "- ")
21692197
s = ""
21702198
first = True
21712199

0 commit comments

Comments
 (0)