Skip to content

Atoms

The atom is the atomic unit of chemistry (and of AsciiChem). An atom captures:

FieldSource positionExample
elementelement symbolC, He, Fe
isotopeprefix^14C
subscriptsuffix (after _)H_2
chargesuffixCa^2+
oxidation_statesuffixFe^(III)
lone_pairsprefix (:)::O
radical_electronssuffix (.)N.
atom_paritysuffix (@R/@S)C@R
x2, y2suffix (@(x,y))C@(10,20)
x3, y3, z3suffix (@(x,y,z))C@(1,2,3)
spin_multiplicitysuffix (@m(N))C@m(2)
atom_titlesuffix (@t("..."))C@t("C1")
x_fract, y_fract, z_fractsuffix (@f(x,y,z))C@f(0.5,0.25,0.75)
ring_closuressuffix (digit)C1

Multiple annotations chain in a fixed order: C@(10,20)@R@m(2)@t("C1")@f(0.5,0.5,0.5).

See also: Coordinates, Ring closures, Stereochemistry, Annotations.

A capital letter optionally followed by a lowercase letter.

Source Rendered
H He Fe Au
Install the asciichem gem to see this rendered.

A subscript multiplicity follows _ directly. The subscript binds to the immediately preceding atom.

Source Rendered
H_2 O_3 H_2O
Install the asciichem gem to see this rendered.

For multi-character subscripts, use braces:

Source Rendered
H_{2a}
Install the asciichem gem to see this rendered.

Hydrogen accepts bare digits as an implicit subscript, so common formulae can be written without _:

Source Rendered
H2 H2O CH4 NH3
Install the asciichem gem to see this rendered.

Each canonicalises to the explicit form on round-trip (H_2, H_2O, CH_4, NH_3).

Charges are suffix superscripts in IUPAC number-then-sign form:

Source Rendered
Ca^2+ Cl^- SO_4^2-
Install the asciichem gem to see this rendered.

Oxidation states are Roman numerals wrapped in parens:

Source Rendered
Fe^(II) Fe^(III) Mn^(VII)
Install the asciichem gem to see this rendered.

The model captures these as Atom#oxidation_state (“II”, “III”, “VII”), distinct from a generic superscript.

The prefix isotope — the headline semantic fix

Section titled “The prefix isotope — the headline semantic fix”

The defining difference between AsciiChem and AsciiMath lives here.

Source Rendered
^14C ^131I ^238U
Install the asciichem gem to see this rendered.

In AsciiChem, the ^14 prefix binds to the following atom. The parse produces one Atom with isotope: "14". The MathML output is:

<msup><mi>C</mi><mn>14</mn></msup>

In AsciiMath, the same input would force a phantom carrier:

<msup><mi></mi><mn>14</mn></msup><mi>C</mi>

— an empty base followed by a sibling atom. The semantic binding (isotope 14 belongs to Carbon) is lost.

mhchem’s left-subscript isotope component — ^{227}_{90}Th — rides the combined form:

Source Rendered
^227_90Th
Install the asciichem gem to see this rendered.

The parse produces one Atom with isotope: "227" AND atomic_number: "90". The MathML output stacks them as the prescript pair — the atomic number under the mass number:

<mmultiscripts>
<mi>Th</mi><none/><none/><mprescripts/>
<mn>90</mn><mn>227</mn>
</mmultiscripts>

The atomic number only arrives attached to a ^-mass prefix — non-breaking by construction: the standalone _14C keeps its legacy isotope reading (the canonical text spells the caret form), and after the element the _digits suffix stays a subscript (^14C_6 is six carbons-14). The linter cross-checks the pair against the element’s real atomic number — ^14_7C is an error (“stated atomic number 7 does not match C’s atomic number 6”), while ^14_6C and plain ^14C stay silent. The wire carries atomicNumber (model v0.8.0) and CML the aci:atomicNumber attribute.

Leading digits on a molecule are the coefficient, distinct from the leading digit of a subscript. The grammar uses positive lookahead to disambiguate.

Source Rendered
2H_2O 3H_2
Install the asciichem gem to see this rendered.

The 2 in 2H_2O is the molecule’s coefficient; the 2 in H_2 is the atom’s subscript. Both are captured in the right place.

Play