Chemistry notation using mhchem: Difference between revisions

From MoodleDocs
No edit summary
No edit summary
Line 13: Line 13:
3
3
\ce{Sb2O3}
\ce{Sb2O3}
H
H
+
+
\ce{H+}
\ce{H+}
CrO
CrO
2–
2–
4
4
\ce{CrO4^2-}
\ce{CrO4^2-}
AgCl
AgCl
2
2
\ce{AgCl2-}
\ce{AgCl2-}
[AgCl
[AgCl
2
2
Line 29: Line 33:
\ce{[AgCl2]-}
\ce{[AgCl2]-}
Y
Y
99+
99+
\ce{Y^{99}+}
\ce{Y^{99}+}
Y
Y
99+
99+
\ce{Y^{99+}}
\ce{Y^{99+}}
H
H
2(aq)
2(aq)
\ce{H2_{(aq)}}
\ce{H2_{(aq)}}
NO
NO
3
3
\ce{NO3-}
\ce{NO3-}
(NH
(NH
4
4
Line 48: Line 57:
S
S
\ce{(NH4)2S}
\ce{(NH4)2S}
Amounts
Amounts
Place amounts directly in front of a formula. A small space will be inserted automatically.
Place amounts directly in front of a formula. A small space will be inserted automatically.
2H
2H
2
2
O
O
\ce{2H2O}
\ce{2H2O}
1
1
2
2
Line 60: Line 73:
O
O
\ce{1/2H2O}
\ce{1/2H2O}
Isotopes
Isotopes
227
227
90
90
Line 66: Line 81:
+
+
\ce{^{227}_{90}Th+}
\ce{^{227}_{90}Th+}
6
6
Fonts
Fonts
A few words about fonts. LaTeX distinguishes between text fonts and math fonts. In general,
 
the math fonts have much more glyphs: alphas, nabla operators and all that kind of suff. Ideally,
A few words about fonts. LaTeX distinguishes between text fonts and math fonts. In general, the math fonts have much more glyphs: alphas, nabla operators and all that kind of suff. Ideally, the math font looks very similar to the text font and that is why many LaTeX users do not know about the two kinds of fonts. However, the distinction is important for the use of mhchem.
the math font looks very similar to the text font and that is why many LaTeX users do not know
 
about the two kinds of fonts. However, the distinction is important for the use of
In the following examples, I will switch the text font to sans serif. This way, one can easily distinguish text font (sans serif) and math font (with serifs):textfont and math font. When setting a document in sans serif, one would, of course, use a matching math font. When you are in a math environment (e.g. opened and closed with a $), you could simply use \ce. Its content will be set in an upright font. (Remember: all variables—like V for volume—are set using an italic font, physical units and chemical elements are set using an upright font.)
mhchem
 
.
In the following examples, I will switch the text font to sans serif. This way, one can easily
distinguish text font (sans serif) and math font (with serifs):
textfont
and
math font
. When setting
a document in sans serif, one would, of course, use a matching math font.
When you are in a math environment (e.g. opened and closed with a $), you could simply use
\ce
. Its content will be set in an upright font. (Remember: all variables—like
V
for volume—are
set using an italic font, physical units and chemical elements are set using an upright font.)
V
V
H
H
Line 92: Line 95:
O
O
$V_{\ce{H2O}}$
$V_{\ce{H2O}}$
When used in text mode,
 
\ce
When used in text mode, \ce adapts to the current text font. You could simply write a formula in one of your section titles it would be set with the correct, no matter where is appears (sectiontitle, header, contents, references, ...).
adapts to the current text font. You could simply write a formula in
 
one of your section titles it would be set with the correct, no matter where is appears (section
title, header, contens, references, ...).
H
H
2
2
Line 104: Line 105:
O
O
\ce{H2O}, $\ce{H2O}$
\ce{H2O}, $\ce{H2O}$
Ce
Ce
IV
IV
\ce{Ce^{IV}}
\ce{Ce^{IV}}
There are some special cases. A negative charge in text mode is replaced with a dash (
 
--
There are some special cases. A negative charge in text mode is replaced with a dash (--), because a text minus sign often is too short. All ‘operators’, e.g. ‘+’ and reaction arrows, are always taken from the math font.
),
because a text minus sign often is too short. All ‘operators’, e.g. ‘+’ and reaction arrows, are
always taken from the math font.


Special Symbols
Special Symbols
Line 124: Line 123:
O
O
\ce{KCr(SO4)2
\ce{KCr(SO4)2
*
*
12H2O}
12H2O}
Line 135: Line 135:
O
O
\ce{KCr(SO4)2.12H2O}
\ce{KCr(SO4)2.12H2O}
[Cd{SC(NH
[Cd{SC(NH
2
2
Line 152: Line 153:
2
2
\cf{[Cd\{SC(NH2)2\}2].[Cr(SCN)4(NH3)2]2}
\cf{[Cd\{SC(NH2)2\}2].[Cr(SCN)4(NH3)2]2}
RNO
RNO
Line 161: Line 163:
2
2
$\ce{RNO2^{-.}}$, \ce{RNO2^{-.}}
$\ce{RNO2^{-.}}$, \ce{RNO2^{-.}}
version
 
2
μ
μ
-Cl
-Cl
\ce{$\mu\hyphen$Cl}
\ce{$\mu\hyphen$Cl}
version
 
3.05
Bonds
Bonds
Horizontal bonds can be set using the characters
Horizontal bonds can be set using the characters
-
-
,
,
=
=
and
and
#
#
inside a formula (single, double,
inside a formula (single, double,
version
 
triple bond) inside a formula (a - at the end of a formula yields a negative charge).
2
 
triple bond) inside a formula (a
C6H5−CHO
-
at the end of a formula yields a negative charge).
C
6
H
5
CHO
\ce{C6H5-CHO}
\ce{C6H5-CHO}
X
 
X−−Y−−−Z
Y
Z
\ce{X=Y#Z}
\ce{X=Y#Z}
A
 
A−B−−C−−−D
B
C
D
\ce{A\sbond B\dbond C\tbond D}
\ce{A\sbond B\dbond C\tbond D}
7
 
Different books visualise bonds in extremely different ways. I will implement the possiblity to
Different books visualise bonds in extremely different ways. I will implement the possiblity to adjust the appearance in the future. In the meanwhile, the minus sign from the math font is used
adjust the appearance in the future. In the meanwhile, the minus sign from the math font is used
to display the bonds (even in text mode). The bonds are vertically aligned on the math axis. For most math fonts, this is lower than half the height of a capital letter.
to display the bonds (even in text mode). The bonds are vertically aligned on the math axis. For
 
most math fonts, this is lower than half the height of a capital letter.
The \bond command allows you to typeset some types of special bonds.
The
 
\bond
A−B−−C−−−D
command allows you to typeset some types of special bonds.
version
3
A
B
C
D
\ce{A\bond{-}B\bond{=}C\bond{#}D}
\ce{A\bond{-}B\bond{=}C\bond{#}D}
A
 
A−−−B−−−−C
B
C
\ce{A\bond{~}B\bond{~-}C}
\ce{A\bond{~}B\bond{~-}C}
A
 
A−−−−−B−−−−−C−−−−−D
B
C
D
\ce{A\bond{~=}B\bond{~--}C\bond{-~-}D}
\ce{A\bond{~=}B\bond{~--}C\bond{-~-}D}
A
 
···
A···B····C
B
····
C
\ce{A\bond{...}B\bond{....}C}
\ce{A\bond{...}B\bond{....}C}
A
 
A→B←C
B
C
\ce{A\bond{->}B\bond{<-}C}
\ce{A\bond{->}B\bond{<-}C}
Please be aware, that the dashed bonds use the
 
\scalebox
Please be aware, that the dashed bonds use the \scalebox macro internally, which may not be visualised correctly by some DVI viewers. If you switch to another math font, the sidebearing of the minus sign may vary, which would cause the dashed bonds to align badly (in \bond{~=}, for instance). In that case, you may want to adjust the layout by using the command \mhchemoptions{minus-sidebearing-left=0.06em, minus-sidebearing-right=0.11em} with the appropriate values.
macro internally, which may
 
not be visualised correctly by some DVI viewers. If you switch to another math font, the
sidebearing of the minus sign may vary, which would cause the dashed bonds to align badly
(in
\bond{~=}
, for instance). In that case, you may want to adjust the layout by using the
command
\mhchemoptions{minus-sidebearing-left=0.06em,
minus-sidebearing-right=0.11em}
with the appropriate values.
Using Math
Using Math
To use math commands inside
 
\ce
To use math commands inside \ce, one can enclose that commands with $.
, one can enclose that commands with
 
$
Fe(CN)62
.
version
3.05
Fe(CN)
6
2
\ce{Fe(CN)_{$\frac{6}{2}$}}
\ce{Fe(CN)_{$\frac{6}{2}$}}
x
 
Na(NH
xNa(NH4)HPO4∆−→(NaPO3)x+xNH3↑+xH2O
4
)HPO
4
−→
(NaPO
3
)
x
+
x
NH
3
+
x
H
2
O
\ce{$x\,$ Na(NH4)HPO4 ->[\Delta]
\ce{$x\,$ Na(NH4)HPO4 ->[\Delta]
(NaPO3)_{$x$} +
(NaPO3)_{$x$} +
$x\,$ NH3 ^ + $x\,$ H2O}
$x\,$ NH3 ^ + $x\,$ H2O}


Some Comments
Some Comments
All features mentioned above are provided by the
All features mentioned above are provided by the \cf command. \ce calls \cf internally for all summary formulae and only sets the reaction arrows on its own. Most of the time, you do not have to worry about what command to use. Simply use \ce all the time. In some special cases, however, you may run into trouble. Recursion is one example (i.e. calling \ce from inside \ce). It may be helpful then, to use the \cf command for the inner formula.
\cf
 
command.
\ce
calls
\cf
internally for all summary formulae
and only sets the reaction arrows on its own. Most of the time, you do not have to worry about what command to use.
Simply use
\ce
all the time. In some special cases, however, you may run into trouble. Recursion is one example (i.e.
calling
\ce
from inside
\ce
). It may be helpful then, to use the
\cf
command for the inner formula.
Formulae
Formulae
Reaction Arrows
Reaction Arrows
CO
CO
2
2
Line 354: Line 242:
2CO
2CO
\ce{CO2 + C -> 2CO}
\ce{CO2 + C -> 2CO}
CO
CO
2
2
Line 361: Line 250:
2CO
2CO
\ce{CO2 + C <- 2CO}
\ce{CO2 + C <- 2CO}
CO
CO
2
2
Line 371: Line 261:
2CO
2CO
\ce{CO2 + C <=> 2CO}
\ce{CO2 + C <=> 2CO}
8
 
H
H
+
+
Line 385: Line 275:
O
O
\ce{H+ + OH- <=>> H2O}
\ce{H+ + OH- <=>> H2O}
A
A
←→
←→
Line 390: Line 281:
0
0
\ce{$A$ <-> $A’$}
\ce{$A$ <-> $A’$}
CO
CO
2
2
Line 398: Line 290:
2CO
2CO
\ce{CO2 + C ->[\alpha] 2CO}
\ce{CO2 + C ->[\alpha] 2CO}
CO
CO
2
2
Line 407: Line 300:
2CO
2CO
\ce{CO2 + C ->[\alpha][\beta] 2CO}
\ce{CO2 + C ->[\alpha][\beta] 2CO}
As with
 
^
As with ^ and _, the content above and below reaction arrows is set in math font. When you want to put descriptive text there, use the \text command. Or, as a shortcut, you could type a ‘T’ between reaction arrow and opening bracket.
and
 
_
, the content above and below reaction arrows is set in math font. When you want
to put descriptive text there, use the
\text
command. Or, as a shortcut, you could type a ‘T’
between reaction arrow and opening bracket.
CO
CO
2
2
Line 424: Line 311:
2CO
2CO
\ce{CO2 + C ->[\text{above}] 2CO}
\ce{CO2 + C ->[\text{above}] 2CO}
CO
CO
2
2
Line 434: Line 322:
\ce{CO2 + C
\ce{CO2 + C
->[\text{above}][\text{below}] 2CO}
->[\text{above}][\text{below}] 2CO}
CO
CO
2
2
Line 443: Line 332:
2CO
2CO
\ce{CO2 + C ->T[above][below] 2CO}
\ce{CO2 + C ->T[above][below] 2CO}
Similarly, there is a shortcut for using
 
\ce
Similarly, there is a shortcut for using \ce with reaction arrows:
with reaction arrows:
 
A
A
+
+
Line 454: Line 343:
B
B
\ce{$A$ ->[\ce{+H2O}] $B$}
\ce{$A$ ->[\ce{+H2O}] $B$}
A
A
+
+
Line 462: Line 352:
B
B
\ce{$A$ ->C[+H2O] $B$}
\ce{$A$ ->C[+H2O] $B$}
Precipitate and Gas
Precipitate and Gas
Use
 
v
Use v or (v) for precipitate (arrow down) and ^ or (^) for gas (arrow up), both separated by spaces.
or
 
(v)
for precipitate (arrow down) and
^
or
(^)
for gas (arrow up), both separated by
spaces.
SO
SO
2–
2–
Line 484: Line 368:
\ce{SO4^2- + Ba^2+ -> BaSO4 v}
\ce{SO4^2- + Ba^2+ -> BaSO4 v}
Watch Out!
Watch Out!
Please be aware that you sometimes have to enclose spaces in braces. In particular, you have to
Please be aware that you sometimes have to enclose spaces in braces. In particular, you have to do so, when they appear between brackets that belong to an reaction arrow.
do so, when they appear between brackets that belong to an reaction arrow.
 
A
A
enclose spaces!
enclose spaces!
Line 493: Line 378:
0
0
\ce{$A$ <->T[{enclose spaces!}] $A’$}
\ce{$A$ <->T[{enclose spaces!}] $A’$}
Further Examples
Further Examples
\ce{Zn^2+
\ce{Zn^2+
<=>[\ce{+ 2OH-}][\ce{+ 2H+}]
<=>[\ce{+ 2OH-}][\ce{+ 2H+}]
Line 532: Line 419:
2–
2–
Hydroxozikat
Hydroxozikat
version
 
 
3.05
$K = \frac{[\ce{Hg^2+}][\ce{Hg}]}{[\ce{Hg2^2+}]}$
$K = \frac{[\ce{Hg^2+}][\ce{Hg}]}{[\ce{Hg2^2+}]}$
K
K
Line 574: Line 460:
2–
2–
red
red
version
3.05

Revision as of 18:09, 28 August 2014

The mhchem pack­age pro­vides com­mands for type­set­ting chem­i­cal molec­u­lar for­mu­lae and equa­tions.

Basics

H 2 O \ce{H2O}

Sb 2 O 3 \ce{Sb2O3}

H + \ce{H+}

CrO 2– 4 \ce{CrO4^2-}

AgCl – 2 \ce{AgCl2-}

[AgCl 2 ] – \ce{[AgCl2]-}

Y 99+ \ce{Y^{99}+}

Y 99+ \ce{Y^{99+}}

H 2(aq) \ce{H2_{(aq)}}

NO – 3 \ce{NO3-}

(NH 4 ) 2 S \ce{(NH4)2S}

Amounts

Place amounts directly in front of a formula. A small space will be inserted automatically.

2H 2 O \ce{2H2O}

1 2 H 2 O \ce{1/2H2O}

Isotopes

227 90 Th + \ce{^{227}_{90}Th+}

6

Fonts

A few words about fonts. LaTeX distinguishes between text fonts and math fonts. In general, the math fonts have much more glyphs: alphas, nabla operators and all that kind of suff. Ideally, the math font looks very similar to the text font and that is why many LaTeX users do not know about the two kinds of fonts. However, the distinction is important for the use of mhchem.

In the following examples, I will switch the text font to sans serif. This way, one can easily distinguish text font (sans serif) and math font (with serifs):textfont and math font. When setting a document in sans serif, one would, of course, use a matching math font. When you are in a math environment (e.g. opened and closed with a $), you could simply use \ce. Its content will be set in an upright font. (Remember: all variables—like V for volume—are set using an italic font, physical units and chemical elements are set using an upright font.)

V H 2 O $V_{\ce{H2O}}$

When used in text mode, \ce adapts to the current text font. You could simply write a formula in one of your section titles it would be set with the correct, no matter where is appears (sectiontitle, header, contents, references, ...).

H 2 O, H 2 O \ce{H2O}, $\ce{H2O}$

Ce IV \ce{Ce^{IV}}

There are some special cases. A negative charge in text mode is replaced with a dash (--), because a text minus sign often is too short. All ‘operators’, e.g. ‘+’ and reaction arrows, are always taken from the math font.

Special Symbols

KCr(SO 4 ) 2 · 12H 2 O \ce{KCr(SO4)2

12H2O} KCr(SO 4 ) 2 · 12H 2 O \ce{KCr(SO4)2.12H2O}

[Cd{SC(NH 2 ) 2 } 2 ] · [Cr(SCN) 4 (NH 3 ) 2 ] 2 \cf{[Cd\{SC(NH2)2\}2].[Cr(SCN)4(NH3)2]2}

RNO − · 2 , RNO – · 2 $\ce{RNO2^{-.}}$, \ce{RNO2^{-.}}

μ -Cl \ce{$\mu\hyphen$Cl}

Bonds

Horizontal bonds can be set using the characters -

,

= and

inside a formula (single, double,

triple bond) inside a formula (a - at the end of a formula yields a negative charge).

C6H5−CHO \ce{C6H5-CHO}

X−−Y−−−Z \ce{X=Y#Z}

A−B−−C−−−D \ce{A\sbond B\dbond C\tbond D}

Different books visualise bonds in extremely different ways. I will implement the possiblity to adjust the appearance in the future. In the meanwhile, the minus sign from the math font is used to display the bonds (even in text mode). The bonds are vertically aligned on the math axis. For most math fonts, this is lower than half the height of a capital letter.

The \bond command allows you to typeset some types of special bonds.

A−B−−C−−−D \ce{A\bond{-}B\bond{=}C\bond{#}D}

A−−−B−−−−C \ce{A\bond{~}B\bond{~-}C}

A−−−−−B−−−−−C−−−−−D \ce{A\bond{~=}B\bond{~--}C\bond{-~-}D}

A···B····C \ce{A\bond{...}B\bond{....}C}

A→B←C \ce{A\bond{->}B\bond{<-}C}

Please be aware, that the dashed bonds use the \scalebox macro internally, which may not be visualised correctly by some DVI viewers. If you switch to another math font, the sidebearing of the minus sign may vary, which would cause the dashed bonds to align badly (in \bond{~=}, for instance). In that case, you may want to adjust the layout by using the command \mhchemoptions{minus-sidebearing-left=0.06em, minus-sidebearing-right=0.11em} with the appropriate values.

Using Math

To use math commands inside \ce, one can enclose that commands with $.

Fe(CN)62 \ce{Fe(CN)_{$\frac{6}{2}$}}

xNa(NH4)HPO4∆−→(NaPO3)x+xNH3↑+xH2O \ce{$x\,$ Na(NH4)HPO4 ->[\Delta]

(NaPO3)_{$x$} + $x\,$ NH3 ^ + $x\,$ H2O}

Some Comments All features mentioned above are provided by the \cf command. \ce calls \cf internally for all summary formulae and only sets the reaction arrows on its own. Most of the time, you do not have to worry about what command to use. Simply use \ce all the time. In some special cases, however, you may run into trouble. Recursion is one example (i.e. calling \ce from inside \ce). It may be helpful then, to use the \cf command for the inner formula.

Formulae

Reaction Arrows

CO 2 + C −−→ 2CO \ce{CO2 + C -> 2CO}

CO 2 + C ←−− 2CO \ce{CO2 + C <- 2CO}

CO 2 + C −−

) −− 2CO \ce{CO2 + C <=> 2CO}

H + + OH – ) − −−

H 2 O \ce{H+ + OH- <=>> H2O}

A ←→ A 0 \ce{$A$ <-> $A’$}

CO 2 + C α −→ 2CO \ce{CO2 + C ->[\alpha] 2CO}

CO 2 + C α −→ β 2CO \ce{CO2 + C ->[\alpha][\beta] 2CO}

As with ^ and _, the content above and below reaction arrows is set in math font. When you want to put descriptive text there, use the \text command. Or, as a shortcut, you could type a ‘T’ between reaction arrow and opening bracket.

CO 2 + C above −−−→ 2CO \ce{CO2 + C ->[\text{above}] 2CO}

CO 2 + C above −−−→ below 2CO \ce{CO2 + C ->[\text{above}][\text{below}] 2CO}

CO 2 + C above −−−→ below 2CO \ce{CO2 + C ->T[above][below] 2CO}

Similarly, there is a shortcut for using \ce with reaction arrows:

A + H 2 O −−−→ B \ce{$A$ ->[\ce{+H2O}] $B$}

A + H 2 O −−−→ B \ce{$A$ ->C[+H2O] $B$}

Precipitate and Gas

Use v or (v) for precipitate (arrow down) and ^ or (^) for gas (arrow up), both separated by spaces.

SO 2– 4 + Ba 2+ −−→ BaSO 4 ↓ \ce{SO4^2- + Ba^2+ -> BaSO4 v}

Watch Out! Please be aware that you sometimes have to enclose spaces in braces. In particular, you have to do so, when they appear between brackets that belong to an reaction arrow.

A enclose spaces! ←−−−−−−−→ A 0 \ce{$A$ <->T[{enclose spaces!}] $A’$}

Further Examples

\ce{Zn^2+ <=>[\ce{+ 2OH-}][\ce{+ 2H+}] $\underset{\text{amphoteres Hydroxid}}{\ce{Zn(OH)2 v}}$ <=>C[+2OH-][{+ 2H+}] $\underset{\text{Hydroxozikat}}{\cf{[Zn(OH)4]^2-}}$ } 9 Zn 2+ + 2OH – −−−−−

) −−−−− + 2H + Zn(OH) 2 ↓ amphoteres Hydroxid + 2OH – −−−−−

) −−−−− + 2H + [Zn(OH) 4 ] 2– Hydroxozikat


$K = \frac{[\ce{Hg^2+}][\ce{Hg}]}{[\ce{Hg2^2+}]}$ K = [ Hg 2 + ][ Hg ] [ Hg 2 + 2 ] \ce{Hg^2+ ->[\ce{I-}] $\underset{\mathrm{red}}{\ce{HgI2}}$ ->C[I-] $\underset{\mathrm{red}}{\ce{[Hg^{II}I4]^2-}}$ } Hg 2+ I – −→ HgI 2 red I – −→ [Hg II I 4 ] 2– red