Difference between revisions of "Chemistry"
(added some examples of chemical structures) |
|||
Line 142: | Line 142: | ||
The main difference with the official chemic module is that the <code>\modlecule</code> from this example uses the same font as the one in surrounding text, while the official module always uses roman font (which is probably the proper way if you're writing dozens of formulas). Hans's module is also more powerful (can do much more trickery than a simple conversion of subscripts and superscripts). See the manuals listed above. | The main difference with the official chemic module is that the <code>\modlecule</code> from this example uses the same font as the one in surrounding text, while the official module always uses roman font (which is probably the proper way if you're writing dozens of formulas). Hans's module is also more powerful (can do much more trickery than a simple conversion of subscripts and superscripts). See the manuals listed above. | ||
+ | |||
+ | == Chemical structures == | ||
+ | |||
+ | (see also [http://mitglied.lycos.de/ppchtex/00index.html PPCHTeX structure database]) | ||
+ | |||
+ | <texcode> | ||
+ | \usemodule[chemic] | ||
+ | |||
+ | \starttext | ||
+ | |||
+ | \startchemical | ||
+ | \chemical[FIVE,FRONT,BB125,+SB3,-SB4,Z4][O] | ||
+ | \chemical[FIVE,FRONT,+R1235,+RZ1235][H,H,\SR{HOH_2C},OH] | ||
+ | \chemical[FIVE,FRONT,-R1235,-RZ1235][H,OH,H,H] | ||
+ | \stopchemical | ||
+ | |||
+ | \stoptext | ||
+ | </texcode> | ||
+ | |||
+ | [[Image:Chemistry_example1.png]] | ||
+ | |||
+ | <texcode> | ||
+ | \usemodule[chemic] | ||
+ | \setupchemical[width=fit] | ||
+ | |||
+ | \starttext | ||
+ | |||
+ | \startchemical | ||
+ | \chemical[SIX,B,C,MOV2,B,C,R234,RZ234,MOV5,MOV6,B,C,R561,RZ561] | ||
+ | [R,R,R,R,R,R] | ||
+ | \stopchemical | ||
+ | |||
+ | \stoptext | ||
+ | </texcode> | ||
+ | |||
+ | [[Image:chemistry_example2.png]] | ||
+ | |||
+ | To draw this structure horizontally: | ||
+ | <texcode> | ||
+ | \usemodule[chemic] | ||
+ | \setupchemical[width=fit] | ||
+ | |||
+ | \starttext | ||
+ | |||
+ | \rotate[rotation=90]{ | ||
+ | \startchemical | ||
+ | \chemical[SIX,B,C,MOV2,B,C,R234,RZ234,MOV5,MOV6,B,C,R561,RZ561] | ||
+ | [\RotR,\RotR,\RotR,\RotR,\RotR,\RotR] | ||
+ | \stopchemical | ||
+ | } | ||
+ | |||
+ | /stoptext | ||
+ | </texcode> | ||
+ | |||
+ | [[Image:chemistry_example3.png]] | ||
[[Category:Graphics]] | [[Category:Graphics]] | ||
[[Category:Chemistry]] | [[Category:Chemistry]] |
Revision as of 16:49, 26 January 2009
< Math, XML, Graphics, MetaPost >
ConTeXt comes with the extensive chemistry module PPCHTeX which allows the drawing of chemical structures and the typesetting of reactions.
PPCHTeX works with plain TeX, LaTeX and - of course - with ConTeXt.
- PPCHTeX (general) by Pragma
- PPCHTeX documentation by Pragma
- PPCHTeX mailing list
- PPCHTeX mailing list archive
Some other PPCHTeX links:
- PPCHTeX structure database
- PPCHTeX FAQ and PPCHTeX FAQ in PDF(rather old)
- TUG Boat article on PPCHTeX by Hans Hagen and A.F Otten
Some other links about chemistry in ConTeXt:
- Chromatograms macro
- ChemML (screen), MathML extension for chemistry
Formulae with chemic module
\usemodule[chemic] \chemical{HSO_4^{-}}
- It can also be used to typeset chemical reactions
\usemodule[chemic] \startformula \chemical{2H_2,+,O_2,->,2H_2O} \stopformula
Simple Formulae in Text Mode
An alternative to using the chemistry module or mathmode for typesetting simple formulae are the three ConTeXt commands \high, \low and \lohi. This might be useful if you want to typset the formula with the same font as the surrounding text (in titles or slanted fonts, although that might not be desired in all situations).
\ss H\low{2}O also consists of H\high{+} and OH\high{--}. There are two main carbon isotopes: \lohi{6}{12}C and \lohi[left]{6}{13}C.
Taco's macros implement this approach [1]:
\newbox\chemlowbox \def\chemlow#1% {\setbox\chemlowbox\hbox{{\switchtobodyfont[small]#1}}} \def\chemhigh#1% {\ifvoid\chemlowbox \high{{\switchtobodyfont[small]#1}}% \else \/\lohi{\box\chemlowbox}{{\switchtobodyfont[small]#1}}\fi } \def\finishchem% {\ifvoid\chemlowbox \else \iffluor \fluorfalse \kern-.1em \fi\low{\box\chemlowbox}\fi} % for "kerning" after F \newif\iffluor \unexpanded\def\molecule% {\bgroup \catcode`\_=\active \uccode`\~=`\_ \uppercase{\let~\chemlow}% \catcode`\^=\active \uccode`\~=`\^ \uppercase{\let~\chemhigh}% \dostepwiserecurse {65}{90}{1} {\catcode \recurselevel = \active \uccode`\~=\recurselevel \uppercase{\edef~{\noexpand\finishchem \rawcharacter{\recurselevel}}}}% \uccode `\~=`\F \uppercase{\def~{\finishchem F\fluortrue}}% \catcode`\-=\active \uccode`\~=`\- \uppercase{\def~{--}}% \loggingall \domolecule }% \def\domolecule#1% {\expandafter\scantokens\expandafter {\detokenize{#1\finishchem}}\egroup}
\bs Bold slanted molecules: \molecule{HSO_4^-} and \molecule{SF_6}
The main difference with the official chemic module is that the \modlecule
from this example uses the same font as the one in surrounding text, while the official module always uses roman font (which is probably the proper way if you're writing dozens of formulas). Hans's module is also more powerful (can do much more trickery than a simple conversion of subscripts and superscripts). See the manuals listed above.
Chemical structures
(see also PPCHTeX structure database)
\usemodule[chemic] \starttext \startchemical \chemical[FIVE,FRONT,BB125,+SB3,-SB4,Z4][O] \chemical[FIVE,FRONT,+R1235,+RZ1235][H,H,\SR{HOH_2C},OH] \chemical[FIVE,FRONT,-R1235,-RZ1235][H,OH,H,H] \stopchemical \stoptext
\usemodule[chemic] \setupchemical[width=fit] \starttext \startchemical \chemical[SIX,B,C,MOV2,B,C,R234,RZ234,MOV5,MOV6,B,C,R561,RZ561] [R,R,R,R,R,R] \stopchemical \stoptext
To draw this structure horizontally:
\usemodule[chemic] \setupchemical[width=fit] \starttext \rotate[rotation=90]{ \startchemical \chemical[SIX,B,C,MOV2,B,C,R234,RZ234,MOV5,MOV6,B,C,R561,RZ561] [\RotR,\RotR,\RotR,\RotR,\RotR,\RotR] \stopchemical } /stoptext