-
Notifications
You must be signed in to change notification settings - Fork 205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Asy fixes #1275
Asy fixes #1275
Conversation
I know this is for the sample article but have you tried running mbx with svg output over some 3D graphs? I could try running it over the 3D graphs in APEX to see how that comes out. Overkill maybe, but John seemed to think it should work fine if everything is reasonably up to date |
Here is my "standard" MWE for 3d tests:
If you use this with A propos to this PR, asymptote-contour.svg does the same thing, and that is precisely why I rolled my own to make the svg file that is included in the c245f5d commit. |
Doesn't
Maybe there's a bug in this part of the code? |
My recollection is that the SVG created by asy makes assumptions about the
location of the PNG file that are inaccurate when the two files live in a
directory *below* the directory with the page including the image.
Do the mbx drill, put everything in place, then use your browser to open
*just* the SVG image.
At least that is how I remember it before I disappear to grade final exams. mbx
definitely looks for a PNG and tries to place it correctly.
…On 5/12/20 11:31 AM, sean-fitzpatrick wrote:
Doesn't |mbx| have a subroutine that checks for the png files and copies them if
they're there?
|for diagram in diagrams: asydiagram = diagram[0] # can condition processing on
diagram[1] # which is a string: '2D' or '3D' if outformat == 'source':
shutil.copy2(asydiagram, dest_dir) elif outformat == 'html': filebase, _ =
os.path.splitext(asydiagram) asyout = "{}.{}".format(filebase, outformat) asysvg
= "{}.svg".format(filebase) asypng = "{}_*.png".format(filebase) asy_cmd =
[asy_executable, '-outformat', outformat, asydiagram] _verbose("converting {} to
{}".format(asydiagram, asyout)) _debug("asymptote conversion
{}".format(asy_cmd)) subprocess.call(asy_cmd, stdout=devnull,
stderr=subprocess.STDOUT) if os.path.exists(asyout) == True:
shutil.copy2(asyout, dest_dir) else: shutil.copy2(asysvg, dest_dir) # Sometimes
Asymptotes SVGs include multiple PNGs for colored regions for f in
glob.glob(asypng): shutil.copy2(f, dest_dir) else: filebase, _ =
os.path.splitext(asydiagram) asyout = "{}.{}".format(filebase, outformat) asypng
= "{}_*.png".format(filebase) asy_cmd = [asy_executable, '-noprc', '-offscreen',
'-batchMask', '-outformat', outformat, asydiagram] _verbose("converting {} to
{}".format(asydiagram, asyout)) _debug("asymptote conversion
{}".format(asy_cmd)) subprocess.call(asy_cmd, stdout=devnull,
stderr=subprocess.STDOUT) shutil.copy2(asyout, dest_dir) # Sometimes Asymptotes
SVGs include multiple PNGs for colored regions for f in glob.glob(asypng):
shutil.copy2(f, dest_dir) |
Maybe there's a bug in this part of the code?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1275 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAOLM4RNPM7QY6D4UBRXVXDRRGIZHANCNFSM4M6MIWFA>.
|
I made a fresh copy of the mathbook repo and reran xsltproc on the sample-article followed by mbx using asy with the -f html option. First of all, using version 2.65 of asymptote will now clear up the problem with the Riemann surface. It looks beautiful. Next, I found a (start for a) solution to the problem with the contour plot. It is in the graphics.html file generated by xsltproc. The diff between to original and new graphics.html files is given below, but in summary:
is changed to
4c4
< <!--* on 2020-05-13T12:23:52-05:00 *-->
---
> <!--* on 2020-05-13T09:32:40-05:00 *-->
351c351
< <figure class="figure figure-like" id="figure-asymptote-contour-plot"><div class="image-box" style="width: 100%; margin-left: 0%; margin-right: 0%;"><object data="images/asymptote-contour.html" id="asymptote-contour" width="600" height="600"><img src="images/asymptote-contour.svg" style="width: 100%; height: auto;" alt=""></object></div>
---
> <figure class="figure figure-like" id="figure-asymptote-contour-plot"><div class="image-box" style="width: 100%; margin-left: 0%; margin-right: 0%;"><object data="images/asymptote-contour.svg" id="asymptote-contour" width="600" height="600"><img src="images/asymptote-contour.svg" style="width: 100%; height: auto;" alt=""></object></div> I can see where these lines get generated in the mathbook-html.xsl file, but I'm hesitant to add my own fix since I'm not sure what other things would be affected. |
And furthermore, the source for asymptote-contour.asy is
Question: |
I'm going to try running mbx with svg output on APEX Calculus. (All asymptote graphs are 3D graphs there though.)
So I think (but could be wrong) that it's the |
So what I learned today is that version 2.65 (in fact, I think 2.62 will do) is good enough to run But if I run I spent awhile tonight fighting to get asymptote to compile from the github source. Every time I think I've got it, it turns out I was missing some library and it doesn't work as expected. I'll try again tomorrow! |
Sean -- Could you try the with same experiment the asymptote-contour.asy attached? |
So, is The |
Yes, I think for most use cases, we want to run with HTML output -- we get SVGs for free on figures where there is no 3D content. We might need different commands for PDF and SVG, because we have to pass different options. For PDF we probably want I've been able to get 2.66 to compile from source but it isn't working quite right. In particular, the |
@mdoob - what "extra" did you need to do to make the "contour" plot? Just a newer version of It appears to have the two "gradient" images embedded directly as base64 (one PNG, one JPG) within the single SVG file, where formerly the SVG "linked in" two external PNG files. The new scheme would be a big improvement. |
Here is my output running Asymptote 2.66 on This was on my laptop where I'm running Ubuntu 18.04. I'm able to compile Asymptote just fine here. But I know John was asking about having I'll try on my desktop in a bit. |
Hi Sean --
Did you get the same result with -f svg and -f html?
My problem was with the former working and the latter not.
…------------------------------------------------------------------
Michael Doob Telephone: (204) 474-9796
Senior Scholar
Department of Mathematics email: Michael.Doob@UManitoba.ca
University of Manitoba
Winnipeg, MB, Canada R3T 2N2
------------------------------------------------------------------
________________________________________
From: sean-fitzpatrick <notifications@github.com>
Sent: May 14, 2020 2:13:37 PM
To: rbeezer/mathbook
Cc: Michael Doob; Mention
Subject: Re: [rbeezer/mathbook] Asy fixes (#1275)
Caution: This message was sent from outside the University of Manitoba.
Here is my output running Asymptote 2.66 on asymptote-contour.svg:
contour plot<http://www.cs.uleth.ca/~fitzpat/asymptote-contour.svg>
This was on my laptop where I'm running Ubuntu 18.04. I'm able to compile Asymptote just fine here. But I know John was asking about having dvisvgm at version 2.9.1. That's not possible on 18.04 because it requires a newer version of libc6.
I'll try on my desktop in a bit.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#1275 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAVJL7VLF4APSIUFIV7IUYTRRQ7GDANCNFSM4M6MIWFA>.
|
Yes, I got the same result. Running
and I get what appears to be the same SVG as before. |
Here is where I see us now: when running mbx with -f html, the svg file and png files that Just to repeat: I also tried adding the attribute dimension="2", but it made no difference. |
In the HTML for APEX Calculus (most recently generated about a week ago) each Asymptote figure appears like the following (this is the very first Asymptote figure in the book):
As I understand it, this looks first for the HTML, and if that is missing, it uses SVG. But yes -- I can confirm what Michael is saying: if I remove the HTML file (or rather, rename it), the SVG is not being used as fallback. I just get an empty image. But if I right-click and select view image, the SVG is there. |
I'm confused by the diff @mdoob posted above. First, the timestamps look out-of-order (older one is leaving). And the The checks on the When I build with this PR applied everyting looks fine - in other words, SVG fallbacks are working. |
It took me some time to find a single change that would put everything right. I saved the
Yes, the svg and png files show up properly in the images directory. The problem is that the graphics.html files doesn't read them. I think that asy and mbx are doing the right thing. It appears that during the extraction of the asymptote code from the xml file, the source is being interpreted as a 3D figure. |
To add a little more fuel to the fire:
So every call to asy uses -f html. Now mbx has received '2D' or '3D' to indicate the dimension of the figure. Shouldn't that be used at this point? |
It wasn't clear to me if mbx was now receiving that information. But is that even necessary? I think the point is that Asymptote can make that decision. We just run mbx with html as the output type. Asymptote is going to successfully convert every image. Some will become html, some will become svg. The mbx script calls |
Ok. If that's the plan, let's forget 2D/3D in extract-asymptote.xsl. Just use -f html on everything.
Sounds like a plan! |
The main reason I'm trying to figure out svg is that someone might want to force svg format for figures that would otherwise be html. So we want to be able to run It seems like Asymptote 2.66 should support this. Although John mentioned in email that |
I added the 2D/3D information to
I believe this is already there. |
Yes, I put it there in that initial pull request to add support for html output from Asymptote. Though I'm not sure if that PR we ever fully merged. For the various output formats, I think we're at: PDF: works on all figures. I'm not sure there's much demand for other formats (EPS?). We're maybe a year out from being able to do a clean mbx run using default versions in a stable Linux distro. But for those willing to pull in a few programs at higher version numbers we should be there by next week. |
OK, positive result. I am currently enjoying watching a shell script blast through 309 asy files generated from APEX Calculus ptx. All but a few are 3D, and I'm generating SVG. A slight modification of a suggestion from John Bowman does the trick: I'm running: The Note however that SVG and PDF will need different command line options, so we will have to tweak the mbx script a bit more -- I think -- to treat these separately. |
OK, spent a long time reading through all this. Seems there are two things to do:
When we are confident about changes, it would help if @sean-fitzpatrick were to write down the best asy command lines (switches) for html/svg, pure-svg, and PDF. |
In the good news/bad news department:
I suspect the reason is that I've got the most recent It's possibly |
I made a change to mathbook-html.xsl following Sean's suggestion. Here is the diff
All the figures displayed correctly. I looked at the logs and did get a number of 404s for html files, but later all the svg and png files came in as expected (200 return code). |
Thanks, Michael. I'll make a beta version soon, so folks can hit it with a variety of browsers. |
Beta here: https://pretextbook.org/beta/2020-05-16-asymptote/graphics.html Old 2-D Riemann surface. Figure 9.12 is 3D HTML via If @mdoob and @sean-fitzpatrick both report success here, then I can put it on -dev for wider testing. |
Sean and I went down the local/hosted version problem earlier. To make a long story short, |
The graphics in the sample article all show up for me. The non-interactive 3D image seems like it could be higher quality but I don't think that's a PreTeXt issue. I get the same results on both Chrome and Firefox on Ubuntu 18.04. |
Looks like the png got loaded instead of the svg. What do your logs tell you? |
Looking at the page source (or using the inspector), I think the embed option is including the SVG source. Then the SVG loads the PNG. |
Commits here by @mdoob have been repackaged, keeping everything as-is. Thanks very much for the flexibility of a separate commit for the contour plot, which at one point I did consider dropping. Nice use of git. I moved the 3D surface into a subsection with the 3D cone. And added documentation, including keyboard controls from @mdoob on I'm going to keep this open. If I got recommened Thanks for all the good work on this one. We're getting there. |
This has been a nice improvement (fun, too). My understanding is that with asymptote version 2.66, all the 3d figures compile and display correctly. Right? |
For html (WebGL) output, it seems like simply doing I'm not sure if it's necessary to add anything in there for SVG fallback. For SVG, based on what I pulled from the email thread with John and @mdoob we can use The One interesting thing to note: when I build @mdoob with 2.66 we can compile 3D figures directly to SVG, and everything is contained in a single svg. (So we'd be OK with |
Working on Goals for
My understanding and tests on old software (which I will document)
asy -noprc -iconify -batchMask -f pdf asymptote-workcone.asy
asy -f html asymptote-lever.asy
asy -f svg -render=4 -iconify asymptote-lever-solo.asy |
I was able to compile the work cone example using the command you provided. So maybe it's something specific to your version of asymptote? I just pasted the macros from the sample article into a file, along with the asymptote code. Some experimentation tells me that the option |
Thanks. Sounds like we need to choose between backward-compatibility (e.g. I'm for that, since I do not think there has been much uptake of |
Testing your new mbx. One urgent change for asymptote: |
Right. I've got a "asy-command-line" commit all queued up, which will remove
this. But needed to keep that separate for now since I've got too many fingers
in the pie. ;-)
…On 5/20/20 10:07 AM, sean-fitzpatrick wrote:
Testing your new mbx. One urgent change for asymptote: |-offscreen| needs to be
removed. If you run |asy| with |-offscreen| on Windows, it hangs at an error
message and |mbx| can't finish.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1275 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAOLM4QTVPB3AK4MOJ3TDYLRSQE4JANCNFSM4M6MIWFA>.
|
Looks like for pdf, I'm not entirely sure that |
from
|
With 3bb8833 I'm going to close this now. Thanks, @mdoob and @sean-fitzpatrick, for all the work on this one. |
I noticed a couple of things in 3bb8833 that need adjusting. This looks like it got copied over from the html block. But you don't want it here. For the html block, this checks to see if an html file was created. If not (because the diagram was 2D) it looks for the SVG instead. I think you just need to delete this line as well as line 115 (the At line 124, I think maybe For the |
Sorry Sean, I'm doing a system install on my home computer and was away. Exactly what do you want me to try out? |
Hi Michael. Just looking for confirmation that we have reasonable command line options for each file format in the |
In a matter of hours it will be a module `pretext\pretext.py`
…On 5/21/20 7:37 PM, sean-fitzpatrick wrote:
Hi Michael. Just looking for confirmation that we have reasonable command line
options for each file format in the |mbx| script.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#1275 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAOLM4XUISJVRFC3XYGHYQDRSXQNLANCNFSM4M6MIWFA>.
|
This pull request addresses the missing asymptote Figures 9.9 and 9.11 in Section 9.3. The added svg files will now display properly. The Riemann surface actually uses WebGL, so maybe it is slightly out of place. The contour plot is a bit more of a problem. I generated it myself rather that using mbx,
so it does show what PreTeXt can do, albeit not using the standard route. If this makes you uncomfortable, I included that file with a separate commit so that it is easy to abandon. Now that it has my attention, I'll use the next few days to see how dvisvgm might be adapted.
Cheers,
Michael