Skip to content

Commit

Permalink
Allow named units to have a LaTeX representation (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
rieder committed Sep 3, 2024
1 parent ecb3db9 commit a02468b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/amuse/units/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class unit(object):
Units can also be named, by creating a named unit.
"""

_latex_representation = None
__array_priority__ = 100

def __mul__(self, other):
Expand Down Expand Up @@ -142,6 +144,12 @@ def __ne__(self, other):
def __hash__(self):
return self._hash

def latex(self):
if self._latex_representation is not None:
return self._latex_representation
else:
return self.symbol

@late
def _hash(self):
return hash(id(self))
Expand Down Expand Up @@ -853,15 +861,16 @@ class named_unit(unit):
>>> (20.0 | (60.0 * si.s)).as_quantity_in(minute)
quantity<20.0 min>
"""
def __init__(self, name, symbol, unit):

def __init__(self, name, symbol, unit, latex=None):
self.name = name
self.symbol = symbol
self.local_unit = unit
self._latex_representation = latex

def __str__(self):
return self.symbol


def reference_string(self):
return self.to_simple_form().reference_string()

Expand Down

0 comments on commit a02468b

Please sign in to comment.