From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/64604 Path: news.gmane.org!not-for-mail From: "Thomas A. Schmitz" Newsgroups: gmane.comp.tex.context Subject: Re: Marginal line numbers Date: Fri, 17 Dec 2010 23:41:00 +0100 Message-ID: <80D15B33-91BE-4D99-A49A-B9CA932D06F3@uni-bonn.de> References: Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 (Apple Message framework v1082) Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1292625697 24975 80.91.229.12 (17 Dec 2010 22:41:37 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 17 Dec 2010 22:41:37 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Fri Dec 17 23:41:32 2010 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from balder.ntg.nl ([195.12.62.10]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PTizS-00082X-9t for gctc-ntg-context-518@m.gmane.org; Fri, 17 Dec 2010 23:41:30 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id C35B3CA917; Fri, 17 Dec 2010 23:41:25 +0100 (CET) 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 F-s886WeyLRv; Fri, 17 Dec 2010 23:41:25 +0100 (CET) Original-Received: from balder.ntg.nl (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 3BC6ECA91D; Fri, 17 Dec 2010 23:41:18 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 4C0D5CA8BF for ; Fri, 17 Dec 2010 23:41:04 +0100 (CET) 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 YG-OyFH9H4A2 for ; Fri, 17 Dec 2010 23:41:02 +0100 (CET) Original-Received: from filter2-til.mf.surf.net (filter2-til.mf.surf.net [194.171.167.218]) by balder.ntg.nl (Postfix) with ESMTP id 020E2CA914 for ; Fri, 17 Dec 2010 23:41:01 +0100 (CET) Original-Received: from uni-bonn.de (mail.uni-bonn.de [131.220.15.113]) by filter2-til.mf.surf.net (8.14.3/8.14.3/Debian-5+lenny1) with ESMTP id oBHMf0IN003361 for ; Fri, 17 Dec 2010 23:41:01 +0100 Original-Received: from [87.178.49.47] (account tschmit1@uni-bonn.de HELO [192.168.0.2]) by fe2.uni-bonn.de (CommuniGate Pro SMTP 5.2.12) with ESMTPA id 51794563 for ntg-context@ntg.nl; Fri, 17 Dec 2010 23:41:00 +0100 In-Reply-To: X-Mailer: Apple Mail (2.1082) X-Bayes-Prob: 0.0001 (Score 0, tokens from: @@RPTN) X-CanIt-Geo: ip=131.220.15.113; country=DE; region=07; city=Bonn; latitude=50.7333; longitude=7.1000; http://maps.google.com/maps?q=50.7333,7.1000&z=6 X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 0bDImF1R7 - 7bf342d7b14a - 20101217 X-Scanned-By: CanIt (www . roaringpenguin . com) on 194.171.167.218 X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.12 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 Xref: news.gmane.org gmane.comp.tex.context:64604 Archived-At: On Dec 16, 2010, at 10:28 PM, Jon Crump wrote: > Thomas, et alia. > > Thanks so very much! I now have this: > > \startluacode > function filter(s) > if math.mod(s,5) == 0 then > context.color( { "darkred" }, s ) > end > end > \stopluacode > > \define[1]\MyNumber% > {\ctxlua{filter(#1)}\endgraf} > > \startxmlsetups xml:lb > \lineNumbers{\MyNumber{\xmlatt{#1}{n}}} > \xmlflush{#1} > \stopxmlsetups > > \defineinmargin [lineNumbers] [outer] [normal] > This was just an example to show you how to use lua to do things which are difficult or impossible or cumbersome in TeX alone, such as math, working with strings (substitutions, etc.), conditionals, loops... You don't have to take my code verbatim; the "darkred" was just meant to show that you can apply certain code to a number if it matches a condition (here: be divisible by 5). > This gets me what I wanted. Still fumbling greatly with the macro > syntax. I'm not sure what the recursion is for, for example. On the > other hand the lua seems rather straightforward to me by comparison. I > tried returning an empty string like this: context.color( {"blue"}, '' > ) to remove the other numbers, but that seemed silly, so I just > removed the 'else' clause instead, and that seemed to work as well. > Yes, of course, if all you want is process numbers divisible by 5, that's the easiest way. But it's good to know that lua allows more complex conditionals - you could use "elseif"s to make numbers divisible by 100 bold, or whatever. I find such conditionals in TeX much more cumbersome; even for somebody with no programming background like myself, they are easy to write in lua. The recursion was just a way of demonstrating the effect. \dorecurse is a wonderful macro to construct minimal examples (you can search the mail archive for some real gems). And, as a hint: constructing a compilable minimal example not only is educational (I don't know how often I could solve my problems when I tried to produce a minimal example and saw where my approach was failing), but will also improve your chances of people actually willing to help you. If you want to see an elegant way of producing minimal examples in xml, search the mail archive for "xmlprocessbuffer." Thomas ___________________________________________________________________________________ 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 ___________________________________________________________________________________