Skip to content

Commit

Permalink
Tidy up some LaTeX output
Browse files Browse the repository at this point in the history
  • Loading branch information
xnx committed Mar 22, 2022
1 parent cb628dd commit 50a2c08
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ and its molar mass.
'H<sub>2</sub><sup>18</sup>O'
>>> print(Formula('H2(18O)').latex)
\mathrm{H}_{2}^{18}\mathrm{O}
\mathrm{H}_{2}{}^{18}\mathrm{O}
>>> Formula('(235U)').mass
235.04392819
Expand Down Expand Up @@ -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
'<sup>52</sup>Cr<sup>1</sup>H 1σ<sup>2</sup>.2σ<sup>1</sup>.1δ<sup>2</sup>.1π<sup>2</sup> <sup>6</sup>Σ<sup>+</sup> v=0 J=2'
Expand Down
4 changes: 2 additions & 2 deletions doc/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ and its molar mass.
'H<sub>2</sub><sup>18</sup>O'
>>> print(Formula('H2(18O)').latex)
\mathrm{H}_{2}^{18}\mathrm{O}
\mathrm{H}_{2}{}^{18}\mathrm{O}
>>> Formula('(235U)').mass
235.04392819
Expand Down Expand Up @@ -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
'<sup>52</sup>Cr<sup>1</sup>H 1σ<sup>2</sup>.2σ<sup>1</sup>.1δ<sup>2</sup>.1π<sup>2</sup> <sup>6</sup>Σ<sup>+</sup> v=0 J=2'
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/pyvalem/formula.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<sup>%d</sup>%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)
Expand Down
4 changes: 2 additions & 2 deletions src/pyvalem/stateful_species.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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)
)
2 changes: 1 addition & 1 deletion src/pyvalem/states/atomic_term_symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/good_formulas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)+",
Expand Down
6 changes: 3 additions & 3 deletions tests/test_atomic_term_symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ def test_atomic_term_symbol(self):

a0 = AtomicTermSymbol("1S_0")
self.assertEqual(a0.html, "<sup>1</sup>S<sub>0</sub>")
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, "<sup>4</sup>D")
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, "<sup>2</sup>P<sup>o</sup><sub>1/2</sub>")
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)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_formula.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_html_latex_and_slug(self):
"(1H)(14N)(16O)3(18O)",
"<sup>14</sup>N<sup>1</sup>H<sup>16</sup>O<sub>2</sub>"
"<sup>18</sup>O<sup>16</sup>O",
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",
),
Expand Down
2 changes: 1 addition & 1 deletion tests/test_reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
)
Expand Down

0 comments on commit 50a2c08

Please sign in to comment.