From 9d98a3c962f04b87440231cc52e511e4f10158b1 Mon Sep 17 00:00:00 2001 From: Remco de Boer Date: Fri, 7 May 2021 10:34:38 +0200 Subject: [PATCH] fix: rendering of Clebsch-Gordan coefficient The mini-fix for CG introduced by ComPWA/expertsystem#454 did not work well yet. This fix also removes the intermediate _ClebschGordanLatexFix class by replacing the CG._latex method --- src/ampform/helicity.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/ampform/helicity.py b/src/ampform/helicity.py index e51857610..5015abed7 100644 --- a/src/ampform/helicity.py +++ b/src/ampform/helicity.py @@ -3,7 +3,7 @@ import logging import operator from functools import reduce -from typing import Any, Dict, Iterable, List, Optional, Tuple, Union +from typing import Any, Dict, Iterable, List, Optional, Tuple, Type, Union import attr import sympy as sp @@ -703,7 +703,7 @@ def _generate_partial_decay( # pylint: disable=too-many-locals daughter_spins[0].projection - daughter_spins[1].projection ) - cg_ls = _ClebschGordanLatexFix( + cg_ls = CG( j1=sp.nsimplify(ang_mom.magnitude), m1=sp.nsimplify(ang_mom.projection), j2=sp.nsimplify(spin.magnitude), @@ -711,7 +711,7 @@ def _generate_partial_decay( # pylint: disable=too-many-locals j3=sp.nsimplify(parent_spin.magnitude), m3=sp.nsimplify(decay_particle_lambda), ) - cg_ss = _ClebschGordanLatexFix( + cg_ss = CG( j1=sp.nsimplify(daughter_spins[0].magnitude), m1=sp.nsimplify(daughter_spins[0].projection), j2=sp.nsimplify(daughter_spins[1].magnitude), @@ -723,10 +723,13 @@ def _generate_partial_decay( # pylint: disable=too-many-locals # https://github.com/sympy/sympy/issues/21001 -class _ClebschGordanLatexFix(CG): - def _latex(self, printer: LatexPrinter, *args: Any) -> str: - j3, m3, j1, m1, j2, m2 = map( # pylint: disable=invalid-name - printer._print, # pylint: disable=protected-access - (self.j3, self.m3, self.j1, self.m1, self.j2, self.m2), - ) - return f"{{C^{j3,m3}_{j1, m1, j2, m2}}}" +# pylint: disable=protected-access, unused-argument +def _latex_fix(self: Type[CG], printer: LatexPrinter, *args: Any) -> str: + j3, m3, j1, m1, j2, m2 = map( + printer._print, + (self.j3, self.m3, self.j1, self.m1, self.j2, self.m2), + ) + return f"{{C^{{{j3},{m3}}}_{{{j1},{m1},{j2},{m2}}}}}" + + +CG._latex = _latex_fix