## Recommended Posts

So, in my quest to make LaTeX more useful on the forums, I stumbled upon the mhchem package. Basically, it allows you to very easily typeset chemical formuae and reactions. For example:

[ce]CO2 + C -> 2CO[/ce]

This looks great, and it's not complex either: to see the text I used to generate it, click on the image. Instead of using the $tag, we use the [ce] tag for chemical equations. Also, you can put things above the line, like so: [ce]CO2 + C ->[\text{heat}] 2CO[/ce] Here's a few more examples to whet your appetite: [ce]CO2 + C <=> 2CO[/ce] [ce]H+ + OH- <=>> H2O[/ce] [ce]SO4^2- + Ba^2+ -> BaSO4 v[/ce] If you want to typeset an individual molecule, such as [ce]H2SO4[/ce], the [ce] tag can handle it easily. You can do some of the following things as well: [ce](NH4)2S[/ce] [ce]NO3-[/ce] Hope you find it useful; I'll post again in a little while. [Important note: Some posts in this thread have LaTeX that does not display correctly. This is because they used the old method of displaying chemical equations. The new method, the [ce] tag, is now the only way that works.] Edited by Cap'n Refsmmat add a note ##### Link to post ##### Share on other sites • Replies 54 • Created • Last Reply #### Top Posters In This Topic #### Popular Days #### Top Posters In This Topic #### Popular Days #### Popular Posts So, in my quest to make LaTeX more useful on the forums, I stumbled upon the mhchem package. Basically, it allows you to very easily typeset chemical formuae and reactions. For example: [ce]CO2 + If it were me, I'd just end the CE section after your cdot then begin it again before the OH... Like this: [ce]Rf-CF2COOH + \cdot[/ce][ce]{OH} -> Rf-CF2\cdot + CO2 + H2O[/ce] [ce]R Oh yes, here's a very complex example to show you how much this thing can do: [ce]{{x\,}} Na(NH4)HPO4 ->[\Delta] (NaPO3)_{{x}} + {{x\,}} NH3 ^ + {{x\,}} H2O[/ce] ##### Link to post ##### Share on other sites Okay, a little introduction for people who've never used LaTeX before. Click on the images to look at the code that generated them. Basically, it's very simple. We can use the command [ce][/ce] to create individual molecules by themselves. For example, say we wanted to do H2SO4 - which is understandable, but looks a lot nicer with LaTeX. Then, in BBCode, we'd have the phrase [ce]H2SO4[/ce], as follows: [ce]H2SO4[/ce] Basically, you type whatever comes into your head. LaTeX sorts all the formatting out for you. Let's try a harder example: what about something like an ion H+? Again, type whatever comes into your head: [ce]H+[/ce] Click on the image to see the code that generated it. A little harder: (NaPO3)2. This requires not a lot more effort: [ce](NaPO3)2[/ce] Indeed, we just type it in like we did the last lot. It even typesets fractions for you: [ce]1/2H20[/ce] So typesetting this stuff is pretty easy. Formulae are just as easy. When you want a single arrow, you type ->. We can get something like: [ce]CO2 + C -> 2CO[/ce] pretty easily. You can make the arrow go left by typing <- instead of ->. To get something above the arrow, you need to put T[yourtext] next to the arrow. For instance: [ce]CO2 + C <-T[above] 2CO[/ce] The T basically tells LaTeX that you want text above, not some kind of math symbol. You can even get double arrows by using <=>, and if you wanted a longer arrow on the top then you might use <=>>. You'll want to check out the documentation (at the top of the page). It has a load of examples you can get your teeth into. Good luck ##### Link to post ##### Share on other sites TEST [ce]H2 + O2 -> H2O + \text{energy}[/ce] ##### Link to post ##### Share on other sites Wow, this addition is [math]\cf{SUPErB}$.

(A.k.a. sulfur-uranium-phosphorus-erbium-boron)

##### Share on other sites
damn it failed, why?
You need the [ math] [/ math] tags wrapped around it to get it to work (without the spaces, of course), like:

$\ce{H2 + O2 -> H2O + Energy}$

Also, you had some syntax errors. The code for the above was:

\ce{H2 + O2 -> H2O + Energy}


##### Share on other sites

I should point this out: you need to encapsulate everything in math tags:

[math ]\cf{SUPErB}[/math]

(except for the little space).

##### Share on other sites

For equations, it's best to use \ce. It renders -> properly then.

##### Share on other sites

$\ce{2Cs_{(s)} + 2H2O_{(l)} -> 2H2_{(g)} + 2Cs+_{(aq)} + 2OH-_{(aq)}}$

VERY cool!

##### Share on other sites

Sorry jdurg. I didn't edit anything in there. My computer displayed an error and so I clicked "edit post" to see what was up.

##### Share on other sites

$\ce{H2 + O2 -> H2O + Energy}$

##### Share on other sites

I've taken the liberty of typing up some of the reactions from the "What's your favourite reaction thread" as some more examples. These were pretty much copied and pasted straight in:

H2SO4's: [ce]Ca2C + H2O -> Ca(OH)2 + C2H2[/ce]

akcapr's: [ce]2Zn + O2 -> 2ZnO[/ce] and [ce]NH4NO3 -> N2O + 2H2O[/ce].

ed84c's: [ce]HF + Rb -> RbF + H2[/ce]

Another note: make sure you leave spaces between two elements that you want to connect up to a +; otherwise mhchem will think you're trying to type in an ion:

[ce]H2O+H2O -> 2H2O[/ce] or [ce]H2O + H2O -> 2H2O[/ce].

Edited by Cap'n Refsmmat
##### Share on other sites
Sorry jdurg. I didn't edit anything in there. My computer displayed an error and so I clicked "edit post" to see what was up.

No Problem. At one point, I tried to add in "+ KA-FREAKING-BOOM!!!!!!!!" to the equation, but it didn't like it for some reason and kept saying 'unspecified' error. So I just decided to leave it out.

##### Share on other sites

Can I take it, that we all would like to thank dave lots for his work on this?

##### Share on other sites

$\ce{MnO + H2SO4 -> MnSO4 + H2O}$

Cool, thanks for the guide.

Not a problem

##### Share on other sites

Hi!

This is the author of the mhchem LaTeX package. It's nice to see people using my work. Have a lot of fun with it!

If you have any feedback (good or bad), please feel free to contact me. In particular, I would be very interested if you find a chemical expression that mhchem does not support currently.

##### Share on other sites
Hi!

This is the author of the mhchem LaTeX package. It's nice to see people using my work. Have a lot of fun with it!

If you have any feedback (good or bad)' date=' please feel free to contact me. In particular, I would be very interested if you find a chemical expression that mhchem does not support currently.[/quote']

Sorry to sidetrack the thread all, but I'd like to offer my thanks to you It's a great package, ideal for this kind of forum environment.

##### Share on other sites
• 1 month later...

The LaTeX package has been updated to support mhchem 2.0. You can use the [ce] [/ce] tags to encapsulate anything you want to write.

The classic example: CO2 + C -> 2CO: [ce]CO2 + C -> 2CO[/ce]

Have fun

Edited by Cap'n Refsmmat
testing
##### Share on other sites
• 4 months later...

To typeset chemical formulae directly into your PHP forum you have to install LaTeX render for php with asmath package, and your server have to have Linux OS installed. To typeset chemical formulae with LaTeX you can combine PPCHTeX, XymTeX, any many more. You dont tell user how to typeset their desire formulae. I am writing a book about typesetting chemical formulae with LaTeX, if someone interested please let me know.

##### Share on other sites

Also want to try ... $\ce{Al + Cu -> Au + Cl}$

##### Share on other sites

$\ce{Zn^2+ <=>[\ce{+ 2OH-}][\ce{+ 2H+}] {\underset{\text{Hydroxide trong khong khi}}{\ce{Zn(OH)2 v}}} %group! <=>C[+2OH-][{+ 2H+}] {\underset{\text{Hydroxozikat}}{\cf{[Zn(OH)4]^2-}}}% group! }$

I've just typed some vietnamese words into the quote mode to show my friend how mhchem work in PHP, so this is an example for our admin to install this package in our chemistry club forum.

Nếu chúng ta có thể cài đặt được mhchem trong diễn đàn thì hay biết mấy giống như forum của người ta đó, bác Viên coi sao chuyển qua PHP để anh em có thể nhập được công thức hóa học, nhưng file xuất ra dưới dạng ảnh, có khi nào lại làm cho forum chạy chậm không?

In the mhchem manual I dont see any code for typeset organic ring formulae. Is this a disadvance of mhchem package?

##### Share on other sites

Only just seen this. It appears that mhchem doesn't really support organic rings. There are other style sheets around for this, but I haven't implemented them on here since they're quite hard from the standpoint of syntax for users. Maybe I'll get around to doing it one day

##### Share on other sites

Yes, I know many people try to write some packages for typesetting chemical formulae for inorganic and organic but, they seem to be difficult to use, some of them can typeset organic ring but not easy to locate the picture at the position that you desire. And another disadvantage of chemistry packages is the syntax too complicated for users, even me. You've done a wonderful work to help people insert some simple ones into this forum.

##### Share on other sites
• 2 weeks later...

dave, would there be any way to do basic structure diagrams and electron configurations in LaTeX?

Cheers,

Ryan Jones

## Create an account

Register a new account