Skip to content

Commit

Permalink
BREAK: move simplify_latex_rendering() to io module
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer committed Mar 17, 2024
1 parent 258b03a commit 01522fc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/ampform_dpd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
ThreeBodyDecayChain,
get_decay_product_ids,
)
from ampform_dpd.io import (
simplify_latex_rendering, # noqa: F401 # pyright:ignore[reportUnusedImport]
)
from ampform_dpd.spin import create_spin_range


Expand Down Expand Up @@ -386,17 +389,6 @@ def formulate_non_resonant(
return sp.Rational(1), {}


def simplify_latex_rendering() -> None:
"""Improve LaTeX rendering of an `~sympy.tensor.indexed.Indexed` object."""

def _print_Indexed_latex(self, printer, *args): # noqa: N802
base = printer._print(self.base)
indices = ", ".join(map(printer._print, self.indices))
return f"{base}_{{{indices}}}"

sp.Indexed._latex = _print_Indexed_latex


def create_mass_symbol_mapping(decay: ThreeBodyDecay) -> dict[sp.Symbol, float]:
return {
sp.Symbol(f"m{i}"): decay.states[i].mass
Expand Down
11 changes: 11 additions & 0 deletions src/ampform_dpd/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,3 +378,14 @@ def _warn_about_unsafe_hash():
"""
message = dedent(message).replace("\n", " ").strip()
_LOGGER.warning(message)


def simplify_latex_rendering() -> None:
"""Improve LaTeX rendering of an `~sympy.tensor.indexed.Indexed` object."""

def _print_Indexed_latex(self, printer, *args): # noqa: N802
base = printer._print(self.base)
indices = ", ".join(map(printer._print, self.indices))
return f"{base}_{{{indices}}}"

sp.Indexed._latex = _print_Indexed_latex

0 comments on commit 01522fc

Please sign in to comment.