Skip to content

Commit

Permalink
Add latex representation of Units
Browse files Browse the repository at this point in the history
  • Loading branch information
xnx committed Jun 3, 2022
1 parent 63141fa commit 7944352
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
build/
dist/
pyqn.egg-info/
.venv
activate
15 changes: 15 additions & 0 deletions pyqn/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,21 @@ def html(self):
h.append(' ')
return ''.join(h)


@property
def latex(self):
e = []
n = len(self.atom_units)
for i, atom_unit in enumerate(self.atom_units):
# TODO use proper LaTeX for prefix.
e.extend([atom_unit.prefix or '', atom_unit.base_unit.latex])
if atom_unit.exponent != 1:
e.append('^{' + str(atom_unit.exponent) + '}')
if i < n-1:
e.append(r'\,')
return r'\mathrm{' + ''.join(e) + '}'


def conversion(self, other, force=None, strict=False):
"""
Return the factor required to convert this Units to
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages
setup(
name = 'pyqn',
version = '1.2',
version = '1.2.1',
packages = find_packages(),
author = 'Christian Hill',
url = 'https://github.com/xnx/pyqn',
Expand Down

0 comments on commit 7944352

Please sign in to comment.