| 453 | return term, needs_parens |
| 454 | |
| 455 | def _repr_latex_(self): |
| 456 | # get the scaled argument string to the basis functions |
| 457 | off, scale = self.mapparms() |
| 458 | term, needs_parens = self._format_term(self._repr_latex_scalar, |
| 459 | off, scale) |
| 460 | |
| 461 | mute = r"\color{{LightGray}}{{{}}}".format |
| 462 | |
| 463 | parts = [] |
| 464 | for i, c in enumerate(self.coef): |
| 465 | # prevent duplication of + and - signs |
| 466 | if i == 0: |
| 467 | coef_str = f"{self._repr_latex_scalar(c)}" |
| 468 | elif not isinstance(c, numbers.Real): |
| 469 | coef_str = f" + ({self._repr_latex_scalar(c)})" |
| 470 | elif c >= 0: |
| 471 | coef_str = f" + {self._repr_latex_scalar(c, parens=True)}" |
| 472 | else: |
| 473 | coef_str = f" - {self._repr_latex_scalar(-c, parens=True)}" |
| 474 | |
| 475 | # produce the string for the term |
| 476 | term_str = self._repr_latex_term(i, term, needs_parens) |
| 477 | if term_str == '1': |
| 478 | part = coef_str |
| 479 | else: |
| 480 | part = rf"{coef_str}\,{term_str}" |
| 481 | |
| 482 | if c == 0: |
| 483 | part = mute(part) |
| 484 | |
| 485 | parts.append(part) |
| 486 | |
| 487 | if parts: |
| 488 | body = ''.join(parts) |
| 489 | else: |
| 490 | # in case somehow there are no coefficients at all |
| 491 | body = '0' |
| 492 | |
| 493 | return rf"${self.symbol} \mapsto {body}$" |
| 494 | |
| 495 | # Pickle and copy |
| 496 | |