Skip to content
AsciiC6hem

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
H
He
He
Uue
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
H 2
O_3
O 3
H_2O
H 2 O

For multi-character subscripts, use braces:

Source Rendered
H_{2a}
H {2a}

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

Source Rendered
H2
H 2
H2O
H 2 O
CH4
C H 4
NH3
N H 3

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+
Ca 2 +
Cl^-
Cl -
SO_4^2-
S O 4 2 -

Oxidation states are Roman numerals wrapped in parens:

Source Rendered
Fe^(II)
Fe II
Fe^(III)
Fe III
Mn^(VII)
Mn VII

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
C 14
^131I
I 131
^238U
U 238

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.

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
2 H 2 O
3H_2
3 H 2

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