From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/48045 Path: news.gmane.org!not-for-mail From: Hans Hagen Newsgroups: gmane.comp.tex.context Subject: the other blog (chemical stuff) Date: Fri, 06 Mar 2009 10:20:46 +0100 Message-ID: <49B0EAEE.6040609@wxs.nl> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; Format="flowed" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1236331384 17246 80.91.229.12 (6 Mar 2009 09:23:04 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 6 Mar 2009 09:23:04 +0000 (UTC) To: mailing list for ConTeXt users , Aditya Mahajan Original-X-From: ntg-context-bounces@ntg.nl Fri Mar 06 10:24:20 2009 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from ronja.vet.uu.nl ([131.211.172.88] helo=ronja.ntg.nl) by lo.gmane.org with esmtp (Exim 4.50) id 1LfWHw-000449-JT for gctc-ntg-context-518@m.gmane.org; Fri, 06 Mar 2009 10:24:16 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id C11F11FB60; Fri, 6 Mar 2009 10:22:17 +0100 (CET) Original-Received: from ronja.ntg.nl ([127.0.0.1]) by localhost (smtp.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 05028-02-4; Fri, 6 Mar 2009 10:21:46 +0100 (CET) Original-Received: from ronja.vet.uu.nl (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id 305711FA4C; Fri, 6 Mar 2009 10:21:38 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id CD3EB1FA4C for ; Fri, 6 Mar 2009 10:21:20 +0100 (CET) Original-Received: from ronja.ntg.nl ([127.0.0.1]) by localhost (smtp.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 05028-02-3 for ; Fri, 6 Mar 2009 10:21:00 +0100 (CET) Original-Received: from filter2-til.mf.surf.net (filter2-til.mf.surf.net [194.171.167.218]) by ronja.ntg.nl (Postfix) with ESMTP id 602111FA2B for ; Fri, 6 Mar 2009 10:20:54 +0100 (CET) Original-Received: from mail.pragma-ade.net (dsl-083-247-100-017.solcon.nl [83.247.100.17]) by filter2-til.mf.surf.net (8.13.8/8.13.8/Debian-3) with ESMTP id n269Kr2M032720 for ; Fri, 6 Mar 2009 10:20:53 +0100 Original-Received: from [10.100.1.100] (unverified [10.100.1.100]) by controller-1 (SurgeMail 3.9e) with ESMTP id 16769-1840426 for multiple; Fri, 06 Mar 2009 10:20:47 +0100 User-Agent: Thunderbird 2.0.0.19 (Windows/20081209) X-Originating-IP: 10.100.1.100 X-Authenticated-User: hagen@controller-1 X-Bayes-Prob: 0.0001 (Score 0, tokens from: @@RPTN) X-CanIt-Geo: ip=83.247.100.17; country=NL; region=16; city=Dronten; latitude=52.5333; longitude=5.7167; http://maps.google.com/maps?q=52.5333,5.7167&z=6 X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 189505496 - 52376cc9a3db X-Scanned-By: CanIt (www . roaringpenguin . com) on 194.171.167.218 X-Virus-Scanned: amavisd-new at ntg.nl X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.11 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: ntg-context-bounces@ntg.nl Errors-To: ntg-context-bounces@ntg.nl X-Virus-Scanned: amavisd-new at ntg.nl Xref: news.gmane.org gmane.comp.tex.context:48045 Archived-At: Hi aditya, some comments on the other bog item ... (others may wikify it) you can do a quick and dirty solution as well (tested in mkiv): \def\MoleculeC#1{$\enablesupersub\tf#1$} now, concerning the lua solution, it looks pretty clean and ok, but there is some room for improvement ... the following version supports nested braces and numbers (we can let this evolve in a proper chemical subsystem if needed since eventually i will replace ppchtex anyway) \startluacode local molecule = { } local format, sprint = string.format, tex.sprint function commands.justtext(one) sprint(tex.ctxcatcodes,one) end function commands.low(str) sprint(tex.ctxcatcodes,format("\\low{%s}",str)) end function commands.high(str) sprint(tex.ctxcatcodes,format("\\high{%s}",str)) end function commands.lowhigh(one,two) sprint(tex.ctxcatcodes,format("\\lohi{%s}{%s}",one,two)) end function commands.highlow(one,two) sprint(tex.ctxcatcodes,format("\\hilo{%s}{%s}",one,two)) end local lowercase = lpeg.R("az") local uppercase = lpeg.R("AZ") local plus = lpeg.P("+") local minus = lpeg.P("-") local digit = lpeg.R("09") local sign = plus + minus local cardinal = digit^1 local integer = sign^0 * cardinal local leftbrace = lpeg.P("{") local rightbrace = lpeg.P("}") local nobrace = 1 - (leftbrace + rightbrace) local nested = lpeg.P { leftbrace * (nobrace + lpeg.V(1))^0 * rightbrace } local any = lpeg.P(1) local subscript = lpeg.P("_") local superscript = lpeg.P("^") local content = lpeg.C(nested + integer + any) -- could be made more efficient local lowhigh = subscript * content * superscript * content / commands.lowhigh local highlow = superscript * content * subscript * content / commands.highlow local low = subscript * content / commands.low local high = superscript * content / commands.high local justtext = lpeg.C((1 - somescript)^1) / commands.justtext local parser = (sometext + lowhigh + highlow + low + high)^0 function commands.molecule(string) parser:match(string) end \stopluacode \def\molecule#1{\ctxlua{commands.molecule("#1")}} \molecule{H_2SO_4^-2} \molecule{H_2SO_4^{-2}} \molecule{H_2SO_4^{-2{x}}} Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl ----------------------------------------------------------------- ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://tex.aanhet.net archive : https://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________