ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Asymptote in Context
@ 2014-12-07 17:50 context context
  0 siblings, 0 replies; 6+ messages in thread
From: context context @ 2014-12-07 17:50 UTC (permalink / raw)
  To: ntg-context


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

I have been trying to put Asymptote graphs in Context with the filter
example below. The Asymptote graph is written in a separate PDF file, but
is not included in the final completed PDF document. Is there a simple way
to achieve this?


\usemodule[filter]


\defineexternalfilter

[ASY]

[filtercommand={asy -tex "context" -View -outformat pdf -outname
\externalfilteroutputfile\space \externalfilterinputfile},

output=\externalfilterbasefile.out,

readcommand=\typefile,

cache=force,

location=text,

continue=yes]


\starttext

\startASY[myplot]

draw((1,1)--(2,4));

\stopASY


\externalfigure[myplot]

\stoptext


Thanks

Jeroen

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

[-- Attachment #2: Type: text/plain, Size: 485 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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: Asymptote in Context
  2015-01-02 22:14     ` Context NTG
@ 2015-01-20  3:39       ` Aditya Mahajan
  0 siblings, 0 replies; 6+ messages in thread
From: Aditya Mahajan @ 2015-01-20  3:39 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Fri, 2 Jan 2015, Context NTG wrote:

> Here is an Asymptote example
>
> 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)));
>
>
> Below is how I have started setting this up in Context. This creates a pdf
> file with the drawing, but it is not included in the final docuement.

Sorry for the late reply. You just need to change a few options:

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

Here \startASY behaves similar to \startMPcode. To get something similar 
to \startMPenvironment in mkii, you can use beforebuffer.

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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: Asymptote in Context
  2014-12-28 11:04   ` Mojca Miklavec
@ 2015-01-02 22:14     ` Context NTG
  2015-01-20  3:39       ` Aditya Mahajan
  0 siblings, 1 reply; 6+ messages in thread
From: Context NTG @ 2015-01-02 22:14 UTC (permalink / raw)
  To: mailing list for ConTeXt users


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

Here is an Asymptote example

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


Below is how I have started setting this up in Context. This creates a pdf
file with the drawing, but it is not included in the final docuement.


\defineexternalfilter
[ASY]
[filtercommand={asy -tex "context" -View -outformat pdf -outname
\externalfilteroutputfile\space \externalfilterinputfile},
output=\externalfilterbasefile.out,
readcommand=\typefile,
cache=force,
location=text,
continue=yes]

\starttext
\startASY[myplot]
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
\externalfigure[myplot]
\stoptext


Thanks
Jeroen

2014-12-28 12:04 GMT+01:00 Mojca Miklavec <mojca.miklavec.lists@gmail.com>:

> Dear Aditya,
>
> On Sun, Dec 28, 2014 at 8:21 AM, Aditya Mahajan wrote:
> > On Wed, 24 Dec 2014, Context NTG wrote:
> >
> >> Could anybody explain how to use Asymptote in ConTeXt with the filter
> >> module.
> >
> > Can you post a minimal asymptote file and how it shoud be processed via
> the
> > command line?
>
> I have no time to create a nice minimal example, but here's an ugly
> non-minimal example which should at least enable you to test the
> interaction with the filter module.
>
> I also added one ConTeXt-specific command while trying to make math
> fonts work properly, just replace "lucidaot" with another font in case
> you don't have that one installed.
>
> You can run the example with
>     asy -tex context cylinder.asy
>
> (Maybe it's possible to set the tex engine inside the file as well.)
>
>
> Bonus points if you can get PRC to work properly before TL 2015. Or if
> you can make the file print properly from OS X without using Acrobat
> or ghostscript/CUPS. Preview.app "forgets" to print the (smoothly
> shaded) cylinder for example.
>
> Mojca
>
>
> ___________________________________________________________________________________
> 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://tex.aanhet.net
> archive  : http://foundry.supelec.fr/projects/contextrev/
> wiki     : http://contextgarden.net
>
> ___________________________________________________________________________________
>

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

[-- Attachment #2: Type: text/plain, Size: 485 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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: Asymptote in Context
  2014-12-28  7:21 ` Aditya Mahajan
@ 2014-12-28 11:04   ` Mojca Miklavec
  2015-01-02 22:14     ` Context NTG
  0 siblings, 1 reply; 6+ messages in thread
From: Mojca Miklavec @ 2014-12-28 11:04 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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

Dear Aditya,

On Sun, Dec 28, 2014 at 8:21 AM, Aditya Mahajan wrote:
> On Wed, 24 Dec 2014, Context NTG wrote:
>
>> Could anybody explain how to use Asymptote in ConTeXt with the filter
>> module.
>
> Can you post a minimal asymptote file and how it shoud be processed via the
> command line?

I have no time to create a nice minimal example, but here's an ugly
non-minimal example which should at least enable you to test the
interaction with the filter module.

I also added one ConTeXt-specific command while trying to make math
fonts work properly, just replace "lucidaot" with another font in case
you don't have that one installed.

You can run the example with
    asy -tex context cylinder.asy

(Maybe it's possible to set the tex engine inside the file as well.)


Bonus points if you can get PRC to work properly before TL 2015. Or if
you can make the file print properly from OS X without using Acrobat
or ghostscript/CUPS. Preview.app "forgets" to print the (smoothly
shaded) cylinder for example.

Mojca

[-- Attachment #2: cylinder.asy --]
[-- Type: application/octet-stream, Size: 2236 bytes --]

settings.outformat="pdf";
settings.render=0;
settings.prc=false;

// asy -tex context cylinder.asy
texpreamble("\setupbodyfont[lucidaot,8pt]");
//defaultpen(fontsize(8pt));
defaultpen(font("lucidaot", 8.0));

import solids;

size(0,120);

// Return a right circular cylinder of height h in the direction of axis
// based on a circle centered at c with radius r.
revolution halfcylinder(triple c=O, real r, real h, triple axis=Z, real angle1=0, real angle2=360)
{
  triple C=c+r*perp(axis);
  axis=h*unit(axis);
  return revolution(c,C--C+axis,axis,angle1,angle2);
}

revolution halfthickcylinder(triple c=O, real r1, real r2, real h, triple axis=Z, real angle1=0, real angle2=360)
{
  triple C=c+r1*perp(axis);
  triple dC=(r2-r1)*perp(axis);
  axis=h*unit(axis);
  return revolution(c,C--C+axis--C+axis+dC--C+dC--cycle,axis,angle1,angle2);
}

currentlight=light(4,-5,5);
currentprojection=orthographic(2,-5,0.6);

real r1=0.50, r2=0.52, h=0.40;
real px=0.1, py=px, pz=0.2;
real phi1=5, phi2=165;

surface patient = scale(px,py,pz)*shift(-0.5,-0.5,-0.5)*unitcube;

revolution ring1=rotate(-90,Y)*shift(0,-h/2,0)*halfthickcylinder(O,r1,r2,h,Y,phi1,phi2);
revolution ring2=yscale3(-1)*ring1;

real dax = 0.2;
draw((r2,0,r2)--(r2,0,r2+dax),blue,Arrow3);
label("$z$", (r2,0,r2+dax), N, blue);
draw((r2,0,r2)--(r2,dax,r2),green,Arrow3);
label("$y$", (r2,dax,r2), NE, green);
draw((r2,0,r2)--(r2+dax,0,r2),red,Arrow3);
label("$x$", (r2+dax,0,r2), E, red);


draw(surface(ring2),yellow);

draw(O--(rotate(-phi1,Y)*scale3(r2)*Z),dashed);
draw(O--(rotate(-phi2,Y)*scale3(r2)*Z),dashed);

label(format("$%.0f°$", phi1), (rotate(-phi1,Y)*scale3(r2)*Z), N);
label(format("$%.0f°$", phi2), (rotate(-phi2,Y)*scale3(r2)*Z), S);

real ax(real t) {return 0.5*r2*cos(t);}
real ay(real t) {return 0.5*r2*sin(t);}
real az(real t) {return 0;}
path3 ap=graph(ay,az,ax,0,-pi*phi2/180,operator ..);
draw(ap,Arrow3);
label("$\phi$", (rotate(-phi2/2,Y)*scale3(r2/2)*Z), W);


draw(scale3(-pz/2)*Z--scale3(-r2)*Z,red);
draw(scale3(-pz/2)*Z--scale3(pz/2)*Z,red+dashed);
draw(patient, blue+opacity(.7), 0.4bp+black);
draw(scale3(pz/2)*Z--scale3(r2)*Z,red);

draw(surface(ring1),yellow);

path3 ah = rotate(-30,Y)*shift(r2,0,0)*scale3(0.5*h)*((0,-1,0)--(0,1,0));


[-- Attachment #3: cylinder.pdf --]
[-- Type: application/pdf, Size: 57748 bytes --]

[-- Attachment #4: Type: text/plain, Size: 485 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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: Asymptote in Context
  2014-12-24 21:41 Context NTG
@ 2014-12-28  7:21 ` Aditya Mahajan
  2014-12-28 11:04   ` Mojca Miklavec
  0 siblings, 1 reply; 6+ messages in thread
From: Aditya Mahajan @ 2014-12-28  7:21 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Wed, 24 Dec 2014, Context NTG wrote:

> Could anybody explain how to use Asymptote in ConTeXt with the filter
> module.

Can you post a minimal asymptote file and how it shoud be processed via 
the command line?

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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Asymptote in Context
@ 2014-12-24 21:41 Context NTG
  2014-12-28  7:21 ` Aditya Mahajan
  0 siblings, 1 reply; 6+ messages in thread
From: Context NTG @ 2014-12-24 21:41 UTC (permalink / raw)
  To: mailing list for ConTeXt users


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

Could anybody explain how to use Asymptote in ConTeXt with the filter
module.

Thanks
Jeroen

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

[-- Attachment #2: Type: text/plain, Size: 485 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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

end of thread, other threads:[~2015-01-20  3:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-07 17:50 Asymptote in Context context context
2014-12-24 21:41 Context NTG
2014-12-28  7:21 ` Aditya Mahajan
2014-12-28 11:04   ` Mojca Miklavec
2015-01-02 22:14     ` Context NTG
2015-01-20  3:39       ` Aditya Mahajan

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