Jump to content

Recommended Posts

Posted (edited)

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 [math] 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
Posted

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]

Posted

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 :)

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

 

[math]\ce{H2 + O2 -> H2O + Energy}[/math]

 

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

 

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

Posted

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

 

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

 

(except for the little space).

Posted

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.

Posted (edited)

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

Guest mhchem
Posted

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.

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

  • 1 month later...
Posted (edited)

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
  • 4 months later...
Posted

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.

Posted

[math]

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

}

[/math]

 

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.

 

So if you know how to install LaTeX render in ASP please help us.

Thanks in advance

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?

Posted

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 :)

Posted

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.

  • 2 weeks later...
Posted

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

 

Cheers,

 

Ryan Jones

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.