FxEditor
User guideQuickstartExamplesAPIDesignFxTeX
OverviewAPIExamplesRight-click menuSupported commandsAccessibilityFxTeX Packages
Using packagesmhchemFxTeX Server
OverviewAPIAccess and keysSelf-hostingSpeedPlugins
OverviewLicensing
How licensing worksmhchem
mhchem writes chemistry the way chemists write it: \ce{H2SO4} rather than
\mathrm{H_2SO_4}. Inside \ce, numbers after an element are subscripts,
charges go up, and -> is a reaction arrow; \pu does the same for
physical units. The editor below has the chemistry panels — mhchem's and chemfig's —
with the maths a chemist needs around them. Click any example on this page to open it there.
Adding mhchem to your page
In fxTeX Pro, name mhchem when you render the page:
fxTeXPro.ready.then(() => {
fxTeXPro.unlock('fx_pk_your-key-here');
fxTeXPro.autoRender({ packages: ['mhchem'] });
});
In the equation editor, name it to EqEditor.init() and add its
panels to the toolbar. This is the editor above, with chemfig as well:
<script src="https://fxeditor.codecogs.com/fxeditor.api.min.js"></script>
<div id="toolbar"></div>
<div id="mathview"></div>
<div id="latex"></div>
<script>
const ready = EqEditor.init({
licence: 'fx_pk_your-key-here',
packages: ['mhchem', 'chemfig']
});
const toolbar = EqEditor.Toolbar.link('toolbar', [
['mhchem', 'mhchem_arrows', 'chemfig', 'chemfig_ext', 'arrows'],
['operators_core', 'subsupset', 'brackets', 'greeklower', 'greekupper', 'symbols', 'spaces']
]);
ready.then(() => {
const latex = EqEditor.LaTeXView.link('latex');
const mathview = EqEditor.MathView.link('mathview').addLaTeXView(latex);
toolbar.addLaTeXView(latex).addMathView(mathview);
mathview.setLatex('\\ce{2H2 + O2 -> 2H2O}');
});
</script>
The mhchem panel has charges, isotopes, oxidation states, precipitates, gases
and bonds; mhchem_arrows has the reaction arrows, with room for conditions above
and below. Both write inside \ce{}, and add it only when the caret is not in one
already. See Using packages for more on both steps.
Formulae and charges
Write a formula as it reads. A number after an element or a bracket is a subscript; a charge
at the end goes up, with or without a ^.
\ce{H2O}The 2 is a subscript.
\ce{Sb2O3}Element symbols are upright, not italic.
\ce{H+}A charge at the end is a superscript.
\ce{CrO4^2-}Subscript and charge together, stacked.
\ce{[AgCl2]-}Complexes in square brackets.
\ce{[Cu(NH3)4]^2+}Groups nest.
\ce{Y^99+}Multi-digit charges need only the ^.
Stoichiometric numbers
A number in front of a formula is its coefficient, and stays full size. Fractions and decimals work too.
\ce{2H2O}No space needed after the number.
\ce{0.5H2O}A decimal coefficient.
\ce{1/2H2O}A fraction, set small.
Isotopes and nuclides
Mass and atomic numbers go before the symbol, as a superscript and a subscript, and line up on the left.
\ce{^{227}_{90}Th+}Mass number above, atomic number below.
\ce{^{0}_{-1}n^{-}}Prescripts and a charge on the same symbol.
Oxidation states and radicals
Roman numerals in a superscript are oxidation states; a dot in one is a radical.
\ce{Fe^{II}}An oxidation state.
\ce{Fe^{II}Fe^{III}2O4}Mixed oxidation states in one formula.
\ce{OCO^{.-}}A radical anion.
States of matter
A state in brackets after a formula is set as a subscript-sized label.
\ce{H2O(l)}Liquid.
\ce{NaCl(s)}Solid.
\ce{CO2(g)}Gas.
\ce{NaOH(aq,$\infty$)}Maths inside the state, between $ signs.
Reaction arrows
Arrows are written with -, <, > and
=, with a space on each side, and stretch to fit anything written over them.
\ce{A -> B}Reaction.
\ce{A <- B}Reverse reaction.
\ce{A <-> B}Resonance.
\ce{A <--> B}Forward and back, two arrows.
\ce{A <=> B}Equilibrium.
\ce{A <=>> B}Equilibrium lying to the right.
\ce{A <<=> B}Equilibrium lying to the left.
\ce{N2 + 3H2 <=> 2NH3}A whole equation: + with spaces round it is a plus sign.
Conditions on arrows
Text in square brackets after an arrow goes above it, and a second pair below. It is read as
chemistry; put text in braces, and maths between $ signs.
\ce{A ->[H2O] B}A reagent above the arrow.
\ce{A ->[{text above}][{text below}] B}Text above and below.
\ce{A ->[$x$][$x_i$] B}Maths above and below.
\ce{Hg^2+ ->[I-] HgI2 ->[I-] [Hg^{II}I4]^2-}A sequence of reactions.
Precipitates and gases
A v on its own is a precipitate, an arrow down; a ^ on its own is a
gas given off, an arrow up.
\ce{SO4^2- + Ba^2+ -> BaSO4 v}Barium sulfate precipitates.
\ce{x Na(NH4)HPO4 ->[\Delta] (NaPO3)_x + x NH3 ^ + x H2O}Ammonia given off, and a variable coefficient.
Bonds
Between two atoms, -, = and # are single, double and
triple bonds. \bond{} draws these and the rest by name. For structures in two
dimensions, use chemfig.
\ce{A-B=C#D}Single, double and triple.
\ce{CH3-CH=CH2}Propene.
\ce{A\bond{~}B\bond{~-}C}Delocalised bonds.
\ce{A\bond{...}B\bond{....}C}Dotted bonds.
\ce{A\bond{->}B\bond{<-}C}Dative bonds.
Addition compounds
A full stop or an asterisk between two formulae is a centred dot.
\ce{CuSO4.5H2O}A hydrate.
\ce{KCr(SO4)2*12H2O}The asterisk works the same way.
Chemistry and maths together
\ce can go anywhere in an equation, and maths can go inside \ce
between $ signs.
K_a = \frac{[\ce{H3O+}][\ce{A-}]}{[\ce{HA}]}An equilibrium constant: \ce inside a fraction.
\ce{2H2 + O2 -> 2H2O} \quad \Delta H = \pu{-572 kJ}A reaction and its enthalpy.
\ce{CH4 + 2 $\left( \ce{O2 + 79/21 N2} \right)$}Maths inside \ce, and \ce inside that.
Physical units
\pu sets a number and its units: upright units, a thin space between them, and
exponents written plainly. A space, or *, between units is a multiplication;
/ is a fraction and // a slash.
\pu{123 kJ}A number and its unit.
\pu{123 mm2}A number after a unit is its power.
\pu{123 kJ mol-1}Negative powers.
\pu{123 kJ/mol}As a fraction.
\pu{123 kJ//mol}With a slash.
\pu{1.2e3 kJ}Scientific notation.
\pu{25 °C}Degrees.
R = \pu{8.314 J K-1 mol-1}Inside an equation.
The mhchem manual
This page covers what most chemistry needs. mhchem itself is by Martin Hensel; its manual covers every part of the syntax:
mhchem manual (PDF) — the LaTeX package's documentation, on CTAN.
mhchem on CTAN — the package, its licence and versions.
More
chemfig — structural formulae and reaction schemes.
Using packages — turning packages on, and their panels.
Supported commands — every chemistry command fxTeX reads.
CodeCogs®