ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Aditya Mahajan <adityam@umich.edu>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: [NTG-context] Re: Combining python and lua
Date: Wed, 25 Oct 2023 21:52:58 +0200 (CEST)	[thread overview]
Message-ID: <858p6424-2683-9873-944r-08ronp9549os@hzvpu.rqh> (raw)
In-Reply-To: <046d83a6-d4c5-4c01-99ed-57b83d555b86@Spark>

[-- Attachment #1: Type: text/plain, Size: 1451 bytes --]

On Wed, 25 Oct 2023, Alexandre Christe wrote:

> Dear list,
> 
> I’d like to know the best approach to make this a bit more usable. I’m trying to typeset a table with sin/cos/tan values. I’d like to be able to convert the angles in degrees into radians (with math notation) and to compute the trigonometric function leading to sin(pi/4) = 1/2, or cos(pi/6) = sqrt(3)/2 and display it in math mode.
> 
> Here’s 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 = 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 symbolic 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 temp 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

[-- Attachment #2: Type: text/plain, Size: 511 bytes --]

___________________________________________________________________________________
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
___________________________________________________________________________________

  parent reply	other threads:[~2023-10-25 19:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <990d094b-4733-492b-83f2-8014d51658c5@Spark>
2023-10-25 15:45 ` [NTG-context] " Alexandre Christe
2023-10-25 19:17   ` [NTG-context] " Bruce Horrocks
2023-10-25 19:52   ` Aditya Mahajan [this message]
2023-10-26  9:21     ` Alexandre Christe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=858p6424-2683-9873-944r-08ronp9549os@hzvpu.rqh \
    --to=adityam@umich.edu \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).