# Chemeq : a chemical equation parser

Chemeq is hosted as a project at Savannah-GNU

chemeq is a basic standalone filter written in C language, flex and bison. It inputs strings like:
2H2 + O2 ---> 2 H2O

and can outputs LaTeX code, many useful messages and much more.
It aims to be embedded in educational applications.

## Examples :

1. chemeq used inside a WIMS server to implement simple exercises.
2. chemeq used in a simple shell command :
 example:~$echo "2H2 + O2 ---> 2 H2O" | chemeq -lc 2\,H_{2}\,+\,O_{2}\,\rightarrow\,2\,H_{2}O OK  which means : 2 molecules of dihydrogen react with one molecule of dioxygen, yelding two water molecules. The first line, "2\,H_{2}\,+\,O_{2}\,\rightarrow\,2\,H_{2}O" is a translation of the equation in LaTeX language. The second line "OK" means that the equation is well equilibrated. When the input is not successfully parsed, the filter fails with the exit code 1.  example:~$ echo "2H^2 + O2 ---> 2 H2O" | chemeq -lc ERROR parse error at 4 

3. chemeq used in a shell command to match an erroneous syntax against a template, which may be a common student's mistake :
 example:~$input="1/2 H2 + 1/2 O2 -> 1/2 H2O" example:~$ template="H2 +O2 ->H2O" example:~$if [ "$(echo $input|chemeq -n)" = "$(echo \$template|chemeq -n)" ]; then > echo match; > else echo no match; > fi match 

## NOTES

• Syntax of ions
allthough in some cases, shorter expressions are sucessfully parsed, it is safer to consider that an "up arrow" (^) must be put before the charge symbols of an ion.
 Examples : H3O^+, Fe(CN)6^4-, OH^- 
• Square brackets
Square brackets are allowed outside of a simple chemical notation, as in [Fe(CN)6]4-, and only there.
• Chemical equilibrium constants
For chemical equilibriums, the constant for the Gulder-Waage equation or the potential for the Nernst equation can be written at the end of the equation, surrounded by parentheses. See some examples in src/test.1, and get them rendered by LaTeX with the command src/chemreport

This filter can be embedded in educational test systems, in order to analyze a student's answer to a problem of physics or chemistry.

This software snippet is GPL, see the file COPYING.

Feedback is welcome.

Options, Installation, Test mode and demo.