~~ODT~~

Chem plugin

This DokuWiki plugin formats a molecular formula by using 'chem' tag.

Downloadchem.zip (1 KB)2008-09-29

Examples

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

Installation

  1. Download and extract chem.zip.
  2. Upload the 'chem' folder to 'lib/plugins' directory of your DokuWiki.

or,

  1. Create a ‘chem’ directory in ‘lib/plugins’ directory.
  2. Put the code below with a name of 'syntax.php' into 'chem' directory.

History

  • 2008-09-29 Supported the Open document format export using ODT plugin.
  • 2008-03-21 Seperator implementation and bracket support

DISCUSSION

Kibi's bug-fix

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

  • oxidation state: N-3, N-1, N0, N+1, N+3, H2+1S+6O3-2S-2
  • ”+” in equation: 2H2 + O2 ⇒ 2H2O
  • alternative formulas like Anion2Cation3
  • isotope numbers: 238U, 2239Pu
 
en/chem_plugin.txt · Last modified: 2010/01/24 12:04 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
2010 I.Obataya