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

Method _repr_latex_

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

Source from the content-addressed store, hash-verified

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

Callers 3

as_latexMethod · 0.80
test_latexMethod · 0.80
test_non_finiteMethod · 0.80

Calls 5

mapparmsMethod · 0.95
_format_termMethod · 0.95
_repr_latex_scalarMethod · 0.95
_repr_latex_termMethod · 0.95
joinMethod · 0.80

Tested by 3

as_latexMethod · 0.64
test_latexMethod · 0.64
test_non_finiteMethod · 0.64