From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/110613 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Fabrice Couvreur Newsgroups: gmane.comp.tex.context Subject: Lua code and table Date: Wed, 17 Feb 2021 18:40:54 +0100 Message-ID: Reply-To: mailing list for ConTeXt users Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1491202183469606751==" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34398"; mail-complaints-to="usenet@ciao.gmane.io" To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Wed Feb 17 18:46:10 2021 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane-mx.org Original-Received: from zapf.boekplan.nl ([5.39.185.232] helo=zapf.ntg.nl) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lCQtu-0008no-6w for gctc-ntg-context-518@m.gmane-mx.org; Wed, 17 Feb 2021 18:46:10 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 1E0AA280980; Wed, 17 Feb 2021 18:45:57 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Jh0czM0ef5LB; Wed, 17 Feb 2021 18:45:56 +0100 (CET) Original-Received: from zapf.ntg.nl (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 2EC57280A6C; Wed, 17 Feb 2021 18:45:56 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 14C42280937 for ; Wed, 17 Feb 2021 18:45:55 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id XSxITWJdZQZg for ; Wed, 17 Feb 2021 18:45:54 +0100 (CET) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=209.85.161.44; helo=mail-oo1-f44.google.com; envelope-from=fabrice1.couvreur@gmail.com; receiver= Original-Received: from mail-oo1-f44.google.com (mail-oo1-f44.google.com [209.85.161.44]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by zapf.ntg.nl (Postfix) with ESMTPS id 3618D28087D for ; Wed, 17 Feb 2021 18:45:54 +0100 (CET) Original-Received: by mail-oo1-f44.google.com with SMTP id e17so3246194oow.4 for ; Wed, 17 Feb 2021 09:45:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=VkN/WkJf/Vnv0HTv1g5ljHob/I1H8aPRnaHFL5PEb6w=; b=G4Xr+Pm6u6T6gMMeAt5kzS027RlmWUobHAftsN37O7c+NBeQ5BW1G/XHADMcSZwsQl gCz89EkT1tSKzBYCQpLT/OX7M0d12Qp/9cwbPv2lZXmWDPighgQLhokgVE7bug1h64v7 L7Ojupd0B2/V5h98lRLFgPfQoemz4KCtpj0uO5NToMnUv2MYjMvMhA1ILpLTN0dIq8bR 82pNFTpMQXY0rR4tI3IcQ8M3OS9/pZECO05zjK/hbtgTFfg9bylm84kBjhdv0u50kG+D 2a1ZYVjlXbSqmz/gbqOEtoBKzlLHdwm5lbbFz2JROQHJqye61EK9i6iDtDBzJS163/VG lpqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=VkN/WkJf/Vnv0HTv1g5ljHob/I1H8aPRnaHFL5PEb6w=; b=JCxXWmRuupEIZmcSp5GCqOgzHRc5kHI6MK9V6F+QA+b12LJxWHB0AOn3iz1Fy7fE9f fI/GPk06j0RQr3a6MENgtWs/KDjNh0TQ4X7UO0wT8IkK6wwt9Pk4QJy+ytmUA6xKdMlf vOdx/8z9OafB8nuxPe9P87mLU2zT230xnngdAFDqmShJJlYl+GJjGBqfMtBFmsgaTtWP L3D92Abjjo8WY9JYHzY0zIovo5nP425edukDhulYx0ReU1Cld5vBixllDyQOLOYR+/rg XqqfHmLNHWEBelRfnnbJAwwUXLgM0vqBbDQSwP8GziDS9jE6sOLF372SrDUXXCmqk33/ b8ag== X-Gm-Message-State: AOAM5336bNDpig7eCTVznznm/nryxHe8Zkboug9G3KRklAH7P8s2ru0C 0qj76F69HMMfhZ6koZdDUm5ixm/8HxeqR2t2G4nbtjl49KE= X-Google-Smtp-Source: ABdhPJx4A2aWEvUNcOMqq8E+i4V3gJVUKuqy+rfyTZJJ971SzZV9Dnj21gbRZ+tRUA1m6cPq9BZD7FIMb4Q+VfZQpaI= X-Received: by 2002:a4a:c44d:: with SMTP id h13mr116958ooq.65.1613583952209; Wed, 17 Feb 2021 09:45:52 -0800 (PST) X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.26 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" Xref: news.gmane.io gmane.comp.tex.context:110613 Archived-At: --===============1491202183469606751== Content-Type: multipart/alternative; boundary="000000000000496cfb05bb8bca69" --000000000000496cfb05bb8bca69 Content-Type: text/plain; charset="UTF-8" Hi, The code works, but is it possible to make it shorter ? Thank you Fabrice \startuseMPgraphic{DiagonalRule} rulethickness := \frameddimension{rulethickness}; drawoptions( withpen pencircle scaled rulethickness withcolor \MPcolor{\framedparameter{framecolor}}); pair leftcorner, rightcorner, Leftcorner, Rightcorner; leftcorner := (rulethickness, \overlayheight-rulethickness); rightcorner := (\overlaywidth-rulethickness, rulethickness); Leftcorner := ( rulethickness, rulethickness); Rightcorner := (\overlaywidth-rulethickness,\overlayheight-rulethickness); draw leftcorner -- rightcorner; draw Leftcorner -- Rightcorner; \stopuseMPgraphic \defineoverlay [DiagonalRule] [\useMPgraphic{DiagonalRule}] \define[2]\DiagonalLabel{% \setuptabulate [after={\blank[\frameddimension{offset}]}] \starttabulate [|p|r|] \NC \NC \bf #2 \NC\NR \NC \bf #1 \NC \NC\NR \stoptabulate } \starttext \startluacode local background_one = { align = "middle", style = "type", background = "DiagonalRule", } local letters_1 = { "A", "B", "C", "D", "E", "F", "G", "H" } context.startxtable({"align={middle,lohi}, width=0.8cm,offset=0.8ex,bodyfont=9pt,framecolor=cyan"}) context.startxrow() context.startxcell({"frame=off"}) context() context.stopxcell() for _, letter in ipairs(letters_1) do context.startxcell() context(letter) context.stopxcell() end context.stopxrow() for _, letter in ipairs(letters_1) do context.startxrow() context.startxcell() context(letter) context.stopxcell() for j = 0, 7 do context.startxcell( j == 0 and letter == "B" and background_one or j == 0 and letter == "C" and background_one or j == 0 and letter == "D" and background_one or j == 0 and letter == "G" and background_one or j == 0 and letter == "H" and background_one or j == 1 and letter == "A" and background_one or j == 1 and letter == "E" and background_one or j == 1 and letter == "F" and background_one or j == 1 and letter == "G" and background_one or j == 2 and letter == "A" and background_one or j == 2 and letter == "D" and background_one or j == 2 and letter == "F" and background_one or j == 2 and letter == "G" and background_one or j == 2 and letter == "H" and background_one or j == 3 and letter == "A" and background_one or j == 3 and letter == "C" and background_one or j == 3 and letter == "E" and background_one or j == 3 and letter == "H" and background_one or j == 4 and letter == "B" and background_one or j == 4 and letter == "D" and background_one or j == 4 and letter == "F" and background_one or j == 4 and letter == "G" and background_one or j == 5 and letter == "B" and background_one or j == 5 and letter == "C" and background_one or j == 5 and letter == "E" and background_one or j == 6 and letter == "A" and background_one or j == 6 and letter == "B" and background_one or j == 6 and letter == "C" and background_one or j == 6 and letter == "E" and background_one or j == 7 and letter == "A" and background_one or j == 7 and letter == "C" and background_one or j == 7 and letter == "D" and background_one ) context() context.stopxcell() end context.stopxrow() end context.stopxtable() \stopluacode \stoptext --000000000000496cfb05bb8bca69 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi, The code work= s, but is it possible to make it shorter ?
Thank you
<= /span> Fabrice


\startuseMPgraphic{DiagonalRule}
=C2=A0 = =C2=A0rulethickness :=3D \frameddimension{rulethickness};

=C2=A0 =C2= =A0drawoptions(
=C2=A0 =C2=A0 =C2=A0withpen pencircle scaled rulethickne= ss
=C2=A0 =C2=A0 =C2=A0withcolor \MPcolor{\framedparameter{framecolor}})= ;

=C2=A0 =C2=A0pair leftcorner, rightcorner, Leftcorner, Rightcorner= ;
=C2=A0 =C2=A0leftcorner =C2=A0:=3D (rulethickness, \overlayheight-rule= thickness);
=C2=A0 =C2=A0rightcorner :=3D (\overlaywidth-rulethickness, = rulethickness);
=C2=A0 =C2=A0Leftcorner =C2=A0:=3D ( rulethickness, rule= thickness);
=C2=A0 =C2=A0Rightcorner :=3D (\overlaywidth-rulethickness,\= overlayheight-rulethickness);

=C2=A0 =C2=A0draw leftcorner -- rightc= orner;
=C2=A0 =C2=A0draw Leftcorner -- Rightcorner;
=C2=A0\stopuseMPg= raphic

\defineoverlay
=C2=A0 [DiagonalRule]
=C2=A0 [\useMPgrap= hic{DiagonalRule}]

\define[2]\DiagonalLabel{%
=C2=A0 \setuptabula= te [after=3D{\blank[\frameddimension{offset}]}]
=C2=A0 \starttabulate [|= p|r|]
=C2=A0 =C2=A0 \NC =C2=A0 =C2=A0\NC \bf #2 \NC\NR
=C2=A0 =C2=A0 = \NC \bf #1 \NC =C2=A0 =C2=A0\NC\NR
=C2=A0 \stoptabulate
}
\startte= xt
\startluacode
=C2=A0 local background_one =3D {
=C2=A0 =C2=A0al= ign =3D "middle",
=C2=A0 =C2=A0style =3D "type",
= =C2=A0 =C2=A0background =3D "DiagonalRule",
=C2=A0 }

= =C2=A0 local letters_1 =3D { "A", "B", "C", &= quot;D", "E", "F", "G", "H" }<= br>=C2=A0 context.startxtable({"align=3D{middle,lohi}, width=3D0.8cm,o= ffset=3D0.8ex,bodyfont=3D9pt,framecolor=3Dcyan"})
=C2=A0 context.st= artxrow()
=C2=A0 context.startxcell({"frame=3Doff"})
=C2=A0= context()
=C2=A0 context.stopxcell()
=C2=A0 for _, letter in ipairs(= letters_1) do
=C2=A0 =C2=A0 context.startxcell()
=C2=A0 =C2=A0 contex= t(letter) context.stopxcell()
=C2=A0 end
=C2=A0 context.stopxrow()=C2=A0 =C2=A0for _, letter in ipairs(letters_1) do
=C2=A0 context.start= xrow()
=C2=A0 =C2=A0 context.startxcell()
=C2=A0 =C2=A0 context(lette= r)
=C2=A0 =C2=A0 context.stopxcell()
=C2=A0 for j =3D 0, 7 do
=C2= =A0 context.startxcell( =C2=A0j =3D=3D 0 and letter =3D=3D "B" an= d background_one
=C2=A0 or j =3D=3D 0 and letter =3D=3D "C" an= d background_one
=C2=A0 or j =3D=3D 0 and letter =3D=3D "D" an= d background_one
=C2=A0 or j =3D=3D 0 and letter =3D=3D "G" an= d background_one
=C2=A0 or j =3D=3D 0 and letter =3D=3D "H" an= d background_one
=C2=A0 or j =3D=3D 1 and letter =3D=3D "A" an= d background_one
=C2=A0 or j =3D=3D 1 and letter =3D=3D "E" an= d background_one
=C2=A0 or j =3D=3D 1 and letter =3D=3D "F" an= d background_one
=C2=A0 or j =3D=3D 1 and letter =3D=3D "G" an= d background_one
=C2=A0 or j =3D=3D 2 and letter =3D=3D "A" an= d background_one
=C2=A0 or j =3D=3D 2 and letter =3D=3D "D" an= d background_one
=C2=A0 or j =3D=3D 2 and letter =3D=3D "F" an= d background_one
=C2=A0 or j =3D=3D 2 and letter =3D=3D "G" an= d background_one
=C2=A0 or j =3D=3D 2 and letter =3D=3D "H" an= d background_one
=C2=A0 or j =3D=3D 3 and letter =3D=3D "A" an= d background_one
=C2=A0 or j =3D=3D 3 and letter =3D=3D "C" an= d background_one
=C2=A0 or j =3D=3D 3 and letter =3D=3D "E" an= d background_one
=C2=A0 or j =3D=3D 3 and letter =3D=3D "H" an= d background_one
=C2=A0 or j =3D=3D 4 and letter =3D=3D "B" an= d background_one
=C2=A0 or j =3D=3D 4 and letter =3D=3D "D" an= d background_one
=C2=A0 or j =3D=3D 4 and letter =3D=3D "F" an= d background_one
=C2=A0 or j =3D=3D 4 and letter =3D=3D "G" an= d background_one
=C2=A0 or j =3D=3D 5 and letter =3D=3D "B" an= d background_one
=C2=A0 or j =3D=3D 5 and letter =3D=3D "C" an= d background_one
=C2=A0 or j =3D=3D 5 and letter =3D=3D "E" an= d background_one
=C2=A0 or j =3D=3D 6 and letter =3D=3D "A" an= d background_one
=C2=A0 or j =3D=3D 6 and letter =3D=3D "B" an= d background_one
=C2=A0 or j =3D=3D 6 and letter =3D=3D "C" an= d background_one
=C2=A0 or j =3D=3D 6 and letter =3D=3D "E" an= d background_one
=C2=A0 or j =3D=3D 7 and letter =3D=3D "A" an= d background_one
=C2=A0 or j =3D=3D 7 and letter =3D=3D "C" an= d background_one
=C2=A0 or j =3D=3D 7 and letter =3D=3D "D" an= d background_one
=C2=A0 )
=C2=A0 context()
=C2=A0 context.stopxcel= l()
=C2=A0 end
=C2=A0 context.stopxrow()
=C2=A0 end
=C2=A0 cont= ext.stopxtable()
\stopluacode
\stoptext
--000000000000496cfb05bb8bca69-- --===============1491202183469606751== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX18KSWYgeW91ciBxdWVzdGlvbiBpcyBvZiBpbnRlcmVz dCB0byBvdGhlcnMgYXMgd2VsbCwgcGxlYXNlIGFkZCBhbiBlbnRyeSB0byB0aGUgV2lraSEKCm1h aWxsaXN0IDogbnRnLWNvbnRleHRAbnRnLm5sIC8gaHR0cDovL3d3dy5udGcubmwvbWFpbG1hbi9s aXN0aW5mby9udGctY29udGV4dAp3ZWJwYWdlICA6IGh0dHA6Ly93d3cucHJhZ21hLWFkZS5ubCAv IGh0dHA6Ly9jb250ZXh0LmFhbmhldC5uZXQKYXJjaGl2ZSAgOiBodHRwczovL2JpdGJ1Y2tldC5v cmcvcGhnL2NvbnRleHQtbWlycm9yL2NvbW1pdHMvCndpa2kgICAgIDogaHR0cDovL2NvbnRleHRn YXJkZW4ubmV0Cl9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fCg== --===============1491202183469606751==--