Putting Chemistry into LaTeX

The LaTeX Typesetting Language is a general purpose typesetting language. Its original primary purpose was to put mathematics into beautiful type. But as the decades have progressed from its inception, its underlying engine has remained relatively fixed, but there have been a plethora of packages added to the LaTeX system (authored by many people!) that greatly enhance its typesetting ability. Firstly, these packages add to the ability of authors to represent mathematics per se, but, secondly, also to represent related objects, such as flow charts, diagrams, even molecules. And this brings us to the adaptation of LaTeX to typeset chemistry in its various modes.

My first disclaimer is that I have not much worked with packages for typesetting chemistry, but I have studied the subject a little, so I'll share the little I know.

The one chemistry package I have used is mhchem.sty. Let's look at this package a bit.

The declaration for the purpose of mhchem is, according to one of its best promoters:

The mhchem package provides commands for typesetting chemical molecular formulae and equations.
which comes from the documentation PDF file by Martin Hensel (mhchem.pdf), as also does the following example:

Assuming that you already have LaTeX installed on your machine, to use this package, 1) download mhchem.sty and have it in the directory as you have your LaTeX file. 2) place the command \usepackage[version=4]{mhchem} in the header of your document, which is somewhere before the line \begin{document}.

You can find the files you need at
https://www.ctan.org/tex-archive/macros/latex/contrib/mhchem


Now let's look at a standard LaTeX version of a random chemical equation.

\begin{equation}
     2\text{Al}\liq + \text{Cr$_2$O$_3$}\sol \overset{\Delta}{\longrightarrow} \text{Al$_2$O$_3$}\sol + 2\text{Cr}\liq\,.
\end{equation}
which will look like

The use of the \text command will create a non-math environment by default, therefore the chemical symbol Al will be printed correctly and not in mathtype as Al. By the way, the way I usually create a displayed equation is with the

\begin{equation}.....\end{equation}

pair, but there are other ways to do this. To create math for in-line use, we use the $...$ pair. For example, to use the chemical symbol for water inline, we could use either H$_2$O or $\ce{H2O}$. (We wouldn't use $H_2O$ because the H and the O would be rendered in math italic.) For Einstein's famous energy equation, we could write: $E=mc^2$ which would look somewhat like E = mc2.

But if we use the mhchem package we get:

\begin{equation}
     2\ce{Al}\liq + \ce{Cr2O3}\sol \ce{->[\Delta]} \ce{Al2O3}\sol + 2\ce{Cr}\liq\,.
\end{equation}
which will look like

The two displayed equations are very close in appearance, but clearly it is easier to typeset the equation using the mhchem commands.

As for the commands \liq and \sol, I defined them myself and used even after I `converted' the file to include mhchem commands. I suppose this package has commands for them but I didn't bother to look them up as I had already put in the work to make my own commands, which, by the way, are as follows:

\newcommand{\liq}{\text{(l)}}
\newcommand{\sol}{\text{(s)}}

These user-defined commands (macros) can be placed almost anywhere in the document, though I usually place them in the preamble (header) of the document.

So far, my only use of this package is in my three papers on stoichiometry, which I started without using the package and then came to use it later on.

Our next topic is about how LaTeX is doing as a typesetting language for chemistry. My own university degree is in mathematics. I have worked with mathematicians to coauthor papers. But most of my collaboration has been with physicists. My own experience has been that in the math and physics communities, LaTeX has the preeminence. However, I read somewhere that the chemistry community, at least in America, has not overwhelmingly moved from MS Word and some similar document program to LaTeX. The two biggest reasons I remember for chemists holding out against moving to LaTeX is 1) It has a steep learning curve, and 2) many of the journals or publishing houses or university professors/thesis advisors they submit to will accept non-LaTeX submissions or even require Word documents or Times Roman type.

Most of what I have learned about this has come from the following link:

https://www.reddit.com/r/chemistry/comments/1vibrc/thesis_writing_word_vs_latex/

So, I want to just summarize the comments left at this page. Some argue that they must render output in Times Roman, which is not available by default in LaTeX, but is can be imported by use of mathptmx.

In addition to the mhchem package, some recommend the chemstyle package. Others recommend chemdraw and mol2chemfig for rendering individual molecules.


Final comments:

I've used both Word and LaTeX now for decades. For virtually all my documents which I will eventually export as a PDF file, I use Word for my fiction and LaTeX for almost everything else, including essays that may have no math in them at all. So, I feel I am in a good position to compare them.

I would say that LaTeX does have a 'steep' learning curve, but so does any other program that I would use to render a bunch of math in. I want at this time to judge the merits of Word vs LaTeX based only on the work one must put into the document compared to the quality of output.

This steep learning curve for LaTeX has been greatly lessened over the decades, as there are now abundant on-line resources, and practically every question I ever queried recently on the Internet on how to solve one of my LaTeX problems has been both asked and answered on some webpage or LaTeX forum. This greatly contrasts to a few decades ago, when all you had to solve your problems were a few costly manuals to read from. My point is that people who have formed a bias against LaTeX by having tried it only decades ago, may not be up-to-date on the abundance of free resources now available.

How about an example? When I just now entered the text "how to display a unity symbol in Word", I got back useless information way off topic. But when I entered "how to display a unity symbol in LaTeX", I got immediate useful information. By the way, what I mean by unity symbol is this (or variation of it):

This symbol was a real problem I had to solve in LaTeX recently, and I found the answers I needed quickly on the Internet. That's a hint of how good the online resources for LaTeX have become these days.

According to the search engines, a unity symbol for Word is a bunch of hands coming together, and for most uses in Word that makes sense. But if you were trying to typeset a mathematics unity symbol in Word, all those hits at the top of the query list are just noise you have to wade through.

So why do the search engines get it right for a unity symbol in LaTeX? Simple. Because LaTeX is about typesetting mathematics and the unity symbol has a meaning as a math symbol. And this is probably reinforced by frequent inquires on it.

Lastly, your LaTeX equations can now be ported effortlessly to webpages via in inclusion of a Mathjax environment definer in your webpages. More about this elsewhere.