Hello, I'm writing a book and there are a lot of illustrations (more than 2K), almost all in Asymptote. So first, thank you!
In MetaPost I liked that the canonical way to proceed was to put many related graphics in a single file. I do the same in Asymptote, especially because I have so many figures, and of course there are often classes of related figures. I use a structure like this.
picture pic;
int picnum = 4;
-- figure drawing in here --
shipout(format(OUTPUT_FN,picnum),pic,format="pdf");
I mean this to be like MetaPost's
beginfig (4)
-- figure drawing in here --
endfig;
One thing that I have not been able to dope out in Asymptote how to do shadowing (sorry if this is the wrong term). I want a construct where changes inside get forgotten when you leave (as with TeX grouping). For example, this file:
Is there some construct that would result in the final one saying dotfactor=6? Am I missing something obvious?
Let me mention the motivation for the question. I'm giving a small talk about some of the above at the TUG meeting in June, trying to fly the Asymotote flag a little, and I wanted to get it right.
Regards,
Jim Hefferon
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If you are including this in a TeX document, it might be better to use \begin{asy}...\end{asy} as shown in latexusage.tex, or \asyinclude{},
along with latexmk. Common code can be enclosed within \begin{asydef}...\end{asydef}.
Enjoy the TUG meeting (and say hello to everyone from me)!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Another potentially relevant technique (which you may already be familiar
with given your use of the term "shadowing"):
If you put everything inside a static struct, and define a new variable real dotfactor inside that struct, then every time you refer to dotfactor within that struct, it will refer to the new variable rather
than the old one. (This is "shadowing.") BUT if you do this, then external
functions like dot() that use the old variable will still use the old
variable, even if called from within the struct.
I don't really see any way a programming language can support the
Metapost-style behavior without dynamic scoping https://stackoverflow.com/a/22395580/2318074, which is generally
considered bad practice in programming language design. The better approach
(from a language design perspective) would have been to minimize the use of
global variables in the plain module. Unfortunately, that ship has
sailed. And in truth, it doesn't present much of an issue in
Asymptote's most common use case (i.e., one program <--> one shipout).
Hello, I'm writing a book and there are a lot of illustrations (more than 2K), almost all in Asymptote. So first, thank you!
In MetaPost I liked that the canonical way to proceed was to put many related graphics in a single file. I do the same in Asymptote, especially because I have so many figures, and of course there are often classes of related figures. I use a structure like this.
I mean this to be like MetaPost's
One thing that I have not been able to dope out in Asymptote how to do shadowing (sorry if this is the wrong term). I want a construct where changes inside get forgotten when you leave (as with TeX grouping). For example, this file:
produces this result.
Is there some construct that would result in the final one saying
dotfactor=6
? Am I missing something obvious?Let me mention the motivation for the question. I'm giving a small talk about some of the above at the TUG meeting in June, trying to fly the Asymotote flag a little, and I wanted to get it right.
Regards,
Jim Hefferon
Hi Jim,
If you really want each section of code to be run in a separate asy process, you can use eval for this:
If you are including this in a TeX document, it might be better to use
\begin{asy}...\end{asy}
as shown inlatexusage.tex
, or\asyinclude{}
,along with
latexmk
. Common code can be enclosed within\begin{asydef}...\end{asydef}
.Enjoy the TUG meeting (and say hello to everyone from me)!
Thank you, John. I'm glad I didn't miss something obvious, as has happened to me before.
Regards,
Jim
Another potentially relevant technique (which you may already be familiar
with given your use of the term "shadowing"):
If you put everything inside a
static struct
, and define a new variablereal dotfactor
inside that struct, then every time you refer todotfactor
within that struct, it will refer to the new variable ratherthan the old one. (This is "shadowing.") BUT if you do this, then external
functions like
dot()
that use the old variable will still use the oldvariable, even if called from within the struct.
I don't really see any way a programming language can support the
Metapost-style behavior without dynamic scoping
https://stackoverflow.com/a/22395580/2318074, which is generally
considered bad practice in programming language design. The better approach
(from a language design perspective) would have been to minimize the use of
global variables in the
plain
module. Unfortunately, that ship hassailed. And in truth, it doesn't present much of an issue in
Asymptote's most common use case (i.e., one program <--> one shipout).
Best,
Charles
On Sat, Jun 3, 2023 at 4:56 AM Jim Hefferon jhefferon@users.sourceforge.net
wrote: