In the last post we downloaded and cleaned up a RSC template. In this post we will add Wright’s chemstyle package to make writing in chemistry even easier, and explore some basic equation and typesetting usage of mhchem and chemstyle. Chemscheme related items (e.g., auto-numbering of compounds) is in the last part of this series.
The chemstyle bundle is available at CTAN (link). We’ll download the entire package, which contains the description (chemstyle.pdf), as well as a .dtx file. To make the bundle available on your system, all you need to do is open .dtx in your tex-editor, and typeset once (with (pdf)TeX). Between mhchem (in our RSC template bundle as mhchem.sty) and chemstyle, we can typeset many chemistry “stuff” with great ease. Let’s go back to change the preamble of our zManuscript.tex to take advantage of chemstyle, and then we’ll play around with what they can do.
Line B tells LaTeX that we are going to use chemstyle, with the rsc option. (I don’t think this matters here, since the rest of the template has already specified the formatting.) Line A tells the typesetting engine to automatically convert any postscript files (.ps, .eps) into .pdfs in 2 runs. This is necessary for the “automagically number compounds” function. If you typeset this document now, the output should look identical to when the lines were not there, but there should be an additional section in the output panel. (Ignore the python line for now… that’s for another day!)
In the next two section, we’ll look at some examples of mhchem and chemstyle. If you would like to follow along, the blank RSC template, together with its daughter folders, is available here as a zip file.
Chemical Equations with mhchem
Martin Hensel’s chemistry package allows you to typeset chemical equations nicely and easily. The manual is available here; the top links from Google (as of Mar 10′) returns implementation of mhchem-LaTeX in blogs, and these have different syntax.
In the previous post we prepared a “writing” file distinct from the template information, and it is there that we will be trying out mhchem:
A – /manuscript/section1.tex is where we type in the equation. Save this file when you’re done, but do not typeset it (LaTeX will complain about a missing preamble.)
B – zManuscript.tex is the main manuscript, and all we need to do here is click on typeset. LaTeX will look for the files it call, and by this, find section1.tex.
C – the .pdf output.
Let’s look at the syntax of the equation a little more closely:
A – as with all LaTeX instructions, chemical equation (ce) is preceded by a backslash (\), with its boundaries defined by curly braces {}.
B – The hat ^ tells LaTeX to superscript the next alphabet, which in this case is a +; so LaTeX renders this as as opposed to a regular + that we use between two reactants.
C – The underscore _ on its own indicates that the next character is to be sub-scripted. That would mean … so we use the curly braces {} to show the entirety of needs to be small.
D – -> is interpreted and drawn as a reaction arrow.
At this point, it may seem like there’s limited advantage to this over a word processor, which may even be more convenient because one could easily super/sub-script with keyboard shortcuts. However, notice that in the output, the state symbols are directly under the charges, as they should be; word processor’s super/sub-script will always offset the text.
And while super/sub-script is the limit of what Word could do, mhchem-LaTeX can go further (examples taken from the mhchem manual):
Notice that the items are adjusted automatically (e.g., length of arrows, centering of text), and that it is possible to align multiple equations – all from a text-based input. Using a word processor, I would have hand-drawn them in ChemDraw or Illustrator. In the tutorial discussing python integration, I will show you an example of preparing custom chemistry exams (programmatically!)
Chemical Typesetting with chemstyle/SIUnit
chemstyle, and the SIUnits package it calls, offers a number of LaTeX instructions that makes writing easier. I’ve chosen to showcase the ones commonly used by chemists, and you can see the full set in their manuals (linked here: chemstyle, SIunit).
The commands above the thin line at line 11 comes from SIunits, and those below (E) comes from chemstyle. Note that at A, curly braces {} were used after \celsius. We do that to help LaTeX understand that the command has ended, and the trailing space is indeed a space we want. Without the set of {} braces, the next space will be omitted, and we get “Cis the same…”. B and C are “math” symbols for LaTeX, and they are typeset in enclosing pair of $$. (Very strange things happen when they are omitted.)
Compare C and D; in C, the superscript (^) has to operate on both ‘2’ and ‘3’, so we use curly braces {} to denote the scope. In D, we only wish for the next letter to be in superscript, so the scope could be omitted. I like to enclose all commands with {}, so I’m clear what their boundaries are.
Using these commands to express units and phrases can save you some time fishing for the right symbols; it also give you the flexibility to re-define how the commands should work, which is useful when submitting derivatives of the same manuscript to multiple agencies which have different conventions.
It is also possible to combine chemstyle and mhchem using inline syntax. This allows us to write equations like the following (\iPr is defined in chemstyle):
In the next part, we’ll look at the chemscheme, a part of chemstyle that we have not touched on yet.
Leave a Reply