diff --git a/README.rst b/README.rst index e68c77e..8e5a5cf 100644 --- a/README.rst +++ b/README.rst @@ -87,7 +87,7 @@ and its molar mass. 'H218O' >>> print(Formula('H2(18O)').latex) - \mathrm{H}_{2}^{18}\mathrm{O} + \mathrm{H}_{2}{}^{18}\mathrm{O} >>> Formula('(235U)').mass 235.04392819 @@ -137,7 +137,7 @@ As ``Formula``, also ``StatefulSpecies`` have ``html`` and ``latex`` attributes. .. code-block:: pycon >>> print(stateful_species.latex) - \mathrm{Ne}^{+} \; 1s^{2}2s^{2}2p^{5}; \; {}^{2}P_{1/2} + \mathrm{Ne}^{+} \; 1s^{2}2s^{2}2p^{5} \; {}^{2}\mathrm{P}_{1/2} >>> StatefulSpecies('(52Cr)(1H) 1sigma2.2sigma1.1delta2.1pi2; 6SIGMA+; v=0; J=2').html '52Cr1H 1σ2.2σ1.1δ2.1π2 6Σ+ v=0 J=2' diff --git a/doc/introduction.rst b/doc/introduction.rst index 0295ac9..a1e7a01 100644 --- a/doc/introduction.rst +++ b/doc/introduction.rst @@ -73,7 +73,7 @@ and its molar mass. 'H218O' >>> print(Formula('H2(18O)').latex) - \mathrm{H}_{2}^{18}\mathrm{O} + \mathrm{H}_{2}{}^{18}\mathrm{O} >>> Formula('(235U)').mass 235.04392819 @@ -123,7 +123,7 @@ As ``Formula``, also ``StatefulSpecies`` have ``html`` and ``latex`` attributes. .. code-block:: pycon >>> print(stateful_species.latex) - \mathrm{Ne}^{+} \; 1s^{2}2s^{2}2p^{5}; \; {}^{2}P_{1/2} + \mathrm{Ne}^{+} \; 1s^{2}2s^{2}2p^{5} \; {}^{2}\mathrm{P}_{1/2} >>> StatefulSpecies('(52Cr)(1H) 1sigma2.2sigma1.1delta2.1pi2; 6SIGMA+; v=0; J=2').html '52Cr1H 1σ2.2σ1.1δ2.1π2 6Σ+ v=0 J=2' diff --git a/setup.py b/setup.py index b65a056..a57da49 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setup( name="pyvalem", - version="2.5.4", + version="2.5.5", description="A package for managing simple chemical species and states", long_description=long_description, long_description_content_type="text/x-rst", diff --git a/src/pyvalem/formula.py b/src/pyvalem/formula.py index 5a6a3b1..3bf892d 100644 --- a/src/pyvalem/formula.py +++ b/src/pyvalem/formula.py @@ -376,7 +376,7 @@ def _parse_formula(self, formula): # number so symbol is the ParseResults ['z', 'Sy']: mass_number, atom_symbol = (int(atom_symbol[0]), atom_symbol[1]) symbol_html = "%d%s" % (mass_number, atom_symbol) - symbol_latex = r"^{{{0:d}}}\mathrm{{{1:s}}}".format( + symbol_latex = r"{{}}^{{{0:d}}}\mathrm{{{1:s}}}".format( mass_number, atom_symbol ) atom_symbol = "%d%s" % (mass_number, atom_symbol) diff --git a/src/pyvalem/stateful_species.py b/src/pyvalem/stateful_species.py index 43fa39b..f3e1a41 100644 --- a/src/pyvalem/stateful_species.py +++ b/src/pyvalem/stateful_species.py @@ -3,7 +3,7 @@ molecule), optionally with with one or more State objects associated with it. The Formula of the StatefulSpecies is separated from its States by whitespace; -States are separated from each other by semicolons (;). +States are separated from each other by semicolons (;) or whitespace. """ from pyvalem.states.atomic_configuration import AtomicConfiguration from pyvalem.states.diatomic_molecular_configuration import ( @@ -147,5 +147,5 @@ def latex(self): if not self.states: return self.formula.latex return r"{} \; {}".format( - self.formula.latex, r"; \; ".join(s.latex for s in self.states) + self.formula.latex, r" \; ".join(s.latex for s in self.states) ) diff --git a/src/pyvalem/states/atomic_term_symbol.py b/src/pyvalem/states/atomic_term_symbol.py index 272d260..e6f6e34 100644 --- a/src/pyvalem/states/atomic_term_symbol.py +++ b/src/pyvalem/states/atomic_term_symbol.py @@ -87,7 +87,7 @@ def html(self): @property def latex(self): - latex_chunks = ["{{}}^{{{}}}{}".format(self.Smult, self.Lletter)] + latex_chunks = ["{{}}^{{{}}}\mathrm{{{}}}".format(self.Smult, self.Lletter)] if self.parity: latex_chunks.append("^o") if self.J is not None: diff --git a/tests/good_formulas.py b/tests/good_formulas.py index 946f3b3..760ea18 100644 --- a/tests/good_formulas.py +++ b/tests/good_formulas.py @@ -18,7 +18,7 @@ "slug": "79Br", "rmm": 78.918337601, "natoms": 1, - "latex": r"^{79}\mathrm{Br}", + "latex": r"{}^{79}\mathrm{Br}", }, "(2H)+": { "stoichiometric_formula": "(2H)+", diff --git a/tests/test_atomic_term_symbols.py b/tests/test_atomic_term_symbols.py index 9089f40..fdacf36 100644 --- a/tests/test_atomic_term_symbols.py +++ b/tests/test_atomic_term_symbols.py @@ -19,21 +19,21 @@ def test_atomic_term_symbol(self): a0 = AtomicTermSymbol("1S_0") self.assertEqual(a0.html, "1S0") - self.assertEqual(a0.latex, "{}^{1}S_{0}") + self.assertEqual(a0.latex, r"{}^{1}\mathrm{S}_{0}") self.assertEqual(a0.S, 0) self.assertEqual(a0.L, 0) self.assertEqual(a0.J, 0) a1 = AtomicTermSymbol("4D") self.assertEqual(a1.html, "4D") - self.assertEqual(a1.latex, "{}^{4}D") + self.assertEqual(a1.latex, r"{}^{4}\mathrm{D}") self.assertEqual(a1.S, 1.5) self.assertEqual(a1.L, 2) self.assertIsNone(a1.J) a2 = AtomicTermSymbol("2Po_1/2") self.assertEqual(a2.html, "2Po1/2") - self.assertEqual(a2.latex, "{}^{2}P^o_{1/2}") + self.assertEqual(a2.latex, r"{}^{2}\mathrm{P}^o_{1/2}") self.assertEqual(a2.parity, "o") self.assertEqual(a2.L, 1) diff --git a/tests/test_formula.py b/tests/test_formula.py index 2db2902..06bd67a 100644 --- a/tests/test_formula.py +++ b/tests/test_formula.py @@ -45,7 +45,7 @@ def test_html_latex_and_slug(self): "(1H)(14N)(16O)3(18O)", "14N1H16O2" "18O16O", - r"^{14}\mathrm{N}^{1}\mathrm{H}^{16}\mathrm{O}_{2}^{18}\mathrm{O}^{16}" + r"{}^{14}\mathrm{N}{}^{1}\mathrm{H}{}^{16}\mathrm{O}_{2}{}^{18}\mathrm{O}{}^{16}" r"\mathrm{O}", "14N-1H-16O2-18O-16O", ), diff --git a/tests/test_reaction.py b/tests/test_reaction.py index c1c2dbc..77f050c 100644 --- a/tests/test_reaction.py +++ b/tests/test_reaction.py @@ -75,7 +75,7 @@ def test_reaction_parsing(self): self.assertEqual( r2.latex, r"\mathrm{C}\mathrm{O} \; v=1 + " - r"\mathrm{O}_{2} \; J=2; \; " + r"\mathrm{O}_{2} \; J=2 \; " r"X{}^{3}\Sigma^-_{g} \rightarrow " r"\mathrm{C}\mathrm{O}_{2} + \mathrm{O}", )