This DokuWiki plugin formats a molecular formula by using 'chem' tag.
| Download | chem.zip (1 KB) | 2008-09-29 |
|---|
| Appearance | code | memo |
|---|---|---|
| C2H6 | <chem>C2H6</chem> | |
| Na2HPO4 12H2O | <chem>Na2HPO4 12H2O</chem> | |
| Al2(SO4)3 | <chem>Al2(SO4)3</chem> | Using brackets |
| C2H5O2-Na+ | <chem>C2H5O2|-Na+</chem> | Inserted a pipe before a formal charge. |
| Cl2H6N2Pt2+ | <chem>Cl2H6N2Pt2+</chem> | Formal charge number before +/-. |
| [(C6H4)2]412+ | <chem>[(C6H4)2]4|12+</chem> | Using several combinations |
Usage of seperation between atom-numbers and charge-numbers
| Appearance | code | memo |
|---|---|---|
| SO42- | <chem>SO4|2-</chem> | Correctly formated |
| SO42- | <chem>SO42-</chem> | Needs a pipe between 4 and 2. |
| SO4 2- | <chem>SO4 2-</chem> | Undesired white space |
or,
(Kibi posted bug-fix and made some extension for isotope expression in the previous system of DW. Since a 'discussion plugin' is not deployed in this current DW, I pasted his/her comment here. Thanks, Kibi — i.obataya 2009/11/11 19:17)
I've made some improvements to your plugin: now it can handle not only charge number of ion, but oxidation state: N-3, N-1, N0, N+1, N+3, H2+1S+6O3-2S-2
Fixed error with ”+” in equation: 2H2 + O2 ⇒ 2H2O
Fixed error with alternative formulas like Anion2Cation3
Added support of isotope numbers: 238^U, 2|239^Pu
All you need is replace function getChemFormat with that:
function getChemFormat($raw){ $pattern = array("/([A-Za-z\]\)]+)(0)/", "/[\|]?([0-9]*)[\^]/", "/([^ ][\]\)]?)[\|]?(([\-\+][0-9]*)|([0-9]*[\-\+]))/", "/([A-Z]|[a-z]|\)|\])([1-9][0-9]*)/"); $replace = array("\${1}<sup>\${2}</sup>", "<sup>\${1}</sup>", "\${1}<sup>\${2}</sup>","\${1}<sub>\${2}</sub>"); return preg_replace($pattern,$replace,$raw); }
The examples ahead would be like this: