From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/47701 Path: news.gmane.org!not-for-mail From: Wolfgang Schuster Newsgroups: gmane.comp.tex.context Subject: Re: Taco's \molecule fails in mkiv Date: Tue, 24 Feb 2009 01:21:45 +0100 Message-ID: <77829622-2E53-4057-930D-AB577FEC2AF1@gmail.com> References: <6faad9f00902230821t6811fff4t4bc868c3e3f2999c@mail.gmail.com> <6D3CC355-796C-4E13-9CE5-0DF668E0439E@gmail.com> <6faad9f00902230914s502988d0pfc7cbc2f01ce570@mail.gmail.com> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 (Apple Message framework v930.3) Content-Type: multipart/mixed; boundary=Apple-Mail-7--570331734 X-Trace: ger.gmane.org 1235463672 27957 80.91.229.12 (24 Feb 2009 08:21:12 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 24 Feb 2009 08:21:12 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Tue Feb 24 09:22:27 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 1LbsYb-0007pF-OT for gctc-ntg-context-518@m.gmane.org; Tue, 24 Feb 2009 09:22:25 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id 37C4F1FB7F; Tue, 24 Feb 2009 09:21:02 +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 21038-01-3; Tue, 24 Feb 2009 09:21:01 +0100 (CET) Original-Received: from ronja.vet.uu.nl (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id C94A31FB57; Tue, 24 Feb 2009 08:53:06 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id 5B8741FA2B for ; Tue, 24 Feb 2009 08:51:41 +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 15275-02 for ; Tue, 24 Feb 2009 08:51:05 +0100 (CET) Original-Received: from filter1-til.mf.surf.net (filter1-til.mf.surf.net [194.171.167.217]) by ronja.ntg.nl (Postfix) with ESMTP id 0CF141FB1D for ; Tue, 24 Feb 2009 01:24:51 +0100 (CET) Original-Received: from fg-out-1718.google.com (fg-out-1718.google.com [72.14.220.153]) by filter1-til.mf.surf.net (8.13.8/8.13.8/Debian-3) with ESMTP id n1O0MRmC014169 for ; Tue, 24 Feb 2009 01:24:08 +0100 Original-Received: by fg-out-1718.google.com with SMTP id e21so32234fga.8 for ; Mon, 23 Feb 2009 16:22:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:received:received:message-id:from:to :in-reply-to:content-type:mime-version:subject:date:references :x-mailer; bh=YprONEX2i1VSnl4NE+OC5pKg3jKemCZFVwyylA7UxoU=; b=hWrg2BYTAcJMMcspqpKfh8yzPkPj+MYl9yDa//Dy5OfNkKfnWEAf/HMLxU2sq/pzBe 2rc8nKlswT5WL7LbCoFkQg67mZqEm7Ky4jzfPgEk2JYreHZG8f6q4VE4LJumPFHzNmG+ ho6M6raAl4Rn1PIG5tLyXNtBeOISgMAvFaK+E= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=message-id:from:to:in-reply-to:content-type:mime-version:subject :date:references:x-mailer; b=fZWYGqP58jQSdGTr3EyIUWZ0SxinlGEM24Olz/qeWIc9P4CQaJAdGcU5IIAZQrzhZD bwoZs+Az997EdzAMqjLhSlBIqb/W9Jetaprmyj96ZdtpfU3LtL5lvJlnkvpvfOe5fV6X zpdwQhznT8yk2G3IVfIJB7XNmJSH3PioH4lwc= Original-Received: by 10.86.66.9 with SMTP id o9mr3316868fga.14.1235434947169; Mon, 23 Feb 2009 16:22:27 -0800 (PST) Original-Received: from ?10.70.170.125? (8.106.113.82.net.de.o2.com [82.113.106.8]) by mx.google.com with ESMTPS id 3sm288651fge.32.2009.02.23.16.22.25 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 23 Feb 2009 16:22:26 -0800 (PST) In-Reply-To: <6faad9f00902230914s502988d0pfc7cbc2f01ce570@mail.gmail.com> X-Mailer: Apple Mail (2.930.3) X-Bayes-Prob: 0.0001 (Score 0, tokens from: @@RPTN) X-CanIt-Geo: ip=72.14.220.153; country=US; region=CA; city=Mountain View; postalcode=94043; latitude=37.4192; longitude=-122.0574; metrocode=807; areacode=650; http://maps.google.com/maps?q=37.4192,-122.0574&z=6 X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 184197773 - ba03c945361e X-Scanned-By: CanIt (www . roaringpenguin . com) on 194.171.167.217 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:47701 Archived-At: --Apple-Mail-7--570331734 Content-Disposition: attachment; filename=molecule_lpeg.tex Content-Type: application/octet-stream; x-mac-creator=48647261; x-unix-mode=0644; x-mac-type=2A2A2A2A; name="molecule_lpeg.tex" Content-Transfer-Encoding: 7bit \startluacode do thirddata = thirddata or { } local molecule = { } function molecule.text(one) tex.sprint(string.format("%s",one)) end function molecule.low(one,two) tex.sprint(string.format("%s\\low{%s}",one,two)) end function molecule.high(one,two) tex.sprint(string.format("%s\\high{%s}",one,two)) end function molecule.lowhigh(one,two,three) tex.sprint(string.format("%s\\lohi{%s}{%s}",one,two,three)) end function molecule.highlow(one,two,three) tex.sprint(string.format("%s\\lohi{%s}{%s}",one,two,three)) end local plus = lpeg.P("+") local minus = lpeg.P("-") local lowercase = lpeg.R("az") local uppercase = lpeg.R("AZ") local number = lpeg.R("09") local subscript = lpeg.P("_") local superscript = lpeg.P("^") local leftbrace = lpeg.P("{") local rightbrace = lpeg.P("}") local single = lowercase + number + plus + minus local multiple = leftbrace * single^1 * rightbrace local content = single + multiple local text = lpeg.C(uppercase^1) / molecule.text local low = lpeg.C(uppercase^1) * subscript * lpeg.C(content) / molecule.low local high = lpeg.C(uppercase^1) * superscript * lpeg.C(content) / molecule.high local lowhigh = lpeg.C(uppercase^1) * subscript * lpeg.C(content) * superscript * lpeg.C(content) / molecule.lowhigh local highlow = lpeg.C(uppercase^1) * superscript * lpeg.C(content) * subscript * lpeg.C(content) / molecule.highlow local parser = (lowhigh + highlow + low + high + text)^0 function thirddata.molecule(string) parser:match(string) end end \stopluacode \def\molecule#1{\ctxlua{thirddata.molecule("#1")}} \starttext \molecule{CO_2} \molecule{H^+} \molecule{H_2^+} \molecule{C_nH_{2n+1}OH} \stoptext --Apple-Mail-7--570331734 Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Am 23.02.2009 um 18:14 schrieb Mojca Miklavec: > thanks a lot for the very nice code :) :) :) > > The second example (H_2^+) does not return expected result - it > should have been > H\lohi{2}{+} > instead, but I don't require such cases for the current document, so I > guess that I'll just replace the old macro with this one for now in > order not to get distracted with TeX problems too much :) You can try the attatched, it use lpeg to parse the content. Wolfgang --Apple-Mail-7--570331734 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ___________________________________________________________________________________ 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 ___________________________________________________________________________________ --Apple-Mail-7--570331734--