LyXChemical formulas in LyX

Information and discussion about LyX, a WYSIWYM editor, available for Linux, Windows and Mac OS X systems.
drmCA
Posts: 31
Joined: Mon Aug 13, 2012 12:18 am

Chemical formulas in LyX

Post by drmCA »

Is there anything in LyX for writing chemical formulas and equasions, similar to Math toolbar?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

josephwright
Site Moderator
Posts: 814
Joined: Tue Jul 01, 2008 2:19 pm

Chemical formulas in LyX

Post by josephwright »

Not that I know of. Are you thinking of the 'A + B -> C' sort of thing or something more complex? The standard LaTeX approach to simple equations is to use mhchem.
Joseph Wright
drmCA
Posts: 31
Joined: Mon Aug 13, 2012 12:18 am

Chemical formulas in LyX

Post by drmCA »

I tried to request mhchem after installing it with mpm, but got the following:

\usepackage[version=3]{mhchem}

! LaTeX Error: File `mhchem.sty' not found.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Re: Chemical formulas in LyX

Post by Stefan Kottwitz »

Call Tools / Reconfigure in the LyX menu,

Stefan
LaTeX.org admin
drmCA
Posts: 31
Joined: Mon Aug 13, 2012 12:18 am

Chemical formulas in LyX

Post by drmCA »

Stefan_K wrote:Call Tools / Reconfigure in the LyX menu,

Stefan
Called, restarted LyX, still the same error.
Searching for the file mhchem.sty, I found it under

~/miktex-texmf/tex/latex/mhchem
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Re: Chemical formulas in LyX

Post by Stefan Kottwitz »

Perhaps LyX could not find it. Try to locate the main MiKTeX folder and install it there, perhaps it would work also if you save it to the same directory where your .lyx document is.

Stefan
LaTeX.org admin
drmCA
Posts: 31
Joined: Mon Aug 13, 2012 12:18 am

Chemical formulas in LyX

Post by drmCA »

Stefan_K wrote:Perhaps LyX could not find it. Try to locate the main MiKTeX folder and install it there, perhaps it would work also if you save it to the same directory where your .lyx document is.

Stefan
That would be strange, as that is the main folder, all other modules are installed there too, including KOMO script which does load.
Anyway, keeping sty file in the same folder works.
drmCA
Posts: 31
Joined: Mon Aug 13, 2012 12:18 am

Chemical formulas in LyX

Post by drmCA »

I can't seem to be able to get gas arrow to work.
Precipitate works fine as per below, but gas renders as ^.
Precipitate and Gas
Use v or (v) for precipitate (arrow down) and ^ or (^) for gas (arrow up), both separated by
spaces.
SO2–
4 +Ba2+ !BaSO4 # \ce{SO4^2- + Ba^2+ -> BaSO4 v}
NaClO + 2H2O > NaClO3 + 2H2 ^

Also, <-> works, but not <=>>
<-> renders into two double headed arrow.
<=>> should render into a longer left arrow with shorter right arrow underneath, but it renders into two opposing arrows of equal length, followed by degree and > sign.
drmCA
Posts: 31
Joined: Mon Aug 13, 2012 12:18 am

Chemical formulas in LyX

Post by drmCA »

This is why gas symbol does not work in chemical equasions under LyX.
It converts ^ symbol into \textasciicircum{}:

\ce{2NaCl + 2H2O -> H2 \textasciicircum{} + Cl2 \textasciicircum{}
+ 2NaOH


Only after exporting Lyx file to plain LaTeX I figured what was going on.
I need to render those symbols - how?

Further, import of a tex file containing this
\ce{ 2NaOH + Cl2 -> 2NaClO + H2 ^}
results in the ^ character being dropped from the source completely. Is that by design?
This is what the same line looks in LyX after import:
\ce{ 2NaOH + Cl2 -> 2NaClO + H2 }
drmCA
Posts: 31
Joined: Mon Aug 13, 2012 12:18 am

Re: Chemical formulas in LyX

Post by drmCA »

Apparenlty this is a bug in LyX, it is not treating the symbols correctly.
Post Reply