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 ___________________________________________________________________________________