MathML
Presentation MathML via Nokogiri. The headline semantic fix:
prefix isotopes bind to the atom (^14C → <msup><mi>C</mi> <mn>14</mn></msup>), not to a phantom empty element.
MathML
Presentation MathML via Nokogiri. The headline semantic fix:
prefix isotopes bind to the atom (^14C → <msup><mi>C</mi> <mn>14</mn></msup>), not to a phantom empty element.
Text
Canonical AsciiChem text. Round-trip conformance:
parse(s).to_text == s. The Text formatter is the
canonicaliser.
HTML
Inline HTML with <sub> and <sup> tags. Suitable for
pages that don’t want to load MathJax.
LaTeX
Wrapped in mhchem’s \ce{...}. Requires
\usepackage[version=4]{mhchem} in the preamble.
SVG (linear)
Text rendered inside an SVG <text> element. Self-contained
vector output without external dependencies.
StructuralSvg
2D structural diagrams via elkrb graph layout. For molecules with bonds, produces skeletal formulae. For crystals, projects fractional coordinates to 2D with unit cell outline (v0.16+).
CML
Chemical Markup Language via the chemicalml gem. Native wire for all constructs (v0.9-v0.11); aci: extension namespace as backwards-compat fallback.
formula = AsciiChem.parse("H_2O")
formula.to_mathml # MathML XML stringformula.to_text # "H_2O"formula.to_html # '<span class="asciichem">H<sub>2</sub>O</span>'formula.to_latex # "\\ce{H2O}"formula.to_svg # SVG XML stringformula.to_structural_svg # structural SVG (diagrams)formula.to_cml # CML XML stringasciichem convert -i "H_2O" -t mathml # defaultasciichem convert -i "H_2O" -t htmlasciichem convert -i "H_2O" -t latexasciichem convert -i "H_2O" -t cml