From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,HTML_FONT_LOW_CONTRAST, HTML_MESSAGE,MAILING_LIST_MULTI autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 15263 invoked from network); 25 Oct 2023 15:50:43 -0000 Received: from cgl.ntg.nl (5.39.185.202) by inbox.vuxu.org with ESMTPUTF8; 25 Oct 2023 15:50:43 -0000 Received: from localhost (localhost [127.0.0.1]) by cgl.ntg.nl (Postfix) with ESMTP id 79BD3483673 for ; Wed, 25 Oct 2023 17:47:59 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at cgl.ntg.nl Received: from cgl.ntg.nl ([127.0.0.1]) by localhost (cgl.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id AXFiWcn59C7F for ; Wed, 25 Oct 2023 17:47:59 +0200 (CEST) Received: from cgl.ntg.nl (localhost [127.0.0.1]) by cgl.ntg.nl (Postfix) with ESMTP id 6206648364E for ; Wed, 25 Oct 2023 17:46:44 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by cgl.ntg.nl (Postfix) with ESMTP id 9D72F482DCF for ; Wed, 25 Oct 2023 17:45:56 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at cgl.ntg.nl Received: from cgl.ntg.nl ([127.0.0.1]) by localhost (cgl.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id GYs-CpuYsKsW for ; Wed, 25 Oct 2023 17:45:56 +0200 (CEST) Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com [209.85.160.180]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cgl.ntg.nl (Postfix) with ESMTPS id 2D13E482538 for ; Wed, 25 Oct 2023 17:45:56 +0200 (CEST) Received: by mail-qt1-f180.google.com with SMTP id d75a77b69052e-41cc776ccb4so37945241cf.1 for ; Wed, 25 Oct 2023 08:45:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698248754; x=1698853554; darn=ntg.nl; h=mime-version:subject:references:in-reply-to:message-id:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=HwvFrrTqfqwIF+g/2C5BdP1ooidRKzLD9d2H7O1VhgU=; b=cdcbN0DsnznzTAGJsT3TaOyhEcS6YO1rsnpxSMz+iEhSqYp0RWZrQDE44d7R6CXAJW qkVaImGZjwurLfE76nJT6riMs8ImEcsHvMmok1xtTYViw2MDpDoHE4On3JWjTHpI+MqJ tlxiY0e1d4M/zwRq9brxA5uz0YwynqTbMwMW64DBA3cmjaMcTZ7rqunND6rg1InSoOQv zC60JJzm9ClUSF6OLelnWyeKVudXTgHTsAp8JSegJXLUDd4VTaZq+KKsceZA739x1CJb 8LdFiKb88Idz5KLRik08DfyXZ1Fnsz6hCmdJV0j/3cip/fRM7PCZdi5LR2rtsoNaLZdp +bng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698248754; x=1698853554; h=mime-version:subject:references:in-reply-to:message-id:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=HwvFrrTqfqwIF+g/2C5BdP1ooidRKzLD9d2H7O1VhgU=; b=lcbWuTt/fvr1SDsP9N9+PFhvD9zHcI0LNDkGPMk1+RlbpTe57i3K2NyiDdh1U8VGpx IUffxszP2N3R8Qok1keLCeKQU1Kn//4rw0xvo/GL406Re/5jFvkmSMqyYAWUL3mJmr4U 39RnDWmIuD8ZOAKGQvs9aJSU/jsaOPaU9ZB7YDYvz5jFMQfE64clauAYkY7KU9Ey2gcT syjvks3/yhTMwemZO/dwPJIEd1esu7NJm4sWEZ+DqWQPAiI751WiaqzaBFLMYwbSZTGP 3rVkhmgeJT8HLmncJyeSD0Jk3OJDhMdKCvp88+sL6LC3kD0RXPytitzH6yXT5XSD0Ptq YUZg== X-Gm-Message-State: AOJu0YzaIBnpj6NEGi/eYba53n/1fTaYi6NNTvVSWP83fJuGiE8PaA55 1mDavQQ8CiRec4cNMuCT2yEvnA9epUA= X-Google-Smtp-Source: AGHT+IGU37gJFNL5VxXC5077JplX7X2FfJSvlog3iKiA/+cKEoHIIAp3Iavu2Sf2iLznFr3VrKqzCw== X-Received: by 2002:a05:622a:18b:b0:41c:b94a:98ac with SMTP id s11-20020a05622a018b00b0041cb94a98acmr18878210qtw.57.1698248753570; Wed, 25 Oct 2023 08:45:53 -0700 (PDT) Received: from [2a02:1210:42e3:ac00:6067:fd00:60:0] ([2a02:1210:42e3:ac00:998e:5126:cc5a:4f1e]) by smtp.gmail.com with ESMTPSA id fv18-20020a05622a4a1200b004182037f655sm4333152qtb.14.2023.10.25.08.45.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Oct 2023 08:45:53 -0700 (PDT) Date: Wed, 25 Oct 2023 17:45:46 +0200 From: Alexandre Christe To: Hans Hagen via ntg-context Message-ID: <046d83a6-d4c5-4c01-99ed-57b83d555b86@Spark> In-Reply-To: <990d094b-4733-492b-83f2-8014d51658c5@Spark> References: <990d094b-4733-492b-83f2-8014d51658c5@Spark> X-Readdle-Message-ID: 046d83a6-d4c5-4c01-99ed-57b83d555b86@Spark MIME-Version: 1.0 Message-ID-Hash: W4FXWOS37BKZNA4WXUKBUPWCDMV5MVNI X-Message-ID-Hash: W4FXWOS37BKZNA4WXUKBUPWCDMV5MVNI X-MailFrom: aleks.christe@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list Reply-To: mailing list for ConTeXt users Subject: [NTG-context] Combining python and lua List-Id: mailing list for ConTeXt users Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: multipart/mixed; boundary="===============6371293803311120440==" --===============6371293803311120440== Content-Type: multipart/alternative; boundary="6539382f_6934fcff_273" --6539382f_6934fcff_273 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Dear list, I=E2=80=99d like to know the best approach to make this a bit more usable= . I=E2=80=99m trying to typeset a table with sin/cos/tan values. I=E2=80=99= d like to be able to convert the angles in degrees into radians (with mat= h notation) and to compute the trigonometric function leading to sin(pi/4= ) =3D 1/2, or cos(pi/6) =3D sqrt(3)/2 and display it in math mode. Here=E2=80=99s my current MWE, where I fail to convert the angles in radi= ans and fail to display the result in symbolic form. =5Cstarttext =5Cstartluacode local angleList =3D =7B0, 30, 45, 60, 90, 120, 135, 150, 180, 210, 225, 2= 40, 270, 300, 315, 330, 360=7D context.bTABLE() =C2=A0context.bTR() =C2=A0context.bTD() context(=22=24x=24=22) context.eTD() =C2=A0context.bTD() context(=22=240=24=22) context.eTD() =C2=A0for =5F, a in ipairs(angleList) do =C2=A0context.bTD() context(=22=24=5Cletterpercent.0f=24=22,a) context.eT= D() =C2=A0end =C2=A0context.eTR() =C2=A0context.bTR() =C2=A0context.bTD() context(=22=24=5C=5Ccos(x)=24=22) context.eTD() =C2=A0for =5F, a in ipairs(angleList) do =C2=A0context.bTD() context(=22=24=5Cletterpercent.3f=24=22,math.cos(math= .rad(a))) context.eTD() =C2=A0end =C2=A0context.eTR() =C2=A0context.bTR() =C2=A0context.bTD() context(=22=24=5C=5Csin(x)=24=22) context.eTD() =C2=A0for =5F, a in ipairs(angleList) do =C2=A0context.bTD() context(=22=24=5Cletterpercent.3f=24=22,math.sin(math= .rad(a))) context.eTD() =C2=A0end =C2=A0context.eTR() =C2=A0context.bTR() =C2=A0context.bTD() context(=22=24=5C=5Ctan(x)=24=22) context.eTD() =C2=A0for =5F, a in ipairs(angleList) do =C2=A0if a =3D=3D 90 or a =3D=3D 270 then =C2=A0context.bTD() context(=22=24-=24=22) context.eTD() =C2=A0else =C2=A0context.bTD() context(=22=24=5Cletterpercent.3f=24=22,math.tan(math= .rad(a))) context.eTD() =C2=A0end =C2=A0end =C2=A0context.eTR() context.eTABLE() =5Cstopluacode =5Cstoptext =5Cstoptext One possible way would be to use Python and the t-filter module, like thi= s =5Cusemodule=5Bfilter=5D %It depends on your OS. In mine it's python3 =5Cdefineexternalfilter =C2=A0=5Bpythontyping=5D =C2=A0=5Bfiltercommand=3D=7Bpython3 =5Cexternalfilterinputfile =5Cspace >= =5Cexternalfilteroutputfile=7D, =C2=A0output=3D=7B=5Cexternalfilterbasefile.tex=7D, =C2=A0cache=3Dyes, =C2=A0readcommand=3D=5Ctypefile, =C2=A0spacebefore=3Dmedium, =C2=A0spaceafter=3Dmedium=5D %We copy settings to save typing =5Cdefineexternalfilter=5Bpythonformula=5D=5Bpythontyping=5D %But instead of typing, we input a formula =5Csetupexternalfilter=5Bpythonformula=5D =C2=A0=5Breadcommand=3D=5Csamplefile=5D %=5Cinput should also work =5Cstarttext Convert angle to radians: =24=5Cstartpythonformula =C2=A0from sympy import * =C2=A0print(latex(pi/180*60)) =C2=A0=5Cstoppythonformula=24 Compute trigonometric function: =24=5Cstartpythonformula =C2=A0from sympy import * =C2=A0print(latex(cos(pi/3))) =C2=A0=5Cstoppythonformula=24 =5Cstoptext However, I haven=E2=80=99t managed so far to combine things (lua and Pyth= on) in an automatic way. How should I proceed=3F A. Christe --6539382f_6934fcff_273 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline
Dear list,

I=E2=80=99d like to know the best approach to make this a bit more usable= . I=E2=80=99m trying to typeset a table with sin/cos/tan values. I=E2=80=99= d like to be able to convert the angles in degrees into radians (with mat= h notation) and to compute the trigonometric function leading to sin(pi/4= ) =3D 1/2, or cos(pi/6) =3D sqrt(3)/2 and display it in math mode.

Here=E2=80=99s my current MWE, where I fail to convert the angles in radi= ans and fail to display the result in symbolic form.

=5Cstarttext

=5Cstartluacode
local angleList =3D =7B0, 30, 45, 60, 90, 120, 135, 150, 180, 210, 225, 2= 40, 270, 300, 315, 330, 360=7D

context.bTABLE()
&=23160;context.bTR()
&=23160;context.bTD() context(=22=24x=24=22) context.eTD()
&=23160;context.bTD() context(=22=240=24=22) context.eTD()
&=23160;for =5F, a in ipairs(angleList) do
&=23160;context.bTD() context(=22=24=5Cletterpercent.0f=24=22,a) context.= eTD()
&=23160;end
&=23160;context.eTR()
&=23160;context.bTR()
&=23160;context.bTD() context(=22=24=5C=5Ccos(x)=24=22) context.eTD()
&=23160;for =5F, a in ipairs(angleList) do
&=23160;context.bTD() context(=22=24=5Cletterpercent.3f=24=22,math.cos(ma= th.rad(a))) context.eTD()
&=23160;end
&=23160;context.eTR()
&=23160;context.bTR()
&=23160;context.bTD() context(=22=24=5C=5Csin(x)=24=22) context.eTD()
&=23160;for =5F, a in ipairs(angleList) do
&=23160;context.bTD() context(=22=24=5Cletterpercent.3f=24=22,math.sin(ma= th.rad(a))) context.eTD()
&=23160;end
&=23160;context.eTR()
&=23160;context.bTR()
&=23160;context.bTD() context(=22=24=5C=5Ctan(x)=24=22) context.eTD()
&=23160;for =5F, a in ipairs(angleList) do
&=23160;if a =3D=3D 90 or a =3D=3D 270 then
&=23160;context.bTD() context(=22=24-=24=22) context.eTD()
&=23160;else
&=23160;context.bTD() context(=22=24=5Cletterpercent.3f=24=22,math.tan(ma= th.rad(a))) context.eTD()
&=23160;end
&=23160;end
&=23160;context.eTR()
context.eTABLE()
=5Cstopluacode

=5Cstoptext

=5Cstoptext

One possible way would be to use Python and the t-filter module, like thi= s

=5Cusemodule=5Bfilter=5D
%It depends on your OS. In mine it's python3
=5Cdefineexternalfilter
&=23160;=5Bpythontyping=5D
&=23160;=5Bfiltercommand=3D=7Bpython3 =5Cexternalfilterinputfile =5Cspace= > =5Cexternalfilteroutputfile=7D,
&=23160;output=3D=7B=5Cexternalfilterbasefile.tex=7D,
&=23160;cache=3Dyes,
&=23160;readcommand=3D=5Ctypefile,
&=23160;spacebefore=3Dmedium,
&=23160;spaceafter=3Dmedium=5D
%We copy settings to save typing
=5Cdefineexternalfilter=5Bpythonformula=5D=5Bpythontyping=5D
%But instead of typing, we input a formula
=5Csetupexternalfilter=5Bpythonformula=5D
&=23160;=5Breadcommand=3D=5Csamplefile=5D %=5Cinput should also work

=5Cstarttext

Convert angle to radians:
=24=5Cstartpythonformula
&=23160;from sympy import *
&=23160;print(latex(pi/180*60))
&=23160;=5Cstoppythonformula=24

Compute trigonometric function:
=24=5Cstartpythonformula
&=23160;from sympy import *
&=23160;print(latex(cos(pi/3)))
&=23160;=5Cstoppythonformula=24

=5Cstoptext

However, I haven=E2=80=99t managed so far to combine things (lua and Pyth= on) in an automatic way.

How should I proceed=3F

A. Christe
--6539382f_6934fcff_273-- --===============6371293803311120440== 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 / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror) archive : https://github.com/contextgarden/context wiki : https://wiki.contextgarden.net ___________________________________________________________________________________ --===============6371293803311120440==--