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