|
Cookbook /
SimpleChemSummary: Simple markup for chemical formulas in PmWiki 2.x pages
Version: 20081108
Prerequisites: PmWiki 2.0
Status: Experimental
Maintainer: Schilkek
Categories: Markup
Download: simplechem.zipΔ
Questions answered by this recipeIs there a simple way to write chemical formulas, such as (C6H5)2CHNH2, without having to include all those markup characters? DescriptionThe simplechem.zipΔ extension offers simple, inline markup that easily represents even complex chemical formulas with a minimum of markup characters. The recipe takes advantage of the structured format of chemical formulas, and inserts appropriate markup based on simple context rules. The result is surprisingly powerful, yet leaves chemical formulas easily readable by human chemists while editing. NotesThe goal of these markup rules is to allow authors to concentrate on the discussion of their
chemistry, not the intricacies of marking up the chemical formulas. The chemical formulas used in discussions of chemical reaction schemes are often complex, and it is extremely convenient to write, for instance, " Installation
include_once('cookbook/simplechem.php');
Once installed, chemical formulas on all pages are automatically marked up according to the rules below. Markup Rules and SyntaxTwo types of rules are provided to support chemical formulas in text. A simple, transparent rule automatically subscripts numbers in text that appears to be a chemical formula. A more advanced rule is explicitly invoked by a leading ampersand (&) character, and offers much more powerful markup options. Simple (transparent) chemical formula markup:Any string that appears to be a common atom followed by a number is rewritten to subscript the number. Strings like CH3CH2CH2OH, polymer-NH2, and H2SO4 are automatically converted to chemical formulas. Recognized atoms are C, H, O, N, P, S, Na, Si, Cl, and Br. These represent the most commonly encountered in biochemistry; extending this rule to other atoms is trivial. This markup makes it natural to write about (for instance) H2N-C6H4-COOH (p-aminobenzoic acid), or simple reactions like this: 3NaOH + H3PO4 ↔ Na3PO4 + 3H2O Some examples of transparent chemical formula markup are:
The transparent method can be combined with explicit markup to extend the repertoire of chemical formulas that can be created:
Clearly, writing the explicit markup quickly becomes cumbersome, and the resulting source is often hard to read and understand while editing. More advanced chemistry markup:For more complicated formulas, the author must signal the start of the formula text with a leading ampersand ('&') character. The formula continues until a character other than numbers, letters, or certain punctuation is encountered. The text "
Despite the relative simplicity of these rules, this markup scheme allows a wide range of formulas to be rendered with very minimal markup. See below for more illustrative examples. Note: No effort is made to ensure that the formula conforms to feasible chemical bonding, nor to IUPAC or SMILES naming conventions. It is up to the author to ensure that the formula makes sense from a physicochemical standpoint... no carbon atoms with 5 substituents, please!
Some examples will help demonstrate the power of this markup:
Note that the '+/-' symbols representing a charge must terminate an expression. To get multiple charges (e.g. an ionic pair), simply merge two formula statements:
Implementation considerations and limitationsNote that the markup needs to be done after links are resolved, to avoid incorrectly adding HTML markup to link names like:
The simple markup rule is fairly specific, but occasionally it will incorrectly mark up a word. To prevent this, simply wrap the offending text in For example, the string '
See alsoContributorsInitial implementation by Karl Schilke (Schilkek) for Oregon State University's School of Chemical, Biological and Environmental Engineering. This script is heavily based on suggestions by Peter Bowers and John Rankin. The author is grateful for their help and code examples. CommentsUser notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki. |