From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/59442 Path: news.gmane.org!not-for-mail From: luigi scarso Newsgroups: gmane.comp.tex.context Subject: TeX macro to merge two lists, bit like Python's zip Date: Wed, 9 Jun 2010 00:16:37 +0200 Message-ID: Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1276035918 22346 80.91.229.12 (8 Jun 2010 22:25:18 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 8 Jun 2010 22:25:18 +0000 (UTC) To: Hans Hagen , mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Wed Jun 09 00:25:17 2010 connect(): No such file or directory 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 1OM7ES-0004fe-1n for gctc-ntg-context-518@m.gmane.org; Wed, 09 Jun 2010 00:25:16 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 912A7C9BD0; Wed, 9 Jun 2010 00:16:49 +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 N8CHECRzmql0; Wed, 9 Jun 2010 00:16:47 +0200 (CEST) Original-Received: from balder.ntg.nl (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 5968AC9BC5; Wed, 9 Jun 2010 00:16:45 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 89EEDC9BC4 for ; Wed, 9 Jun 2010 00:16:43 +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 xcxvWS2LmW9o for ; Wed, 9 Jun 2010 00:16:41 +0200 (CEST) Original-Received: from mail-wy0-f169.google.com (mail-wy0-f169.google.com [74.125.82.169]) by balder.ntg.nl (Postfix) with ESMTP id 34609C9BC1 for ; Wed, 9 Jun 2010 00:16:41 +0200 (CEST) Original-Received: by wya21 with SMTP id 21so43069wya.14 for ; Tue, 08 Jun 2010 15:16:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:date:message-id :subject:from:to:content-type; bh=jaszF4WbBGmFRJ7GZP2Z/lSCyMjNDo6nov0KGx8iJmo=; b=ZUpL5pGIBWVsp0t4GKCzNXHbrj+0Xm0S9ruEfQkim/p/6I/bBJQ0ANHDoDW9MUkrAn q0sdUvdZJHsM70Eoorbi6AzsP4sl+J+eo2L/tjHXsbr3BHaobFWVVxm6SRyl74FH3NfA HVViPs48wXvWZy/RJMn13m1glv528wKmJ/Z98= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=Na4Xh5dcZvMuLw97NLmuErnNTTNOkkcC4wimuGOeIYzM3ofip366c797FJRNWHFs6P b2ebFnXM3HNkWqRCXKituzrAOyfkPdT2KfeI9vEhyLO4EJTw7e5yaVqi0HP9E6eKkHhN LK7bR7mWC1Xw9xea5fLAan0POXkscenmM0ry4= Original-Received: by 10.216.184.6 with SMTP id r6mr3858449wem.87.1276035397608; Tue, 08 Jun 2010 15:16:37 -0700 (PDT) Original-Received: by 10.216.22.19 with HTTP; Tue, 8 Jun 2010 15:16:37 -0700 (PDT) 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:59442 Archived-At: J. Fine asked sometime ago something like python's zip tha merge two "lists" element by element, cfr. http://groups.google.com/group/comp.text.tex/browse_thread/thread/2c1feea4ad19501e/cf6f849c5b81e76c?show_docid=cf6f849c5b81e76c Here is the idea: a list is zero or more control sequence, ie {} is an empty list, \Alpha\Beta is a list with 2 elements, and so on. \zip{\Alpha\Beta}{\Gamma\Delta} gives \Alpha\Gamma\Beta\Delta \starttext % Hans's hint % \def\zipthem#1#2% % {\def\dozipthem##1{\def\dodozipthem####1{1\string##1 2\string####1}\handletokens#2\with\dodozipthem}% % \handletokens#1\with\dozipthem} \def\myzipthem#1#2% {\ctxlua{A = {}; B = {}} \def\dozipthemA##1{\ctxlua{table.insert(A,[[\string##1]])}}% \def\dozipthemB##1{\ctxlua{table.insert(B,[[\string##1]])}}% \handletokens#1\with\dozipthemA \handletokens#2\with\dozipthemB% \ctxlua{% for i=1,math.max(table.maxn(A),table.maxn(B)) do local a = "" local b = "" if A[i] then a = '\\string' ..A[i] end if B[i] then b = '\\string' ..B[i] end tex.sprint(a,b) end tex.print([[\blank]]) for i=1,math.max(table.maxn(A),table.maxn(B)) do local a = A[i] or "" local b = B[i] or "" tex.sprint(a,b) end tex.print([[\blank]]) } } \def\Alpha{A} \def\Beta{B} \def\Gamma{C} \def\Delta{D} \myzipthem{\Alpha\Beta}{\Gamma\Delta}%gives \Alpha\Gamma\Beta\Delta \myzipthem{}{\Gamma\Delta} \stoptext For ours bloggers. -- luigi ___________________________________________________________________________________ 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 ___________________________________________________________________________________