ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Asymptote or Metapost and ConTeXt parameters.
@ 2016-12-19  7:41 Jaroslav Hajtmar
  2016-12-19  9:10 ` Fabrice Couvreur
  2016-12-19 16:19 ` Aditya Mahajan
  0 siblings, 2 replies; 16+ messages in thread
From: Jaroslav Hajtmar @ 2016-12-19  7:41 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 825 bytes --]

Hello ConTeXtist,
I saw the opportunity to insert an Asymptote picture into Context source code (due filter).
For example here: https://mailman.ntg.nl/pipermail/ntg-context/2015/080581.html

Is there a way to pass the ConTeXt parameter which influenced the creation of the Asymptote image? My point eg. the ability to define macros, which gave its parameters to Asymptote procedure or function and depending on these parameters, the image created by Asymptote looked differently.

Before starting work on an illustrative example I am asking, whether it makes sense to deal with such a thing ... I suppose the impossibility of combining asymptote code and such Lua code (or not?).

There is a similar possibility, at least in Metapost? For simpler pictures it would probably suffice ....

Thanx
Jaroslav Hajtmar


[-- Attachment #1.2: Type: text/html, Size: 3404 bytes --]

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

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Asymptote or Metapost and ConTeXt parameters.
  2016-12-19  7:41 Asymptote or Metapost and ConTeXt parameters Jaroslav Hajtmar
@ 2016-12-19  9:10 ` Fabrice Couvreur
  2016-12-19  9:43   ` Hans Hagen
  2016-12-19 16:19 ` Aditya Mahajan
  1 sibling, 1 reply; 16+ messages in thread
From: Fabrice Couvreur @ 2016-12-19  9:10 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 2456 bytes --]

Hello,
I do not answer the question, but I'm interested because I also use
Asymptote. The following code works with context in texlive 2016 but does
not work with standalone context.
thank you,
Fabrice
% macros=mkvi

\usemodule[filter]

\defineexternalfilter
   [ASY]
   [
     filter={asy -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
       import three;
size(8cm,0);
currentlight.background=black;

material White(real x, real y){
   return material(diffusepen=gray(.05+.1x+.3y),
                   emissivepen=gray(.05+.1x+.3y));
}

for(int y=0; y<=2; ++y)
    for(int x=0; x<3; ++x)
        draw(shift(2x,2y,0)*unitsphere,White(x,y));
     \stopASY
   \stopplacefigure
\stoptext


2016-12-19 8:41 GMT+01:00 Jaroslav Hajtmar <hajtmar@gyza.cz>:

> Hello ConTeXtist,
>
> I saw the opportunity to insert an Asymptote picture into Context source
> code (due filter).
>
> For example here: https://mailman.ntg.nl/pipermail/ntg-context/2015/
> 080581.html
>
>
>
> Is there a way to pass the ConTeXt parameter which influenced the creation
> of the Asymptote image? My point eg. the ability to define macros, which
> gave its parameters to Asymptote procedure or function and depending on
> these parameters, the image created by Asymptote looked differently.
>
>
>
> Before starting work on an illustrative example I am asking, whether it
> makes sense to deal with such a thing ... I suppose the impossibility of
> combining asymptote code and such Lua code (or not?).
>
>
>
> There is a similar possibility, at least in Metapost? For simpler pictures
> it would probably suffice ....
>
>
>
> Thanx
>
> Jaroslav Hajtmar
>
>
>
> ____________________________________________________________
> _______________________
> If your question is of interest to others as well, please add an entry to
> the Wiki!
>
> maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/
> listinfo/ntg-context
> webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
> archive  : https://bitbucket.org/phg/context-mirror/commits/
> wiki     : http://contextgarden.net
> ____________________________________________________________
> _______________________
>

[-- Attachment #1.2: Type: text/html, Size: 4982 bytes --]

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

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Asymptote or Metapost and ConTeXt parameters.
  2016-12-19  9:10 ` Fabrice Couvreur
@ 2016-12-19  9:43   ` Hans Hagen
  0 siblings, 0 replies; 16+ messages in thread
From: Hans Hagen @ 2016-12-19  9:43 UTC (permalink / raw)
  To: ntg-context

On 12/19/2016 10:10 AM, Fabrice Couvreur wrote:
> Hello,
> I do not answer the question, but I'm interested because I also use
> Asymptote. The following code works with context in texlive 2016 but
> does not work with standalone context.
> thank you,

it probably depends on what you want to pass as info (i don't have 
asymptote installed nor time to check it) but if the code you pass gets 
expanded then you can add expandable macros or \the\foo kind of code to it

Hans

> Fabrice
> % macros=mkvi
>
> \usemodule[filter]
>
> \defineexternalfilter
>    [ASY]
>    [
>      filter={asy -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
>        import three;
> size(8cm,0);
> currentlight.background=black;
>
> material White(real x, real y){
>    return material(diffusepen=gray(.05+.1x+.3y),
>                    emissivepen=gray(.05+.1x+.3y));
> }
>
> for(int y=0; y<=2; ++y)
>     for(int x=0; x<3; ++x)
>         draw(shift(2x,2y,0)*unitsphere,White(x,y));
>      \stopASY
>    \stopplacefigure
> \stoptext
>
>
> 2016-12-19 8:41 GMT+01:00 Jaroslav Hajtmar <hajtmar@gyza.cz
> <mailto:hajtmar@gyza.cz>>:
>
>     Hello ConTeXtist,____
>
>     I saw the opportunity to insert an Asymptote picture into Context
>     source code (due filter).____
>
>     For example here:
>     https://mailman.ntg.nl/pipermail/ntg-context/2015/080581.html
>     <https://mailman.ntg.nl/pipermail/ntg-context/2015/080581.html>____
>
>     __ __
>
>     Is there a way to pass the ConTeXt parameter which influenced the
>     creation of the Asymptote image? My point eg. the ability to define
>     macros, which gave its parameters to Asymptote procedure or function
>     and depending on these parameters, the image created by Asymptote
>     looked differently.____
>
>     __ __
>
>     Before starting work on an illustrative example I am asking, whether
>     it makes sense to deal with such a thing ... I suppose the
>     impossibility of combining asymptote code and such Lua code (or
>     not?).____
>
>     __ __
>
>     There is a similar possibility, at least in Metapost? For simpler
>     pictures it would probably suffice ....____
>
>     __ __
>
>     Thanx ____
>
>     Jaroslav Hajtmar____
>
>     __ __
>
>
>     ___________________________________________________________________________________
>     If your question is of interest to others as well, please add an
>     entry to the Wiki!
>
>     maillist : ntg-context@ntg.nl <mailto:ntg-context@ntg.nl> /
>     http://www.ntg.nl/mailman/listinfo/ntg-context
>     <http://www.ntg.nl/mailman/listinfo/ntg-context>
>     webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
>     archive  : https://bitbucket.org/phg/context-mirror/commits/
>     <https://bitbucket.org/phg/context-mirror/commits/>
>     wiki     : http://contextgarden.net
>     ___________________________________________________________________________________
>
>
>
>
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to the Wiki!
>
> maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
> webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
> archive  : https://bitbucket.org/phg/context-mirror/commits/
> wiki     : http://contextgarden.net
> ___________________________________________________________________________________
>


-- 

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Asymptote or Metapost and ConTeXt parameters.
  2016-12-19  7:41 Asymptote or Metapost and ConTeXt parameters Jaroslav Hajtmar
  2016-12-19  9:10 ` Fabrice Couvreur
@ 2016-12-19 16:19 ` Aditya Mahajan
  2016-12-20 10:34   ` Jaroslav Hajtmar
  2016-12-20 22:14   ` Alan Braslau
  1 sibling, 2 replies; 16+ messages in thread
From: Aditya Mahajan @ 2016-12-19 16:19 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Mon, 19 Dec 2016, Jaroslav Hajtmar wrote:

> There is a similar possibility, at least in Metapost? For simpler 
> pictures it would probably suffice ....

The ability to pass parameters to metapost has been around since the 
beginning. See the metafun manual for details (search for MPvar). For 
simple images, you can also do:

\define[1]\Circle{\startMPcode draw fullcircle scaled #1*cm; \stopMPcode}

\Circle{1} \Circle{2} \Circle{3}

> Is there a way to pass the ConTeXt parameter which influenced the 
> creation of the Asymptote image? My point eg. the ability to define 
> macros, which gave its parameters to Asymptote procedure or function and 
> depending on these parameters, the image created by Asymptote looked 
> differently.

In principle, something similar to \MPvar can work for asymptote as well 
(or one could do parse the content in Lua rather than expand variables in 
TeX).

> Before starting work on an illustrative example I am asking, whether it 
> makes sense to deal with such a thing ... I suppose the impossibility of 
> combining asymptote code and such Lua code (or not?).

ConTeXt and Metapost are very well integrated, even in MkII. The same 
ideas could work with other graphic backends as well (Asymptote, tikz, and 
others). But it does require a good knowledge of the graphics package.

I am willing to write the code at the context end, if someone who knows 
asymptote can tell me what needs to be done at the 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 / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Asymptote or Metapost and ConTeXt parameters.
  2016-12-19 16:19 ` Aditya Mahajan
@ 2016-12-20 10:34   ` Jaroslav Hajtmar
  2016-12-22  4:49     ` Aditya Mahajan
  2016-12-20 22:14   ` Alan Braslau
  1 sibling, 1 reply; 16+ messages in thread
From: Jaroslav Hajtmar @ 2016-12-20 10:34 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Thanx Aditya 
very much for your Metapost example. This I certainly sufficient for the production of simple images for my ideas. I attach source code, which outlines how I imagined inserting Asymptote images into Context. In the lower part of commented code is fully functional, compiled ConTEXt of TeX Live 2016 (included in the package is also Asymptote). My idea is that Asymptote code is part of my ConTeXt macro and parameters of macro are passed into Asymptote. My example does not work because Asymptote is probably not enough linked with Context. I am very grateful that You would to deal with my problem. 

I am not sure whether it will do Asymptote example as in the case Metapost. That's why I use  filter in my own example (taken from https://mailman.ntg.nl/pipermail/ntg-context/2015/080581.html ).


Thank you once again.

Jaroslav Hajtmar



\usemodule[filter]

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

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

\define[1]\mycircle{
	\startASY
	import graph;
	draw(Circle((0,0),#1));
	\stopASY
}

\starttext
\mycircle{20}
\mycircle{30}
\mycircle{40}
\stoptext


%% simple asymptote example (compiled ConTeXt (LuaTeX) from TeX Live 2016)
%
%\usemodule[filter]
%
%\defineexternalfilter
%   [ASY]
%   [
%     filter={asy -tex "context" -outformat pdf
%             -outname \externalfilteroutputfile},
%     output=\externalfilterbasefile.pdf,
%     cache=yes,
%     readcommand=\ReadImage,
%   ]
%
%\define[1]\ReadImage{\externalfigure[#1]}
%
%\starttext
%\startASY
%import graph;
%draw(Circle((0,0),20));
%\stopASY
%\stoptext


Dne 19.12.16 17:19, ntg-context za uživatele Aditya Mahajan <ntg-context-bounces@ntg.nl za uživatele adityam@umich.edu> napsal(a):

    On Mon, 19 Dec 2016, Jaroslav Hajtmar wrote:
    
    > There is a similar possibility, at least in Metapost? For simpler 
    > pictures it would probably suffice ....
    
    The ability to pass parameters to metapost has been around since the 
    beginning. See the metafun manual for details (search for MPvar). For 
    simple images, you can also do:
    
    \define[1]\Circle{\startMPcode draw fullcircle scaled #1*cm; \stopMPcode}
    
    \Circle{1} \Circle{2} \Circle{3}
    
    > Is there a way to pass the ConTeXt parameter which influenced the 
    > creation of the Asymptote image? My point eg. the ability to define 
    > macros, which gave its parameters to Asymptote procedure or function and 
    > depending on these parameters, the image created by Asymptote looked 
    > differently.
    
    In principle, something similar to \MPvar can work for asymptote as well 
    (or one could do parse the content in Lua rather than expand variables in 
    TeX).
    
    > Before starting work on an illustrative example I am asking, whether it 
    > makes sense to deal with such a thing ... I suppose the impossibility of 
    > combining asymptote code and such Lua code (or not?).
    
    ConTeXt and Metapost are very well integrated, even in MkII. The same 
    ideas could work with other graphic backends as well (Asymptote, tikz, and 
    others). But it does require a good knowledge of the graphics package.
    
    I am willing to write the code at the context end, if someone who knows 
    asymptote can tell me what needs to be done at the 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 / http://www.ntg.nl/mailman/listinfo/ntg-context
    webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
    archive  : https://bitbucket.org/phg/context-mirror/commits/
    wiki     : http://contextgarden.net
    ___________________________________________________________________________________

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Asymptote or Metapost and ConTeXt parameters.
  2016-12-19 16:19 ` Aditya Mahajan
  2016-12-20 10:34   ` Jaroslav Hajtmar
@ 2016-12-20 22:14   ` Alan Braslau
  2016-12-21  7:49     ` Aditya Mahajan
  2017-03-19 18:01     ` Passing data back and forth between metapost and lua Aditya Mahajan
  1 sibling, 2 replies; 16+ messages in thread
From: Alan Braslau @ 2016-12-20 22:14 UTC (permalink / raw)
  To: Aditya Mahajan; +Cc: mailing list for ConTeXt users

On Mon, 19 Dec 2016 08:19:25 -0800
Aditya Mahajan <adityam@umich.edu> wrote:

> The ability to pass parameters to metapost has been around since the 
> beginning. See the metafun manual for details (search for MPvar).

Hans has developed tools making it quite easy to pass data back and
forth between MetaPost and lua. This is quite efficient, and it is
being used more and more in the development of macro functionality.

Alan
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Asymptote or Metapost and ConTeXt parameters.
  2016-12-20 22:14   ` Alan Braslau
@ 2016-12-21  7:49     ` Aditya Mahajan
  2017-03-19 18:01     ` Passing data back and forth between metapost and lua Aditya Mahajan
  1 sibling, 0 replies; 16+ messages in thread
From: Aditya Mahajan @ 2016-12-21  7:49 UTC (permalink / raw)
  To: Alan Braslau; +Cc: mailing list for ConTeXt users

On Tue, 20 Dec 2016, Alan Braslau wrote:

> On Mon, 19 Dec 2016 08:19:25 -0800
> Aditya Mahajan <adityam@umich.edu> wrote:
>
>> The ability to pass parameters to metapost has been around since the
>> beginning. See the metafun manual for details (search for MPvar).
>
> Hans has developed tools making it quite easy to pass data back and
> forth between MetaPost and lua. This is quite efficient, and it is
> being used more and more in the development of macro functionality.

Thanks. It has been a few years since I read the ConTeXt+MP related part 
of the source. I'll look again to see how MP-Lua interface is developed.

Aditya
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Asymptote or Metapost and ConTeXt parameters.
  2016-12-20 10:34   ` Jaroslav Hajtmar
@ 2016-12-22  4:49     ` Aditya Mahajan
  2016-12-23  8:02       ` Jaroslav Hajtmar
  0 siblings, 1 reply; 16+ messages in thread
From: Aditya Mahajan @ 2016-12-22  4:49 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Tue, 20 Dec 2016, Jaroslav Hajtmar wrote:

> very much for your Metapost example. This I certainly sufficient for the 
> production of simple images for my ideas.

> \define[1]\mycircle{
> 	\startASY
> 	import graph;
> 	draw(Circle((0,0),#1));
> 	\stopASY
> }
>
> \starttext
> \mycircle{20}
> \mycircle{30}
> \mycircle{40}
> \stoptext

It is already feasible to define something this simple using the filter 
module. I don't have asymptote installed on the machine that I am 
currently working on, but here is an example that uses pandoc.

\usemodule[filter]

\defineexternalfilter
     [MARKDOWN]
     [
       filtercommand={pandoc -f markdown -t context \externalfilterinputfile\space -o \externalfilteroutputfile},
       cache=yes,
       purge=no, % Just for testing. May be removed.
     ]

\define[1]\TEST
     {\setbuffer[MARKDOWN]This is #1\endbuffer
      \processMARKDOWNbuffer[MARKDOWN]}

\starttext
\startMARKDOWN
   This is **one**
\stopMARKDOWN

\TEST{**ONE**}

\TEST{_TWO_}
\stoptext

With this method, the results are not cached. Let me know if this works 
for your needs.

Aditya
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Asymptote or Metapost and ConTeXt parameters.
  2016-12-22  4:49     ` Aditya Mahajan
@ 2016-12-23  8:02       ` Jaroslav Hajtmar
  2016-12-23 19:22         ` Aditya Mahajan
  0 siblings, 1 reply; 16+ messages in thread
From: Jaroslav Hajtmar @ 2016-12-23  8:02 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Hello Adytia.
Thanks for sending Your code. It seems that it works with Asymptote. Unfortunately, when I am trying to multiple call a macro then I get fatal error, and then compile collapse. I do not know what it could be. Is it possible that my code is wrong. But it is possible that there is a stack overflow etc. It would be a need to look at why the fatal error occurs - It probably can evaluate Hans. Thanks again for your support. Below is my code. If removed commentary characters occurs advised error.

Jaroslav Hajtmar


\usemodule[filter]

\defineexternalfilter
   [ASY]
   [
     filtercommand={asy -tex context \externalfilterinputfile\space -o \externalfilteroutputfile}, output=\externalfilterbasefile.pdf,
     purge=no, 
     cache=yes,
     readcommand=\ReadImage,
   ]

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

\define[1]\mycircle{
#1 - XXX
\setbuffer[ASY]
	import graph;
	draw(Circle((0,0),#1));
\endbuffer
\processASYbuffer[ASY]
}

\starttext
AAA
\startASY
	import graph;
	draw((0,0)--(100,100));
\stopASY

BBB
\mycircle{100}


%CCC
%\mycircle{50}

%DDD
%\mycircle{200}

\stoptext





Dne 22.12.16 5:49, ntg-context za uživatele Aditya Mahajan <ntg-context-bounces@ntg.nl za uživatele adityam@umich.edu> napsal(a):

    On Tue, 20 Dec 2016, Jaroslav Hajtmar wrote:
    
    > very much for your Metapost example. This I certainly sufficient for the 
    > production of simple images for my ideas.
    
    > \define[1]\mycircle{
    > 	\startASY
    > 	import graph;
    > 	draw(Circle((0,0),#1));
    > 	\stopASY
    > }
    >
    > \starttext
    > \mycircle{20}
    > \mycircle{30}
    > \mycircle{40}
    > \stoptext
    
    It is already feasible to define something this simple using the filter 
    module. I don't have asymptote installed on the machine that I am 
    currently working on, but here is an example that uses pandoc.
    
    \usemodule[filter]
    
    \defineexternalfilter
         [MARKDOWN]
         [
           filtercommand={pandoc -f markdown -t context \externalfilterinputfile\space -o \externalfilteroutputfile},
           cache=yes,
           purge=no, % Just for testing. May be removed.
         ]
    
    \define[1]\TEST
         {\setbuffer[MARKDOWN]This is #1\endbuffer
          \processMARKDOWNbuffer[MARKDOWN]}
    
    \starttext
    \startMARKDOWN
       This is **one**
    \stopMARKDOWN
    
    \TEST{**ONE**}
    
    \TEST{_TWO_}
    \stoptext
    
    With this method, the results are not cached. Let me know if this works 
    for your needs.
    
    Aditya
    ___________________________________________________________________________________
    If your question is of interest to others as well, please add an entry to the Wiki!
    
    maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
    webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
    archive  : https://bitbucket.org/phg/context-mirror/commits/
    wiki     : http://contextgarden.net
    ___________________________________________________________________________________

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Asymptote or Metapost and ConTeXt parameters.
  2016-12-23  8:02       ` Jaroslav Hajtmar
@ 2016-12-23 19:22         ` Aditya Mahajan
  2016-12-23 20:28           ` Hans Hagen
  2016-12-24  2:55           ` Jaroslav Hajtmar
  0 siblings, 2 replies; 16+ messages in thread
From: Aditya Mahajan @ 2016-12-23 19:22 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Fri, 23 Dec 2016, Jaroslav Hajtmar wrote:

> Thanks for sending Your code. It seems that it works with Asymptote. 
> Unfortunately, when I am trying to multiple call a macro then I get 
> fatal error, and then compile collapse. I do not know what it could be.

When called for the first time, the code generates test-ASY.pdf file and 
includes it. After the second call, a new test-ASY.pdf is generated. 
ConTeXt generates an error because the name of the files is the same, but 
the content is not.

There should be an option for \externalfigure to disable this check, but I 
couldn't find it. Here is an alternative approach, that changes the name 
of the PDF.

\usemodule[filter]

\unprotect
\appendtoks
   \setuevalue{set\currentexternalfilter buffer}{\externalfilter@set[\currentexternalfilter]}%
\to \everydefineexternalfilter

\unexpanded\def\externalfilter@set
   {\dodoubleargument\externalfiter@set_indeed}

\starttexdefinition externalfiter@set_indeed [#1][#2]#3
    % #1 = filter
    % #2 = options

    \begingroup
    \edef\currentexternalfilter{#1}

    \setupexternalfilter[#1][\c!name=,#2]

    \externalfilter@set_filenames
    \setbuffer[\externalfilter@buffer_name]#3\endbuffer

    \externalfilter@process_filter
  \stoptexdefinition
\protect

\defineexternalfilter
     [MARKDOWN]
     [
       filtercommand={pandoc -f markdown -t context \externalfilterinputfile\space -o \externalfilteroutputfile},
       cache=yes,
       purge=no,
     ]

\define[1]\NEW
     {\setMARKDOWNbuffer{This is #1}}

\traceexternalfilters

\starttext
\startMARKDOWN
   This is **one**
\stopMARKDOWN

\NEW{**ONE**}

\NEW{_TWO_}
\stoptext

Note that this has the same limitation as using \type{...}. The contents of
\NEW{...} must have matched braces. If this works, I can include the code in
t-filter (mkiv only, as I no longer want to maintain the mkii branch).

Aditya
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Asymptote or Metapost and ConTeXt parameters.
  2016-12-23 19:22         ` Aditya Mahajan
@ 2016-12-23 20:28           ` Hans Hagen
  2016-12-24  2:55           ` Jaroslav Hajtmar
  1 sibling, 0 replies; 16+ messages in thread
From: Hans Hagen @ 2016-12-23 20:28 UTC (permalink / raw)
  To: ntg-context

On 12/23/2016 8:22 PM, Aditya Mahajan wrote:
> On Fri, 23 Dec 2016, Jaroslav Hajtmar wrote:
>
>> Thanks for sending Your code. It seems that it works with Asymptote.
>> Unfortunately, when I am trying to multiple call a macro then I get
>> fatal error, and then compile collapse. I do not know what it could be.
>
> When called for the first time, the code generates test-ASY.pdf file and
> includes it. After the second call, a new test-ASY.pdf is generated.
> ConTeXt generates an error because the name of the files is the same,
> but the content is not.
>
> There should be an option for \externalfigure to disable this check, but
> I couldn't find it. Here is an alternative approach, that changes the
> name of the PDF.

object=no should work but even then, the backend can keep files open and 
flush later

Hans



-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Asymptote or Metapost and ConTeXt parameters.
  2016-12-23 19:22         ` Aditya Mahajan
  2016-12-23 20:28           ` Hans Hagen
@ 2016-12-24  2:55           ` Jaroslav Hajtmar
  2016-12-24  3:05             ` Aditya Mahajan
  1 sibling, 1 reply; 16+ messages in thread
From: Jaroslav Hajtmar @ 2016-12-24  2:55 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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

Hello Adytia.
It seems now, that everything at this time works as intended. Many thanks for your support. Below is a minimal example. Attached is a PDF sample result.
I tried also to experiment with the choice "object = no", as suggested by Hans, but without success. I would asking  if you make any changes in filter module?
Or have I misunderstood Your opinion? 
Thank you once again
Jaroslav Hajtmar


Here is minimal example:

\usemodule[filter]

\unprotect
\appendtoks
   \setuevalue{set\currentexternalfilter buffer}{\externalfilter@set[\currentexternalfilter]}%
\to \everydefineexternalfilter

\unexpanded\def\externalfilter@set
   {\dodoubleargument\externalfiter@set_indeed}

\starttexdefinition externalfiter@set_indeed [#1][#2]#3
    % #1 = filter
    % #2 = options

    \begingroup
    \edef\currentexternalfilter{#1}

    \setupexternalfilter[#1][\c!name=,#2]

    \externalfilter@set_filenames
    \setbuffer[\externalfilter@buffer_name]#3\endbuffer

    \externalfilter@process_filter
  \stoptexdefinition
\protect

\defineexternalfilter
   [ASY]
   [
     filtercommand={asy -tex context \externalfilterinputfile\space -o \externalfilteroutputfile}, output=\externalfilterbasefile.pdf,
     purge=no, 
     cache=yes,
     readcommand=\ReadImage,
   ]

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

\define[1]\mycircle{
\setASYbuffer{
	import graph;
	draw(Circle((0,0),#1));
}}


\starttext

\startASY
 import graph;
 draw((0,0)--(100,100));
\stopASY

\mycircle{10}

\mycircle{20}

\mycircle{30}

\stoptext







Dne 23.12.16 20:22, ntg-context za uživatele Aditya Mahajan <ntg-context-bounces@ntg.nl za uživatele adityam@umich.edu> napsal(a):

    On Fri, 23 Dec 2016, Jaroslav Hajtmar wrote:
    
    > Thanks for sending Your code. It seems that it works with Asymptote. 
    > Unfortunately, when I am trying to multiple call a macro then I get 
    > fatal error, and then compile collapse. I do not know what it could be.
    
    When called for the first time, the code generates test-ASY.pdf file and 
    includes it. After the second call, a new test-ASY.pdf is generated. 
    ConTeXt generates an error because the name of the files is the same, but 
    the content is not.
    
    There should be an option for \externalfigure to disable this check, but I 
    couldn't find it. Here is an alternative approach, that changes the name 
    of the PDF.
    
    \usemodule[filter]
    
    \unprotect
    \appendtoks
       \setuevalue{set\currentexternalfilter buffer}{\externalfilter@set[\currentexternalfilter]}%
    \to \everydefineexternalfilter
    
    \unexpanded\def\externalfilter@set
       {\dodoubleargument\externalfiter@set_indeed}
    
    \starttexdefinition externalfiter@set_indeed [#1][#2]#3
        % #1 = filter
        % #2 = options
    
        \begingroup
        \edef\currentexternalfilter{#1}
    
        \setupexternalfilter[#1][\c!name=,#2]
    
        \externalfilter@set_filenames
        \setbuffer[\externalfilter@buffer_name]#3\endbuffer
    
        \externalfilter@process_filter
      \stoptexdefinition
    \protect
    
    \defineexternalfilter
         [MARKDOWN]
         [
           filtercommand={pandoc -f markdown -t context \externalfilterinputfile\space -o \externalfilteroutputfile},
           cache=yes,
           purge=no,
         ]
    
    \define[1]\NEW
         {\setMARKDOWNbuffer{This is #1}}
    
    \traceexternalfilters
    
    \starttext
    \startMARKDOWN
       This is **one**
    \stopMARKDOWN
    
    \NEW{**ONE**}
    
    \NEW{_TWO_}
    \stoptext
    
    Note that this has the same limitation as using \type{...}. The contents of
    \NEW{...} must have matched braces. If this works, I can include the code in
    t-filter (mkiv only, as I no longer want to maintain the mkii branch).
    
    Aditya
    ___________________________________________________________________________________
    If your question is of interest to others as well, please add an entry to the Wiki!
    
    maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
    webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
    archive  : https://bitbucket.org/phg/context-mirror/commits/
    wiki     : http://contextgarden.net
    ___________________________________________________________________________________


[-- Attachment #2: AsymptoteCodeInConTeXt03a-Adytia.pdf --]
[-- Type: application/pdf, Size: 25307 bytes --]

[-- Attachment #3: Type: text/plain, Size: 492 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Asymptote or Metapost and ConTeXt parameters.
  2016-12-24  2:55           ` Jaroslav Hajtmar
@ 2016-12-24  3:05             ` Aditya Mahajan
  0 siblings, 0 replies; 16+ messages in thread
From: Aditya Mahajan @ 2016-12-24  3:05 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Sat, 24 Dec 2016, Jaroslav Hajtmar wrote:

> It seems now, that everything at this time works as intended. Many 
> thanks for your support. Below is a minimal example. Attached is a PDF 
> sample result.

Nice to know that it works.

> I tried also to experiment with the choice "object = no", as suggested 
> by Hans, but without success.

Note that it is "object=no" (without spaces around equal to)

> I would asking if you make any changes in filter module?
> Or have I misunderstood Your opinion?

I will add the code between \unprotect ... \protect to the filter module after
I have tested it a bit more thoroughly.

Aditya
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Passing data back and forth between metapost and lua
  2016-12-20 22:14   ` Alan Braslau
  2016-12-21  7:49     ` Aditya Mahajan
@ 2017-03-19 18:01     ` Aditya Mahajan
  2017-03-19 18:29       ` Aditya Mahajan
  1 sibling, 1 reply; 16+ messages in thread
From: Aditya Mahajan @ 2017-03-19 18:01 UTC (permalink / raw)
  To: Alan Braslau; +Cc: mailing list for ConTeXt users

On Tue, 20 Dec 2016, Alan Braslau wrote:

> On Mon, 19 Dec 2016 08:19:25 -0800
> Aditya Mahajan <adityam@umich.edu> wrote:
>
>> The ability to pass parameters to metapost has been around since the
>> beginning. See the metafun manual for details (search for MPvar).
>
> Hans has developed tools making it quite easy to pass data back and
> forth between MetaPost and lua. This is quite efficient, and it is
> being used more and more in the development of macro functionality.

I finally need to write a macro where I want to pass data from lua to 
metapost. I could not find an example in the source code showing this. 
Can someone show a basic example of how lua-metapost interface works or 
point me to the appropriate files in the source.

Thanks,
Aditya
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Passing data back and forth between metapost and lua
  2017-03-19 18:01     ` Passing data back and forth between metapost and lua Aditya Mahajan
@ 2017-03-19 18:29       ` Aditya Mahajan
  2017-03-19 19:02         ` Hans Hagen
  0 siblings, 1 reply; 16+ messages in thread
From: Aditya Mahajan @ 2017-03-19 18:29 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Sun, 19 Mar 2017, Aditya Mahajan wrote:

> On Tue, 20 Dec 2016, Alan Braslau wrote:
>
>> On Mon, 19 Dec 2016 08:19:25 -0800
>> Aditya Mahajan <adityam@umich.edu> wrote:
>>
>>> The ability to pass parameters to metapost has been around since the
>>> beginning. See the metafun manual for details (search for MPvar).
>>
>> Hans has developed tools making it quite easy to pass data back and
>> forth between MetaPost and lua. This is quite efficient, and it is
>> being used more and more in the development of macro functionality.
>
> I finally need to write a macro where I want to pass data from lua to 
> metapost. I could not find an example in the source code showing this. 
> Can someone show a basic example of how lua-metapost interface works or 
> point me to the appropriate files in the source.

Found some information in the CLD manual. That is sufficient for the 
task at hand for me. But a pointer to a more detailed source will be 
welcome.

Aditya
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Passing data back and forth between metapost and lua
  2017-03-19 18:29       ` Aditya Mahajan
@ 2017-03-19 19:02         ` Hans Hagen
  0 siblings, 0 replies; 16+ messages in thread
From: Hans Hagen @ 2017-03-19 19:02 UTC (permalink / raw)
  To: ntg-context

On 3/19/2017 7:29 PM, Aditya Mahajan wrote:
> On Sun, 19 Mar 2017, Aditya Mahajan wrote:
>
>> On Tue, 20 Dec 2016, Alan Braslau wrote:
>>
>>> On Mon, 19 Dec 2016 08:19:25 -0800
>>> Aditya Mahajan <adityam@umich.edu> wrote:
>>>
>>>> The ability to pass parameters to metapost has been around since the
>>>> beginning. See the metafun manual for details (search for MPvar).
>>>
>>> Hans has developed tools making it quite easy to pass data back and
>>> forth between MetaPost and lua. This is quite efficient, and it is
>>> being used more and more in the development of macro functionality.
>>
>> I finally need to write a macro where I want to pass data from lua to
>> metapost. I could not find an example in the source code showing this.
>> Can someone show a basic example of how lua-metapost interface works
>> or point me to the appropriate files in the source.
>
> Found some information in the CLD manual. That is sufficient for the
> task at hand for me. But a pointer to a more detailed source will be
> welcome.

real low level

\starttext

\startluacode

     document.mydata = { foo = "foo", bar = 123 }

\stopluacode

\startMPcode

     draw fullcircle scaled lua("mp.print(document.mydata.bar)") ;
     draw textext (lua("mp.quoted(document.mydata.foo)")) ;

\stopMPcode

\stoptext

i'll mail you the new chapter in the metafun manual

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2017-03-19 19:02 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-19  7:41 Asymptote or Metapost and ConTeXt parameters Jaroslav Hajtmar
2016-12-19  9:10 ` Fabrice Couvreur
2016-12-19  9:43   ` Hans Hagen
2016-12-19 16:19 ` Aditya Mahajan
2016-12-20 10:34   ` Jaroslav Hajtmar
2016-12-22  4:49     ` Aditya Mahajan
2016-12-23  8:02       ` Jaroslav Hajtmar
2016-12-23 19:22         ` Aditya Mahajan
2016-12-23 20:28           ` Hans Hagen
2016-12-24  2:55           ` Jaroslav Hajtmar
2016-12-24  3:05             ` Aditya Mahajan
2016-12-20 22:14   ` Alan Braslau
2016-12-21  7:49     ` Aditya Mahajan
2017-03-19 18:01     ` Passing data back and forth between metapost and lua Aditya Mahajan
2017-03-19 18:29       ` Aditya Mahajan
2017-03-19 19:02         ` Hans Hagen

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).