The World of Astoria Bob

### Math and Chemistry using KaTeX and mhchem

Here’s a list of integrals that I needed to solve in my integral calculus class in undergraduate school at UB, followed by some chemistry rendering. The math and chemistry use the Kahn Academy’s KaTeX rendering system and an extension called mhchem, developed and maintained by Martin Hensel of Germany. I’ll be trying to incorporate more math and chemistry into writing as I develop more experience with these scripts, with the goal of developing guidance for writing using web browsers instead of word processing. Should be an exciting journey! Enjoy!

$\int \dfrac {\cos x}{\sqrt {1+\sin x}}dx = 2 \sqrt{ 1+ \sin x} + C$ $\int \dfrac {\sin ^{-1}x}{\sqrt {1-x^{2}}}dx = \dfrac {(\sin^{-1} x)^{2}} {2} + C$ $\int \dfrac {\tan x}{\cos ^{2}x}dx = \dfrac {\sec^{2} x}{2} + C$ $\int \dfrac {1}{1-\sin x}dx = -\dfrac {2}{\tan {\dfrac {x}{2}} - 1} + C$ $\int e^{\ln \sqrt {x}}dx = \frac{2x^{\frac{3}{2}}}{3} + C$ $\int \dfrac {\cos \sqrt {x}}{\sqrt {x}}dx = 2\sin \sqrt {x} + C$ $\int \dfrac {1}{\sqrt {x^{2}+2x+2}}dx = \ln {\mid \sqrt {x^{2}+2x+2}+x+1 \mid} + C$ $\int \dfrac {3x-7}{\left( x-1\right) \left( x-2\right) \left( x-3\right) }dx\ = \ln {\mid x-3 \mid} + \ln {\mid x-2 \mid} - 2 \ln {\mid x-1 \mid} + C$ $\int x^{2}e^{x}dx$ $\int \sqrt {x^{2}+1}dx$ $\int \dfrac {e^{x}}{1+e^{2x}}dx$ $\int \dfrac {1}{e^{x}+e^{-x}}dx$ $\int \dfrac {1}{1+\sqrt {x}}dx$ $\int \dfrac {1}{\sqrt {1+\sqrt {x}}}dx$ $\int x^{\frac {2}{3}}\left( x^{\frac {5}{3}}+1\right) ^{\frac {2}{3}}dx$ $\int \dfrac {\cot x}{\ln \left( \sin x\right) }dx$ $\int \dfrac {1}{\sqrt {e^{x}+1}}dx$

Now for some chemistry stuff! Here’s an inorganic reaction rendered with mhchem:

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

As you can see, it’s the reaction of mercury ion with iodide to first produce the diiodide, then reaction with further iodide produces the red tetraiodide complex.

Now let’s see what it looks like in-line. Here goes: $$\ce{Hg^2+ ->[I-] \underset{\mathrm{red}}{\ce{HgI2}} ->[I-] \underset{\mathrm{red}}{\ce{[Hg^{II}I4]^2-}}}$$

Now let’s switch up the reactants and products to do some organic chemistry:

$$\ce{ +}$$   $$\ce{CH3OH}$$    $$\ce{->[H+][\Delta]}$$ $$\ce{+}$$   $$\ce{H2O}$$

Here the reaction is the esterification of benzoic acid with methanol, catalyzed with an acid, and requiring heat, giving methyl benzoate and water as products.

Now here's a caffeine molecule that was drawn by taking a molfile from the web and converting it to an SVG file using a program called Open Babel that runs in a terminal on a computer, in other words a command-line app.

I did some editing on this svg file, as I did on the molecules above to get them looking like I want. I like the result.

After getting a new computer and installing the Brackets app and reinstalling the Open Babel package, I converted a morphine molfile I found in the ChemDoodle app directory I have into an svg file, and edited it like the above molecules to give the following:

morphine

I believe it might be possible to develop an app or script to edit the svg files produced from the molfiles so that they have the appearance seen here. One of the problems I see coming up is that the size of the molecule displayed will vary somewhat, and so a proper standard size may be hard to achieve. Another method used to produce molecules for documents is the LaTeX package chemfig. Its output looks slightly different than the svg output shown here, but takes considerably less text to produce. I will be experimenting with that method as well, and we’ll see which method produces better output.

Stay tuned!