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 21493 invoked from network); 26 Oct 2023 09:25:28 -0000 Received: from cgl.ntg.nl (5.39.185.202) by inbox.vuxu.org with ESMTPUTF8; 26 Oct 2023 09:25:28 -0000 Received: from localhost (localhost [127.0.0.1]) by cgl.ntg.nl (Postfix) with ESMTP id 235A5483646 for ; Thu, 26 Oct 2023 11:23:45 +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 45sSj_mbqMqq for ; Thu, 26 Oct 2023 11:23:44 +0200 (CEST) Received: from cgl.ntg.nl (localhost [127.0.0.1]) by cgl.ntg.nl (Postfix) with ESMTP id 585C248372C for ; Thu, 26 Oct 2023 11:22:13 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by cgl.ntg.nl (Postfix) with ESMTP id 645B348341A for ; Thu, 26 Oct 2023 11:21:20 +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 R3FedE_4P3QI for ; Thu, 26 Oct 2023 11:21:19 +0200 (CEST) Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (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 C5B1C483411 for ; Thu, 26 Oct 2023 11:21:19 +0200 (CEST) Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-53d9b94731aso1056396a12.1 for ; Thu, 26 Oct 2023 02:21:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698312079; x=1698916879; 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=03YM5W7j2bF/Netpe/4rOqUTA2odsqFOjNbN3jT1p3Y=; b=f7XKSeDpeyRZbcFWlCLtn+6c/X70YNoKeK1ubTf9+r3JdZHEqEaQQdYuI0+c1b3F4D jLPn+9B3hZbqmEfvCAb9SHu+6e47e2bEqkuon1tiZZBuTQuQb4EpBcudS77qezWxwvRY xVpvzYQmW8ZhLN4QfwrNcYWfcEvUPycN2CeygVaMZifEqk8TOVySn8mhbnzEq4jN48KX b2qD0ZJ13y9xSD3+lSkAj1CQ/Y4M1uVdFvQLBiE4c0Gj+emzRCQSxc3FwqGIqWaIob/A vbeBEPVBR2iiFpmVGJEZeGb6PuwRFNEnk+ksepYAGDoQgVQr2d97wL19qERE2TXnyXjn nFRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698312079; x=1698916879; 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=03YM5W7j2bF/Netpe/4rOqUTA2odsqFOjNbN3jT1p3Y=; b=hFtt/9GNUGORNlLYT/8hxyKqmbiOlZlyKaX1LSAK9TfkzLQwxeZ2t4wyaJyGnY32DM JihDoTrYTXf4sfmPWIL4EW68UtwllWqAShq68ahvvr//h/r7CgD5SUAksURlh/0w/nH+ KOGd8Ju8teWjCAtt3ETsenb5oczn5DrPOst9fMcZeQpIlzjMkrV2q4Gxt8GalJh/MALX xTqUKEXBp8u1mBicfBlrnrLBtLcJODnQN6mxBKp4KOCZ/BpAymcg1fd5SAWU11ovQu1d ctDRCiSqgSK+VN6sLoV4qHiWDdZNeIMr+9u/DKAbSqV4ea3mf1ez5VdgSG6NH4kzH6T8 OUSg== X-Gm-Message-State: AOJu0YxnnXK6Lim6dCCKIcS1serstfXXaS7gSwkUjZtfMMoVXErV/Wgr SsDIKnPmmaGHWwCzVqT5SHoiBlUPmZY= X-Google-Smtp-Source: AGHT+IHw7EC0VqQMY/HA7Bsnh8tCgBpzDl0UVYI9jESuFB/GMx77z2kGBXCGoliexyJuGfIq4quRVg== X-Received: by 2002:a50:cd95:0:b0:540:ef98:39ae with SMTP id p21-20020a50cd95000000b00540ef9839aemr3361147edi.37.1698312078833; Thu, 26 Oct 2023 02:21:18 -0700 (PDT) Received: from [2a02:1210:42e3:ac00:907e:fd00:60:0] ([2a02:1210:42e3:ac00:c65:f7da:c064:911b]) by smtp.gmail.com with ESMTPSA id x30-20020a50d61e000000b0053fa13e27dcsm11092445edi.48.2023.10.26.02.21.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Oct 2023 02:21:18 -0700 (PDT) Date: Thu, 26 Oct 2023 11:21:12 +0200 From: Alexandre Christe To: mailing list for ConTeXt users Message-ID: <1b0a879f-6384-43d6-a336-973e3616958e@Spark> In-Reply-To: <858p6424-2683-9873-944r-08ronp9549os@hzvpu.rqh> References: <990d094b-4733-492b-83f2-8014d51658c5@Spark> <046d83a6-d4c5-4c01-99ed-57b83d555b86@Spark> <858p6424-2683-9873-944r-08ronp9549os@hzvpu.rqh> X-Readdle-Message-ID: 1b0a879f-6384-43d6-a336-973e3616958e@Spark MIME-Version: 1.0 Message-ID-Hash: F5TROJVNCKD7KY5STQ4MUGJUJGGQZLR6 X-Message-ID-Hash: F5TROJVNCKD7KY5STQ4MUGJUJGGQZLR6 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] Re: 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="===============7105985459015478729==" --===============7105985459015478729== Content-Type: multipart/alternative; boundary="653a2f8d_2733c8e2_273" --653a2f8d_2733c8e2_273 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hi, Thanks for your inputs Aditya and Bruce. I=E2=80=99m still having some issues when trying to include the output of= the filter module within lua. MNWE: =5Cdefineexternalfilter =C2=A0=5Bsympy=5D =C2=A0=5Bfiltercommand=3D=7B/Users/aleks/miniconda3/bin/python3 =5Cextern= alfilterinputfile=5Cspace > =5Cexternalfilteroutputfile=7D, =C2=A0bufferbefore=3Dinit, =C2=A0output=3D=7B=5Cexternalfilterbasefile.out=7D, =C2=A0readcommand=3D=5Ctypefile, =C2=A0read=3Dno,=5D =5Cstartbuffer=5Binit=5D from sympy import * =5Cstopbuffer =5Cstarttext =5Cstartluacode =C2=A0local deg2rad =3D =5B=5B =C2=A0%=5Cstartsympy =C2=A0print(latex(rad(%angleVal%))) =C2=A0%=5Cstopsympy =5D=5D local calcTrig=46unction =3D =5B=5B =C2=A0=5Cstartsympy =C2=A0from sympy import * =C2=A0print(latex(%fname%(rad(%angleVal%)))) =C2=A0=5Cstopsympy =5D=5D local angleList =3D =7B0, 30, 45, 60, 90, 120, 135, 150, 180, 210, 225, = 240, 270, 300, 315, 330, 360=7D for =5F, a in ipairs(angleList) do =C2=A0context.templates=5BcalcTrig=46unction=5D =7B =C2=A0fname =3D =22sin=22, =C2=A0angleVal =3D a =C2=A0=7D end =5Cstopluacode =5Cstoptext In particular, it fails as soon as=C2=A0=C2=A0=5Cstartsympy and =5Cstopsy= mpy are part of the template. Should I protect these=3F A. Christe Le 25 oct. 2023 =C3=A0 21:56 +0200, Aditya Mahajan ,= a =C3=A9crit : > On Wed, 25 Oct 2023, Alexandre Christe wrote: > > > Dear list, > > > > I=E2=80=99d like to know the best approach to make this a bit more us= able. I=E2=80=99m trying to typeset a table with sin/cos/tan values. I=E2= =80=99d like to be able to convert the angles in degrees into radians (wi= th math notation) and to compute the trigonometric function leading to si= n(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 = radians > > there is math.sind, cosd, etc. for computing sin for angle in degrees. = The implementation is l-math.lua is: > > local pipi =3D 2*math.pi/360 > > function math.sind(d) return sin(d*pipi) end > function math.cosd(d) return cos(d*pipi) end > function math.tand(d) return tan(d*pipi) end > > > and fail to display the result in symbolic form. > > Context doesn't do symbolic math. You can try checking if one of the sy= mbolic math libraries in lua provides all the features that you want. > > > One possible way would be to use Python and the t-filter module, like= this > > This can work as follows. Take the array of angles, and convert them to= the desired format in python and write them to a temp file. Read that te= mp file in lua and typeset it as you want. > > Another option is an old proof of concept by Luigi: https://github.com/= bastibe/lunatic-python which allowed two-way communication between python= and luatex. Not sure if it still works. > > Aditya > > =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F= =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F= =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F= =5F=5F=5F=5F=5F=5F=5F=5F=5F > If your question is of interest to others as well, please add an entry = to the Wiki=21 > > maillist : ntg-context=40ntg.nl / https://mailman.ntg.nl/mailman3/lists= /ntg-context.ntg.nl > webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirro= r) > archive : https://github.com/contextgarden/context > wiki : https://wiki.contextgarden.net > =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F= =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F= =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F= =5F=5F=5F=5F=5F=5F=5F=5F=5F --653a2f8d_2733c8e2_273 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline
Hi,

Thanks for your inputs Aditya and Bruce.

I=E2=80=99m still having some issues when trying to include the output of= the filter module within lua.

MNWE:

=5Cdefineexternalfilter&=23160;
&=23160;=5Bsympy=5D
&=23160;=5Bfiltercommand=3D=7B/Users/aleks/miniconda3/bin/python3 =5Cexte= rnalfilterinputfile=5Cspace > =5Cexternalfilteroutputfile=7D,
&=23160;bufferbefore=3Dinit,
&=23160;output=3D=7B=5Cexternalfilterbasefile.out=7D,
&=23160;readcommand=3D=5Ctypefile,
&=23160;read=3Dno,=5D

=5Cstartbuffer=5Binit=5D
from sympy import *
=5Cstopbuffer

=5Cstarttext

=5Cstartluacode
&=23160;local deg2rad =3D =5B=5B
&=23160;%=5Cstartsympy

&=23160;print(latex(rad(%angleVal%)))
&=23160;%=5Cstopsympy
=5D=5D

local calcTrig=46unction =3D =5B=5B<= /span>
&=23160;=5Cstartsympy
&=23160;from sympy import *

&=23160;print(latex(%fname%(rad(%angleVal%))))
&=23160;=5Cstopsympy
=5D=5D

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

for =5F, a in ipairs(angleList) do
&=23160;context.templates=5BcalcTrig=46unction=5D =7B
&=23160;fname =3D =22sin=22,
&=23160;angleVal =3D a
&=23160;=7D
end

=5Cstopluacode

=5Cstoptext

In particular, it fails as soon as&=23160;&=23160;=5Cstartsympy and =5Cst= opsympy are part of the template. Should I protect these=3F

A. Christe
Le 25 oct. 2023 =C3=A0 21:56 +0200,= Aditya Mahajan <adityam=40umich.edu>, a =C3=A9crit :
On Wed, 25 Oct 2023, Alexandre Christe wrote:

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

there is math.sind, cosd, etc. for computing sin for angle in degrees. Th= e implementation is l-math.lua is:

local pipi =3D 2*math.pi/360

function math.sind(d) return sin(d*pipi) end
function math.cosd(d) return cos(d*pipi) end
function math.tand(d) return tan(d*pipi) end

and fail to display the result in symbolic = form.

Context doesn't do symbolic math. You can try checking if one of the symb= olic math libraries in lua provides all the features that you want.
=
One possible way would be to use Python and= the t-filter module, like this

This can work as follows. Take the array of angles, and convert them to t= he desired format in python and write them to a temp file. Read that temp= file in lua and typeset it as you want.

Another option is an old proof of concept by Luigi: https://github.com/ba= stibe/lunatic-python which allowed two-way communication between python a= nd luatex. Not sure if it still works.

Aditya

=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F= =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F= =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F= =5F=5F=5F=5F=5F=5F=5F=5F
If your question is of interest to others as well, please add an entry to= the Wiki=21

maillist : ntg-context=40ntg.nl / https://mailman.ntg.nl/mailman3/lists/n= tg-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
=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F= =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F= =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F= =5F=5F=5F=5F=5F=5F=5F=5F
--653a2f8d_2733c8e2_273-- --===============7105985459015478729== 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 ___________________________________________________________________________________ --===============7105985459015478729==--