Chemistry notation using mhchem: Difference between revisions

From MoodleDocs
(removing work in progress template, as the template was for developer docs)
 
(32 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Filters}}
{{Filters}}
{{Work in progress}}
The mhchem pack­age pro­vides com­mands for type­set­ting chem­i­cal molec­u­lar for­mu­lae and equa­tions.
The mhchem pack­age pro­vides com­mands for type­set­ting chem­i­cal molec­u­lar for­mu­lae and equa­tions.
==Why mhchem?==
==Why mhchem?==
Line 12: Line 11:


==Installation==
==Installation==
The mhchem package can be integrated with Moodle in one of two ways. In general, the first via MathJax is the simplest to set up and provides high quality rendering. However, MathJax rendering       depends on client-side JavaScript processing by the browser and in some circumstances, e.g. on some platforms (mobile) or for particularly complex maths/science expressions, this may result in an unacceptable delay in display. Also, there may be conflicts between MathJax and other JavaScript libraries (e.g. in some third-party Moodle plugins). In these cases, it may be advantageous to shift the workload to the server-side TeX filter. After initial loading the TeX filter-generated images are cached, and so quick to display. In general, the TeX filter generates lower quality rendering, though the new SVG output option in Moodle 2.8 approaches the quality of MathJax. In general the quality of display is:
The mhchem package can be integrated with Moodle in one of two ways. The first, via MathJax is the simplest to set up and provides high quality rendering. However, MathJax rendering depends on client-side JavaScript processing by the browser and may be subject to significant delay, e.g. on some platforms (especially mobile) or for particularly complex maths/science expressions. Also, there may be conflicts between MathJax and other JavaScript libraries (e.g. in some third-party Moodle plugins). In these cases, it may be advantageous to use the server-side TeX filter. After initial loading the TeX filter-generated images are cached, and so quick to display. The TeX filter typically generates lower quality display (MathJax > SVG > PNG > GIF), though the new SVG output option in Moodle 2.8 approaches the quality of MathJax.
 
MathJax > SVG > PNG > GIF


In Moodle 2.8, it is possible to 'have the best of both worlds'  by enabling the TeX and MathJax filters in parallel such that the TeX filter (particularly with SVG rendering) provides a fallback for MathJax, and vice versa.
In Moodle 2.8, it is possible to 'have the best of both worlds'  by enabling the TeX and MathJax filters in parallel such that the TeX filter (particularly with SVG rendering) provides a fallback for MathJax, and vice versa.
Line 30: Line 27:


===via LaTeX===
===via LaTeX===
It is also possible to add [http://http://www.ctan.org/pkg/mhchem mhchem] alongside LaTex on the Moodle server, and then use the Moodle TeX filter. You will need to install and configure the following binaries on the Moodle server.
It is also possible to add [http://www.ctan.org/pkg/mhchem mhchem] alongside LaTex on the Moodle server, and then use the Moodle TeX filter. You will need to install and configure the following binaries on the Moodle server.


latex
latex
Line 46: Line 43:
mhchem
mhchem


Installation details will depend on the server operating system. Most Linux distributions can use their standard package manager to install the binaries and dependencies. e.g. For Fedora 20, mhchem can be installed with: <code>yum install texlive-mhchem</code>. Alternatively, you can use a [http://latex-project.org/ftp.html LaTeX] installation bundle, that includesmhchem, for Linux, Windows or Macintosh servers.
Installation details will depend on the server operating system. Most Linux distributions can use their standard package manager to install the binaries and dependencies. e.g. For Fedora 20, mhchem can be installed with: <code>yum install texlive-mhchem</code>. Alternatively, you can use an appropriate [http://latex-project.org/ftp.html LaTeX] installation bundle, including mhchem, for Linux, Windows or Macintosh servers.


Once installed, in your Moodle Administration > Site administration > Plugins > Filters > TeX notation > LaTeX renderer Settings, add the following to the existing LaTeX preamble:
Once installed, in your Moodle Administration > Site administration > Plugins > Filters > TeX notation > LaTeX renderer Settings, add the following to the existing LaTeX preamble:
Line 69: Line 66:
However, the [https://moodle.org/plugins/view.php?plugin=atto_chemistry Atto Chemistry editor plugin] may also be convenient for users. This automatically wraps expressions within the required delimiters (e.g. \(\ce{...}\) and provides a set of tabbed toolbars and buttons for commonly used symbols, isotope format, reaction and equilibrium arrows etc. Element symbol buttons are arranged in a periodic table layout. It also incorporates some 'standard' TeX symbols (e.g greek and italic characters) that may be useful in a chemistry context.  
However, the [https://moodle.org/plugins/view.php?plugin=atto_chemistry Atto Chemistry editor plugin] may also be convenient for users. This automatically wraps expressions within the required delimiters (e.g. \(\ce{...}\) and provides a set of tabbed toolbars and buttons for commonly used symbols, isotope format, reaction and equilibrium arrows etc. Element symbol buttons are arranged in a periodic table layout. It also incorporates some 'standard' TeX symbols (e.g greek and italic characters) that may be useful in a chemistry context.  


Not quite a WYSIWYG chemistry editor, though still can simplify the construction of chemical equations and also act as an aide-memoire for mhchem syntax.
Not quite a WYSIWYG chemistry editor, though still can simplify the construction of chemical equations and also act as a coding environment and aide-memoire for mhchem syntax.


==Basics==
==Basics==
Line 78: Line 75:


<math>\mathrm{H_{2}O}</math>
<math>\mathrm{H_{2}O}</math>
<code>\ce{H2O}</code>
<code>\ce{ H2O }</code>


<math>\mathrm{Sb_{2}O_{3}}</math>
<math>\mathrm{Sb_{2}O_{3}}</math>
<code>\ce{Sb2O3}</code>
<code>\ce{ Sb2O3 }</code>


<math>\mathrm{H^{+}}</math>
<math>\mathrm{H^{+}}</math>
<code>\ce{H+}</code>
<code>\ce{ H+ }</code>


<math>\mathrm{CrO_{4}^{2-}}</math>
<math>\mathrm{CrO_{4}^{2-}}</math>
<code>\ce{CrO4^2-}</code>
<code>\ce{ CrO4^2- }</code>


<math>\mathrm{AgCl_{2}^-}</math>
<math>\mathrm{AgCl_{2}^-}</math>
<code>\ce{AgCl2-}</code>
<code>\ce{ AgCl2- }</code>


<math>\mathrm{[AgCl_{2}]^-}</math>
<math>\mathrm{[AgCl_{2}]^-}</math>
<code>\ce{[AgCl2]-}</code>
<code>\ce{ [AgCl2]- }</code>


<math>\mathrm{Y^{99+}}</math>
<math>\mathrm{Y^{99+}}</math>
<code>\ce{Y^{99}+}</code>
<code>\ce{ Y^{99}+ }</code>


<math>\mathrm{H_{2}(aq)}</math>
<math>\mathrm{H_{2}(aq)}</math>
<code>\ce{H2_{(aq)}}</code>
<code>\ce{ H2_{(aq)} }</code>


<math>\mathrm{NO_{3}^-}</math>
<math>\mathrm{NO_{3}^-}</math>
<code>\ce{NO3-}</code>
<code>\ce{ NO3- }</code>


<math>\mathrm{(NH_4)_2S}</math>
<math>\mathrm{(NH_4)_2S}</math>
<code>\ce{(NH4)2S}</code>
<code>\ce{ (NH4)2S }</code>


===Amounts===
===Amounts===
Line 112: Line 109:


<math>\mathrm{2H_{2}O}</math>
<math>\mathrm{2H_{2}O}</math>
<code>\ce{2H2O}</code>
<code>\ce{ 2H2O }</code>


<math>\mathrm{\frac{\scriptstyle{1}}{\scriptstyle{2}}H_{2}O}</math>
<math>\mathrm{\frac{\scriptstyle{1}}{\scriptstyle{2}}H_{2}O}</math>
<code>\ce{1/2H2O}</code>
<code>\ce{ 1/2H2O }</code>


===Isotopes===
===Isotopes===
<math>\mathrm{{}_{90}^{227}Th^{+}}</math>
<math>\mathrm{{}_{90}^{227}Th^{+}}</math>
<code>\ce{^{227}_{90}Th+}</code>
<code>\ce{ ^{227}_{90}Th+ }</code>
 
Although the above syntax works in most contexts, occasionally a leading pair of braces may be required
<code>\ce{ {}^{227}_{90}Th+ }</code>


===Fonts===
===Fonts===
Line 131: Line 131:


<math>\mathrm{H_{2}O}</math>, <math>\mathrm{H_{2}O}</math>
<math>\mathrm{H_{2}O}</math>, <math>\mathrm{H_{2}O}</math>
<code>\ce{H2O}, $\ce{H2O}$</code>
<code>\ce{ H2O }, $\ce{H2O}$</code>


<math>\mathrm{Ce^{IV}}</math>
<math>\mathrm{Ce^{IV}}</math>
<code>\ce{Ce^{IV}}</code>
<code>\ce{ Ce^{IV} }</code>


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.
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.
Line 140: Line 140:
===Special Symbols===
===Special Symbols===
<math>\mathrm{KCr(SO_4)_2 \cdot 12H_2O}</math>
<math>\mathrm{KCr(SO_4)_2 \cdot 12H_2O}</math>
<code>\ce{KCr(SO4)2*12H2O}</code>
<code>\ce{ KCr(SO4)2*12H2O }</code>


<math>\mathrm{KCr(SO_4)_2 \cdot 12H_2O}</math>
<math>\mathrm{KCr(SO_4)_2 \cdot 12H_2O}</math>
<code>\ce{KCr(SO4)2.12H2O}</code>
<code>\ce{ KCr(SO4)2.12H2O }</code>


<math>\mathrm{[Cd\{SC(NH_2)_2\}_2] \cdot [Cr(SCN)_4(NH_3)_2]_2}</math>
<math>\mathrm{[Cd\{SC(NH_2)_2\}_2] \cdot [Cr(SCN)_4(NH_3)_2]_2}</math>
<code>\cf{[Cd\{SC(NH2)2\}2].[Cr(SCN)4(NH3)2]2}</code>
<code>\ce{ [Cd\{SC(NH2)2\}2].[Cr(SCN)4(NH3)2]2 }</code>


<math>\mathrm{RNO_{2}^{-.}}</math>, <math>\mathrm{RNO_{2}^{-.}}</math>
<math>\mathrm{RNO_{2}^{-.}}</math>, <math>\mathrm{RNO_{2}^{-.}}</math>
<code>$\ce{RNO2^{-.}}$, \ce{RNO2^{-.}}</code>
<code>$\ce{ RNO2^{-.}}$, \ce{RNO2^{-.} }</code>


<math>\mu\!-\!\mathrm{Cl}</math>
<math>\mu\!-\!\mathrm{Cl}</math>
<code>\ce{$\mu\hyphen$Cl}</code>
<code>\ce{ $\mu\hyphen$Cl }</code>


===Bonds===
===Bonds===
Line 159: Line 159:


<math>\mathrm{C_6H_5\!-\!CHO}</math>
<math>\mathrm{C_6H_5\!-\!CHO}</math>
<code>\ce{C6H5-CHO}</code>
<code>\ce{ C6H5-CHO }</code>


<math>\mathrm{X \!=\!Y\!\equiv\!Z}</math>
<math>\mathrm{X \!=\!Y\!\equiv\!Z}</math>
<code>\ce{X=Y#Z}</code>
<code>\ce{ X=Y#Z }</code>


<math>\mathrm{A\!-\!B\! =\!C\!\equiv\!D}</math>
<math>\mathrm{A\!-\!B\! =\!C\!\equiv\!D}</math>
<code>\ce{A\sbond B\dbond C\tbond D}</code>
<code>\ce{ A\sbond B\dbond C\tbond D }</code>


Different books visualise bonds in extremely different ways. Currently, 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.
Different books visualise bonds in extremely different ways. Currently, 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.
Line 172: Line 172:


<math>\mathrm{A\!-\!B\!=\!C\!\equiv\!D}</math>
<math>\mathrm{A\!-\!B\!=\!C\!\equiv\!D}</math>
<code>\ce{A\bond{-}B\bond{=}C\bond{#}D}</code>
<code>\ce{ A\bond{-}B\bond{=}C\bond{#}D }</code>


<math>\mathrm{A\!\sim\!B\!\simeq\!C }</math>
<math>\mathrm{A\!\sim\!B\!\simeq\!C }</math>
<code>\ce{A\bond{~}B\bond{~-}C}</code>
<code>\ce{ A\bond{~}B\bond{~-}C }</code>


<math>\mathrm{A\!\cong\!B\!\cong\!C\!\cong\!D}</math>
<math>\mathrm{A\!\cong\!B\!\cong\!C\!\cong\!D}</math>
<code>\ce{A\bond{~=}B\bond{~--}C\bond{-~-}D}</code>
<code>\ce{ A\bond{~=}B\bond{~--}C\bond{-~-}D }</code>


<math>\mathrm{A\!\cdots\!B\!\cdot\cdots\!C}</math>
<math>\mathrm{A\!\cdots\!B\!\cdot\cdots\!C}</math>
<code>\ce{A\bond{...}B\bond{....}C}</code>
<code>\ce{ A\bond{...}B\bond{....}C }</code>


<math>\mathrm{A\!\rightarrow\!B\!\leftarrow\!C}</math>
<math>\mathrm{A\!\rightarrow\!B\!\leftarrow\!C}</math>
<code>\ce{A\bond{->}B\bond{<-}C}</code>
<code>\ce{ A\bond{->}B\bond{<-}C }</code>


===Using Math===
===Using Math===
Line 191: Line 191:


<math>\mathrm{Fe(CN)_{\frac{6}{2}}}</math>
<math>\mathrm{Fe(CN)_{\frac{6}{2}}}</math>
<code>\ce{Fe(CN)_{$\frac{6}{2}$}}</code>
<code>\ce{ Fe(CN)_{$\frac{6}{2}$} }</code>


<math>\mathrm{\mathit{x} Na(NH_4)HPO_4 \overset{\Delta }\rightarrow (NaPO_3)_\mathit{x} + \mathit{x} NH_3 \uparrow + \mathit{x} H_2O}</math>
<math>\mathrm{\mathit{x} Na(NH_4)HPO_4 \overset{\Delta }\rightarrow (NaPO_3)_\mathit{x} + \mathit{x} NH_3 \uparrow + \mathit{x} H_2O}</math>
<code>\ce{$x\,$ Na(NH4)HPO4 ->[\Delta](NaPO3)_{$x$} + $x\,$ NH3 ^ + $x\,$ H2O}</code>
<code>\ce{ $x\,$ Na(NH4)HPO4 ->[\Delta](NaPO3)_{$x$} + $x\,$ NH3 ^ + $x\,$ H2O }</code>
 
<math>\mathrm{CH_4(g) + 2O_2(g) \rightarrow CO_2(g) + 2H_2O(l)} \quad \Delta H_{\mathrm{c}}^{\ominus} = -890.3 \; \mathrm{kJ} \; \mathrm{mol}^{-1}</math>
<code>\ce{ CH_4(g) + 2O_2(g) -> CO_2(g) + 2H_2O(l) $\quad \Delta H_\ce{c}^{\ominus} = -890.3 \;$ kJ $\;$ mol^{-1} }</code>


==Formulae==
==Formulae==
Line 201: Line 204:


<math>\mathrm{CO_2 + C \rightarrow 2CO}</math>
<math>\mathrm{CO_2 + C \rightarrow 2CO}</math>
<code>\ce{CO2 + C -> 2CO}</code>
<code>\ce{ CO2 + C -> 2CO }</code>


<math>\mathrm{CO_2 + C \leftarrow 2CO}</math>
<math>\mathrm{CO_2 + C \leftarrow 2CO}</math>
<code>\ce{CO2 + C <- 2CO}</code>
<code>\ce{ CO2 + C <- 2CO }</code>


<math>\mathrm{CO_2 + C \rightleftharpoons 2CO}</math>
<math>\mathrm{CO_2 + C \rightleftharpoons 2CO}</math>
<code>\ce{CO2 + C <=> 2CO}</code>
<code>\ce{ CO2 + C <=> 2CO }</code>


<math>\mathrm{H^+ + OH^- \overset{-\!-\!-\!\rightharpoonup}{\quad \scriptstyle{\leftharpoondown} \quad} H_2O}</math>
<math>\mathrm{H^+ + OH^- \overset{-\!-\!-\!\rightharpoonup}{\quad \scriptstyle{\leftharpoondown} \quad} H_2O}</math>
<code>\ce{H+ + OH- <=>> H2O}</code>
<code>\ce{ H+ + OH- <=>> H2O }</code>


<math>A \leftrightarrow A'</math>
<math>A \leftrightarrow A'</math>
<code>\ce{$A$ <-> $A’$}</code>
<code>\ce{ $A$ <-> $A’$ }</code>


<math>\mathrm{CO_2 + C \; \overset{\alpha}{\rightarrow} \; 2CO}</math>
<math>\mathrm{CO_2 + C \; \overset{\alpha}{\rightarrow} \; 2CO}</math>
<code>\ce{CO2 + C ->[\alpha] 2CO}</code>
<code>\ce{ CO2 + C ->[\alpha] 2CO }</code>


<math>\mathrm{CO_2 + C \; \underset{\beta}{\overset{\alpha}{\rightarrow}} \; 2CO}</math>
<math>\mathrm{CO_2 + C \; \underset{\beta}{\overset{\alpha}{\rightarrow}} \; 2CO}</math>
<code>\ce{CO2 + C ->[\alpha][\beta] 2CO}</code>
<code>\ce{ CO2 + C ->[\alpha][\beta] 2CO }</code>


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.
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.


<math>\mathrm{CO_2 + C \; \overset{above}{-\!\!\!\longrightarrow} \; 2CO}</math>
<math>\mathrm{CO_2 + C \; \overset{above}{-\!\!\!\longrightarrow} \; 2CO}</math>
<code>\ce{CO2 + C ->[\text{above}] 2CO}</code>
<code>\ce{ CO2 + C ->[\text{above}] 2CO }</code>


<math>\mathrm{CO_2 + C \; \underset{below}{\overset{above}{-\!\!\!\longrightarrow}} \; 2CO}</math>
<math>\mathrm{CO_2 + C \; \underset{below}{\overset{above}{-\!\!\!\longrightarrow}} \; 2CO}</math>
<code>\ce{CO2 + C ->[\text{above}][\text{below}] 2CO}</code>
<code>\ce{ CO2 + C ->[\text{above}][\text{below}] 2CO }</code>


<math>\mathrm{CO_2 + C \;  \underset{below}{\overset{above}{-\!\!\!\longrightarrow}} \; 2CO}</math>
<math>\mathrm{CO_2 + C \;  \underset{below}{\overset{above}{-\!\!\!\longrightarrow}} \; 2CO}</math>
<code>\ce{CO2 + C ->T[above][below] 2CO}</code>
<code>\ce{ CO2 + C ->T[above][below] 2CO }</code>


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


<math>\mathrm{A \; \overset{H_2O}{\longrightarrow} \; B}</math>
<math>A \; \mathrm{ \overset{H_2O}{\longrightarrow}} \; B</math>
<code>\ce{$A$ ->[\ce{+H2O}] $B$}</code>
<code>\ce{ $A$ ->[\ce{+H2O} ] $B$}</code>


<math>\mathrm{A \; \overset{H_2O}{\longrightarrow} \; B}</math>
<math>A \; \mathrm{ \overset{H_2O}{\longrightarrow}} \; B</math>
<code>\ce{$A$ ->C[+H2O] $B$}</code>
<code>\ce{ $A$ ->C[+H2O] $B$ }</code>


===Precipitate and Gas===
===Precipitate and Gas===
Line 245: Line 248:


<math>\mathrm{SO_4^{2-} + Ba^{2+} \rightarrow BaSO_4 \downarrow}</math>
<math>\mathrm{SO_4^{2-} + Ba^{2+} \rightarrow BaSO_4 \downarrow}</math>
<code>\ce{SO4^2- + Ba^2+ -> BaSO4 v}</code>
<code>\ce{ SO4^2- + Ba^2+ -> BaSO4 v }</code>


===Watch Out!===
===Watch Out!===
Line 251: Line 254:


<math>A \mathrm{\overset{\text{Enclose  spaces!}}{\longleftarrow\!\!\!-\!\!\!-\!\!\!-\!\!\!-\!\!\!\longrightarrow}} A'</math>
<math>A \mathrm{\overset{\text{Enclose  spaces!}}{\longleftarrow\!\!\!-\!\!\!-\!\!\!-\!\!\!-\!\!\!\longrightarrow}} A'</math>
<code>\ce{$A$ <->T[{Enclose spaces!}] $A’$}</code>
<code>\ce{ $A$ <->T[{Enclose spaces!}] $A’$ }</code>


===Further Examples===
===Further Examples===
Line 257: Line 260:
<math>\mathrm{Zn^{2+} \underset{+2H^+}{\overset{+2OH^-}{\rightleftharpoons}} \underset{\text{amphoteric hydroxide}}{Zn(OH)_2 \downarrow} \underset{+2H^+}{\overset{+2OH^-}{\rightleftharpoons}}  \underset{\text{tetrahydroxozincate}}{[Zn(OH)_4]^{2-}}}</math>
<math>\mathrm{Zn^{2+} \underset{+2H^+}{\overset{+2OH^-}{\rightleftharpoons}} \underset{\text{amphoteric hydroxide}}{Zn(OH)_2 \downarrow} \underset{+2H^+}{\overset{+2OH^-}{\rightleftharpoons}}  \underset{\text{tetrahydroxozincate}}{[Zn(OH)_4]^{2-}}}</math>


<code>\ce{Zn^2+ <=>[\ce{+ 2OH-}][\ce{+ 2H+}]$\underset{\text{amphoteric hydroxide}}{\ce{Zn(OH)2 v}}$<=>C[+2OH-][{+ 2H+}]$\underset{\text{tetrahydroxozincate}}{\cf{[Zn(OH)4]^2-}}$}</code>
<code>\ce{ Zn^2+ <=>[\ce{+ 2OH-}][\ce{+ 2H+}]$\underset{\text{amphoteric hydroxide}}{\ce{Zn(OH)2 v}}$<=>C[+2OH-][{+ 2H+}]$\underset{\text{tetrahydroxozincate}}{\cf{[Zn(OH)4]^2-}}$ }</code>


<math>K = \mathrm{\frac{[Hg^{2+}][Hg]}{[Hg_2^{2+}]}}</math>
<math>K = \mathrm{\frac{[Hg^{2+}][Hg]}{[Hg_2^{2+}]}}</math>
Line 265: Line 268:
<math>\mathrm{Hg^{2+} \; \overset{I^-}{\rightarrow} \; \underset{\text{red}}{HgI_2} \; \overset{I^-}{\rightarrow} \; \underset{\text{red}}{[Hg^{II}I_4]^{2-}}}</math>
<math>\mathrm{Hg^{2+} \; \overset{I^-}{\rightarrow} \; \underset{\text{red}}{HgI_2} \; \overset{I^-}{\rightarrow} \; \underset{\text{red}}{[Hg^{II}I_4]^{2-}}}</math>


<code>\ce{Hg^2+ ->[\ce{I-}]$\underset{\mathrm{red}}{\ce{HgI2}}$->C[I-]$\underset{\mathrm{red}}{\ce{[Hg^{II}I4]^2-}}$}</code>
<code>\ce{ Hg^2+ ->[\ce{I-}]$\underset{\mathrm{red}}{\ce{HgI2}}$->C[I-]$\underset{\mathrm{red}}{\ce{[Hg^{II}I4]^2-}}$ }</code>


==Further information==
==Further information==


[http://http://www.ctan.org/pkg/mhchem The mhchem package]
[http://www.ctan.org/pkg/mhchem The mhchem package]


[http://www.ctan.org/tex-archive/macros/latex/contrib/mhchem/mhchem.pdf mhchem manual]
[http://www.ctan.org/tex-archive/macros/latex/contrib/mhchem/mhchem.pdf mhchem manual]


[http://http://docs.mathjax.org/en/latest/tex.html#mhchem MathJax and mhchem]
[http://docs.mathjax.org/en/latest/tex.html#mhchem MathJax and mhchem]


[[Category:Chemistry]]
[[Category:Chemistry]]

Latest revision as of 20:47, 18 February 2017

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

Why mhchem?

It is possible to display chemical formulae and equations using TeX mathematics mode. However, it is rather cumbersome for a range or reasons. Different display conventions: uppercase letters are displayed in italics for mathematics, whereas element symbols are upright for chemistry. The complexities of supercript and subscript notation, ions and isotopes. Bonds, equilibrium reaction arrows etc.

The mhchem extension allows a more adaptable display and more natural input of chemical formulae and equations. In Moodle, mhchem syntax can use text input directly into an HTML editor (TinyMCE or Atto) or by an Atto chemistry plugin (similar to the Atto equation plugin).

This is particularly useful for documenting isotopes, relative atomic and relative molecular mass, empirical and molecular formulae, balanced equations (full and ionic), equilibium reactions and themodynamics.

For more complex structural and displayed formulae (e.g. organic chemistry), homologous series and functional groups, you may also wish to consider a 'drawing' plugin such as the MarvinJS-based Chemical structures and reaction editor

Installation

The mhchem package can be integrated with Moodle in one of two ways. The first, via MathJax is the simplest to set up and provides high quality rendering. However, MathJax rendering depends on client-side JavaScript processing by the browser and may be subject to significant delay, e.g. on some platforms (especially mobile) or for particularly complex maths/science expressions. Also, there may be conflicts between MathJax and other JavaScript libraries (e.g. in some third-party Moodle plugins). In these cases, it may be advantageous to use the server-side TeX filter. After initial loading the TeX filter-generated images are cached, and so quick to display. The TeX filter typically generates lower quality display (MathJax > SVG > PNG > GIF), though the new SVG output option in Moodle 2.8 approaches the quality of MathJax.

In Moodle 2.8, it is possible to 'have the best of both worlds' by enabling the TeX and MathJax filters in parallel such that the TeX filter (particularly with SVG rendering) provides a fallback for MathJax, and vice versa.

via MathJax

MathJax has become the de facto standard for displaying mathematics on the Web and since version 2.7 Moodle has a built-in MathJax loader filter. However, mhchem still needs to be added to the MathJax configuration.

In Administration > Site administration > Plugins > Filters > Mathjax > Local Mathjax installation, edit the Mathjax configuration to include mhchem.js in the TeX extensions:

TeX: {extensions: ["AMSmath.js","AMSsymbols.js","mhchem.js","noErrors.js","noUndefined.js"]},

For Moodle 2.6 and earlier, MathJax, together with the mhchem extension, can be added to the site HEAD section in:

Administration > Site administration > Appearance > Additional HTML > Within HEAD

via LaTeX

It is also possible to add mhchem alongside LaTex on the Moodle server, and then use the Moodle TeX filter. You will need to install and configure the following binaries on the Moodle server.

latex

dvips

and either

dvisvg for SVG rendering (Moodle 2.8 and later)

or

convert for PNG/GIF rendering (Moodle 2.7 and earlier)

mhchem

Installation details will depend on the server operating system. Most Linux distributions can use their standard package manager to install the binaries and dependencies. e.g. For Fedora 20, mhchem can be installed with: yum install texlive-mhchem. Alternatively, you can use an appropriate LaTeX installation bundle, including mhchem, for Linux, Windows or Macintosh servers.

Once installed, in your Moodle Administration > Site administration > Plugins > Filters > TeX notation > LaTeX renderer Settings, add the following to the existing LaTeX preamble:

\usepackage{mhchem}

to give the following (or similar) preamble:

\usepackage[latin1]{inputenc}

\usepackage{amsmath}

\usepackage{amsfonts}

\usepackage{mhchem}

\RequirePackage{amsmath,amssymb,latexsym}

Atto Chemistry editor plugin

Once the TeX and/or MathJax loader filters are configured to use mhchem, and enabled, mhchem expressions can be directly typed into Moodle using the built-in (TinyMCE or Atto) text editors, as detailed in subsequent sections.

However, the Atto Chemistry editor plugin may also be convenient for users. This automatically wraps expressions within the required delimiters (e.g. \(\ce{...}\) and provides a set of tabbed toolbars and buttons for commonly used symbols, isotope format, reaction and equilibrium arrows etc. Element symbol buttons are arranged in a periodic table layout. It also incorporates some 'standard' TeX symbols (e.g greek and italic characters) that may be useful in a chemistry context.

Not quite a WYSIWYG chemistry editor, though still can simplify the construction of chemical equations and also act as a coding environment and aide-memoire for mhchem syntax.

Basics

Note that mhchem is not currently installed in this documentation wiki. Therefore the chemical display of chemical formulae and equations is simulated and may not exactly correspond to rendering using mhchem, which is usually nicer!.

The default TeX delimiters are \[...\] or $$...$$ for displayed mathematics, and \(...\) for in-line mathematics. For mhchem the additional delimiter \ce{...} is required inside the mathematics delimeters i.e .\[\ce{...}\] or $$\ce{...}$$ for displayed chemical formulae, and \(\ce{...}\) for in-line chemical formulae. In the rest of this document the TeX delimiters are not explicitly shown.

\ce{ H2O }

\ce{ Sb2O3 }

\ce{ H+ }

\ce{ CrO4^2- }

\ce{ AgCl2- }

\ce{ [AgCl2]- }

\ce{ Y^{99}+ }

\ce{ H2_{(aq)} }

\ce{ NO3- }

\ce{ (NH4)2S }

Amounts

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

\ce{ 2H2O }

\ce{ 1/2H2O }

Isotopes

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

Although the above syntax works in most contexts, occasionally a leading pair of braces may be required \ce{ {}^{227}_{90}Th+ }

Fonts

When you are in a math environment (e.g. opened and closed with a \[...\], \(...)\ or $$...$$), you could simply use \ce to set content 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_{\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, ...).

, \ce{ H2O }, $\ce{H2O}$

\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

\ce{ KCr(SO4)2*12H2O }

\ce{ KCr(SO4)2.12H2O }

\ce{ [Cd\{SC(NH2)2\}2].[Cr(SCN)4(NH3)2]2 }

, $\ce{ RNO2^{-.}}$, \ce{RNO2^{-.} }

\ce{ $\mu\hyphen$Cl }

Bonds

Horizontal bonds can be set using the characters -, = and # (single, double, triple bond) inside a formula (a - at the end of a formula yields a negative charge).

\ce{ C6H5-CHO }

\ce{ X=Y#Z }

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

Different books visualise bonds in extremely different ways. Currently, 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.

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

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

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

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

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

Using Math

To use math commands inside \ce{...}, one can enclose the commands with $.

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

\ce{ $x\,$ Na(NH4)HPO4 ->[\Delta](NaPO3)_{$x$} + $x\,$ NH3 ^ + $x\,$ H2O }

\ce{ CH_4(g) + 2O_2(g) -> CO_2(g) + 2H_2O(l) $\quad \Delta H_\ce{c}^{\ominus} = -890.3 \;$ kJ $\;$ mol^{-1} }

Formulae

Reaction Arrows

\ce{ CO2 + C -> 2CO }

\ce{ CO2 + C <- 2CO }

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

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

\ce{ $A$ <-> $A’$ }

\ce{ CO2 + C ->[\alpha] 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.

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

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

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

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

\ce{ $A$ ->[\ce{+H2O} ] $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.

\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.

\ce{ $A$ <->T[{Enclose spaces!}] $A’$ }

Further Examples

\ce{ Zn^2+ <=>[\ce{+ 2OH-}][\ce{+ 2H+}]$\underset{\text{amphoteric hydroxide}}{\ce{Zn(OH)2 v}}$<=>C[+2OH-][{+ 2H+}]$\underset{\text{tetrahydroxozincate}}{\cf{[Zn(OH)4]^2-}}$ }

$K = \frac{[\ce{Hg^2+}][\ce{Hg}]}{[\ce{Hg2^2+}]}$

\ce{ Hg^2+ ->[\ce{I-}]$\underset{\mathrm{red}}{\ce{HgI2}}$->C[I-]$\underset{\mathrm{red}}{\ce{[Hg^{II}I4]^2-}}$ }

Further information

The mhchem package

mhchem manual

MathJax and mhchem