MCPcopy Create free account
hub / github.com/numpy/numpy / _repr_latex_

Method _repr_latex_

numpy/polynomial/_polybase.py:440–491  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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

Callers 3

as_latexMethod · 0.80
test_latexMethod · 0.80
test_non_finiteMethod · 0.80

Calls 4

mapparmsMethod · 0.95
_repr_latex_scalarMethod · 0.95
_repr_latex_termMethod · 0.95
joinMethod · 0.45

Tested by 3

as_latexMethod · 0.64
test_latexMethod · 0.64
test_non_finiteMethod · 0.64