chemistry_tools.formulae.latex
Attention
This module has the following additional requirements:
cawdrey>=0.5.0 mathematical>=0.5.1 pyparsing>=2.4.6 tabulate>=0.8.9
These can be installed as follows:
python -m pip install chemistry-tools[formulae]
Functions and constants for converting formulae to LaTeX.
Functions:
|
Returns the LaTeX subscript of the given value. |
|
Returns the LaTeX superscript of the given value. |
|
Convert a formula string to its LaTeX representation. |
-
string_to_latex
(formula, prefixes=None, infixes=None, suffixes=('(s)', '(l)', '(g)', '(aq)'))[source] Convert a formula string to its LaTeX representation.
Examples:
>>> string_to_latex('NH4+') 'NH_{4}^{+}' >>> string_to_latex('Fe(CN)6+2') 'Fe(CN)_{6}^{2+}' >>> string_to_latex('Fe(CN)6+2(aq)') 'Fe(CN)_{6}^{2+}(aq)' >>> string_to_latex('.NHO-(aq)') '^\bullet NHO^{-}(aq)' >>> string_to_latex('alpha-FeOOH(s)') '\alpha-FeOOH(s)'
- Parameters
formula (
str
) – Chemical formula, e.g.'H2O'
,'Fe+3'
,'Cl-'
.prefixes (
Optional
[Dict
[str
,str
]]) – Mapping of prefixes to their LaTeX equivalents. Default greek letters and.
.infixes (
Optional
[Dict
[str
,str
]]) – Mapping of infixes to their LaTeX equivalents. DefaultNone
.suffixes (
Sequence
[str
]) – Suffixes to keep. Default('(s)', '(l)', '(g)', '(aq)')
.
- Return type
- Returns
The LaTeX representation of the formula.