From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/78281 Path: news.gmane.org!not-for-mail From: Sietse Brouwer Newsgroups: gmane.comp.tex.context Subject: Re: Referring to multiple elements Date: Fri, 14 Sep 2012 14:08:38 +0200 Message-ID: References: <20120913121532.3a6a107e@homerow> <20120914093302.7c98411a@homerow> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1347624553 27600 80.91.229.3 (14 Sep 2012 12:09:13 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 14 Sep 2012 12:09:13 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Fri Sep 14 14:09:17 2012 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from balder.ntg.nl ([195.12.62.10]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TCUht-0007mu-F6 for gctc-ntg-context-518@m.gmane.org; Fri, 14 Sep 2012 14:09:13 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 6D491101F4; Fri, 14 Sep 2012 14:09:06 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id u5sDeskmUIUW; Fri, 14 Sep 2012 14:09:04 +0200 (CEST) Original-Received: from balder.ntg.nl (localhost [IPv6:::1]) by balder.ntg.nl (Postfix) with ESMTP id 09E10101F8; Fri, 14 Sep 2012 14:09:04 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 6B144101F8 for ; Fri, 14 Sep 2012 14:09:02 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id I2mPJhXAzNNc for ; Fri, 14 Sep 2012 14:09:01 +0200 (CEST) Original-Received: from filter3-ams.mf.surf.net (filter3-ams.mf.surf.net [192.87.102.71]) by balder.ntg.nl (Postfix) with ESMTP id 8778E101F4 for ; Fri, 14 Sep 2012 14:09:01 +0200 (CEST) Original-Received: from mail-iy0-f169.google.com (mail-iy0-f169.google.com [209.85.210.169]) by filter3-ams.mf.surf.net (8.14.3/8.14.3/Debian-9.4) with ESMTP id q8EC8xfs023174 for ; Fri, 14 Sep 2012 14:08:59 +0200 Original-Received: by iagk10 with SMTP id k10so3910281iag.14 for ; Fri, 14 Sep 2012 05:08:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=voFsbilu/e2gMtVbrywgTmqEzo0UjLQuASIHaLF1GaA=; b=iIpsuXvE3+A6wmyzK8KJf5ShowAscMcISc2SsErGDHF3TpI70c/RhMkNOenRt0at6S owDXWESktcpmnfP1eTDzn0lKpB5AhqJKWLVNe/UB1uMFIDyx8TYtMHRXuV0I0hxtHXTV zMslTsEQQp5cguBE0gK1jlMn9w8xuQilNz3B+tzvtfNLXQr3gPIe+xqgKoIHvPPzo/zM 9C7YwGpIcDcAVy8hJ4pDg8ZE+tkKp+HfswJekORyYiCSjaFK3rkRzQvPJwLmIQwdatVj VmI8imDcpXziZQ7wryxoSKMiA31VPiRE5SmGgcxpMI5QH/WqoigcSCz58D8N5v5Qk4ep 3nBw== Original-Received: by 10.50.89.164 with SMTP id bp4mr2927641igb.28.1347624538702; Fri, 14 Sep 2012 05:08:58 -0700 (PDT) Original-Received: by 10.64.86.201 with HTTP; Fri, 14 Sep 2012 05:08:38 -0700 (PDT) In-Reply-To: <20120914093302.7c98411a@homerow> X-Bayes-Prob: 0.0001 (Score 0, tokens from: @@RPTN) X-CanIt-Geo: ip=209.85.210.169; 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: 03HX08Xlj - 9732b08a341c - 20120914 (trained as not-spam) X-Scanned-By: CanIt (www . roaringpenguin . com) on 192.87.102.71 X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.14 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ntg-context-bounces@ntg.nl Original-Sender: ntg-context-bounces@ntg.nl Xref: news.gmane.org gmane.comp.tex.context:78281 Archived-At: Hi Marco, The heart of what you need is a lua function that will take an array of numbers, and return an array of consective-number runs, like so: fignumarray = {1, 2, 3, 5, 6, 8, 10, 11, 12} -- figruns = get_runs(fignumarray) -- returns a table structured like so: --> figruns[1].start = 1, figruns[1].stop = 3, --> figruns[2].start = 5, figruns[2].stop = 6, --> figruns[3].start = 8, figruns[3].stop = 8, --> figruns[4].start = 10, figruns[4].stop = 12 I've written one below, plus the scaffolding required to feed it the right input, and print its output to ConTeXt. Only two functions still need writing --- one to turn the context argument [fig:f1, fig:f2, fig:f4] into a lua array of strings, and one to turn each reference string into a figure number. But this should get you on your way. If you're not comfortable with programming LuaTeX, say so and I can fill in the two missing functions sometime this weekend. But they should be doable, really. (And, of course, you may be far more experienced in LuaTeX than I, I don't know.) Cheers, Sietse % should be below startluacode block, but clearer like so \def\inwithranges[#1]% {\ctxlua{u.inwithranges("#1")}} \startluacode u = userdata or { } function get_runs(a) runs = { } run_start = 1 while run_start <= #a do run_stop = run_start while a[run_stop + 1] == a[run_stop] + 1 do run_stop = run_stop + 1 end print(a[run_start] .. "-" .. a[run_stop]) table.insert(runs, {["start"] = a[run_start], ["stop"] = a[run_stop]}) run_start = run_stop + 1 end return runs end function u.inwithranges(ref_string) -- CTX... means I expect ConTeXt already has this function in a library somewhere local ref_array = CTXstring_to_array(refs_string) --FIXME local ref_numbers = { } for _, v in ipairs(ref_array) do ref_numbers[i] = CTXref_to_fignumber(array) --FIXME end ref_numbers.sort() runs = get_runs(ref_numbers) for i, run in ipairs(runs) do context.in( {run.start} ) context("-") context.in( {run.stop} ) if i < #runs then context(',') end end end \stopluacode ___________________________________________________________________________________ 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 : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________