ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Jeroen <contextntg@gmail.com>
To: ntg-context@ntg.nl
Subject: [NTG-context] Re: Status of Asymptote
Date: Wed, 3 Jan 2024 12:39:19 +0100	[thread overview]
Message-ID: <25b373a6-9415-4b47-b644-7dde129a268e@gmail.com> (raw)
In-Reply-To: <511q1rpp-2494-751o-o807-0p87ns24q4po@hzvpu.rqh>

Below is how I have used Asymptote in the past with the Context filter 
module:

download portable ghostsctipt
create dir c:\context\ghostscript and install from 
https://portableapps.com/apps/utilities/ghostscript_portable

download non-portable asymptote
create dir c:\context\asymptote and install from 
http://asymptote.sourceforge.net/

create file c:\context\asy.bat with context
ASYMPTOTE_GS=C:context/ghostscript/bin/gswin64.exe
C:/context/asymptote/asy.exe %*

test with:

\usemodule[filter]

\defineexternalfilter[ASY]
    [filter={/context/asy.bat -tex context -outformat pdf
     -outname \externalfilteroutputfile},
     output=\externalfilterbasefile.pdf,
     cache=yes,
     readcommand=\ReadImage,]

\define[1]\ReadImage{\externalfigure[#1]}

\starttext
    Testing if we can include an asymptote image
    \startplacefigure[location={here}, title={An Asymptote figure}]
      \startASY
        size(10cm);
        import graph;
        real f(real x) {return sin(x);}
        draw(graph(f,-3,3,300),blue);
      \stopASY
    \stopplacefigure
\stoptext


OR alternatively:


\usemodule[filter]

\defineexternalfilter[ASY]
    [filter={/context/asy.bat -tex context -outformat pdf
     -outname \externalfilteroutputfile},
     output=\externalfilterbasefile.pdf,
     cache=yes,
     readcommand=\ReadImage,]

\define[1]\ReadImage{\externalfigure[#1]}

\starttext
    Testing if we can include an asymptote image
    \startplacefigure[location={here}, title={An Asymptote figure}]
      \startASY
        unitsize(1cm);
        draw((-.1,0) -- (2,0), arrow=Arrow(TeXHead));
        draw((0,-.1) -- (0,2), arrow=Arrow(TeXHead));
        draw((0,0) .. (1,1) .. (2,sqrt(2)));
      \stopASY
    \stopplacefigure
\stoptext

Op 31/12/2023 om 00:33 schreef Aditya Mahajan:
> On Sun, 31 Dec 2023, Shiv Shankar Dayal wrote:
>
>> It would be nice to either support Metapost 3D or Asymptote. Right now I
>> generate images separately and embed them in PDF using externalfigure command which works but I have to maintain all the graphics separately.
> It is possible to obtain simple integration for asymptote using the filter module:
>
>    https://github.com/adityam/filter
>
> Using that you could define an asymptote environment so that:
>
> \startbuffer[asymptote-preamble]
> ....
> \stopbuffer
>
> \starttext
>
> \startasymptote
> % Asymptote figure
> \stopasymptote
>
> \stoptext
>
> saves the content of the asymptote-preamble and the figure in a separate file, runs asymptote to generate a PDF figure and includes the figure. The results are cached so the asymptote is re-run only if the content of the figure environment changes.
>
> A drawback of this approach is that the labels are generated by asymptote. That means that the font, colors, and any macros needed for the figures need to be redefined at both context and asymptote end.
>
> Aditya
> ___________________________________________________________________________________
> 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
> ___________________________________________________________________________________
___________________________________________________________________________________
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
___________________________________________________________________________________

  reply	other threads:[~2024-01-03 11:44 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-06  8:43 Alexandre Christe via ntg-context
2021-12-06 15:11 ` Gavin via ntg-context
2021-12-06 17:33   ` Fabrice L via ntg-context
2021-12-07  6:29 ` Aditya Mahajan via ntg-context
2021-12-07  8:42   ` Hans Hagen via ntg-context
2023-12-30 19:04     ` [NTG-context] " Shiv Shankar Dayal
2023-12-30 20:33       ` Gavin via ntg-context
2023-12-30 20:44       ` Alan Braslau via ntg-context
2023-12-30 21:48       ` Hans Hagen
2023-12-30 23:33       ` Aditya Mahajan
2024-01-03 11:39         ` Jeroen [this message]
2024-01-11  6:00           ` shivshankar.dayal

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=25b373a6-9415-4b47-b644-7dde129a268e@gmail.com \
    --to=contextntg@gmail.com \
    --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).