Skip to content

Commit

Permalink
ENH: allow kwargs in ampform.io.aslatex() (#413)
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer authored Apr 30, 2024
1 parent fcaf792 commit 49ea3cb
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/ampform/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


@singledispatch
def aslatex(obj) -> str:
def aslatex(obj, **kwargs) -> str:
"""Render objects as a LaTeX `str`.
The resulting `str` can for instance be given to `IPython.display.Math`.
Expand All @@ -34,26 +34,26 @@ def aslatex(obj) -> str:


@aslatex.register(complex)
def _(obj: complex) -> str:
def _(obj: complex, **kwargs) -> str:
real = __downcast(obj.real)
imag = __downcast(obj.imag)
plus = "+" if imag >= 0 else ""
return f"{real}{plus}{imag}i"


def __downcast(obj: float) -> float | int:
def __downcast(obj: float, **kwargs) -> float | int:
if obj.is_integer():
return int(obj)
return obj


@aslatex.register(sp.Basic)
def _(obj: sp.Basic) -> str:
def _(obj: sp.Basic, **kwargs) -> str:
return sp.latex(obj)


@aslatex.register(abc.Mapping)
def _(obj: Mapping) -> str:
def _(obj: Mapping, **kwargs) -> str:
if len(obj) == 0:
msg = "Need at least one dictionary item"
raise ValueError(msg)
Expand All @@ -65,7 +65,7 @@ def _(obj: Mapping) -> str:


@aslatex.register(abc.Iterable)
def _(obj: Iterable) -> str:
def _(obj: Iterable, **kwargs) -> str:
obj = list(obj)
if len(obj) == 0:
msg = "Need at least one item to render as LaTeX"
Expand Down

0 comments on commit 49ea3cb

Please sign in to comment.