racket / scribble

Other
197 stars 90 forks source link

Possible issue with scribble-math/asymptote #296

Closed encomer closed 3 years ago

encomer commented 3 years ago

An error with the following message is generated when I use Scribble HTML in the indicated code, under Windows 10. This error happens with Racket 7.9 as well as 8.0 (but I understand that it may be related to my particular installation).

The code that generates the above error is:

#lang scribble/manual
@require[scribble-math
         scribble-math/asymptote]

@asymptote{
 import drawtree;
 size(4cm, 0);
 TreeNode root = makeNode("let");
 TreeNode bindings = makeNode(root, "bindings");
 TreeNode binding = makeNode(bindings, "binding");
 TreeNode bid = makeNode(binding, "id");
 TreeNode bexpr = makeNode(binding, "expr");
 TreeNode bindingddd = makeNode(bindings, "\vphantom{x}\dots");
 TreeNode body = makeNode(root, "body");
 TreeNode bodyddd = makeNode(root, "\vphantom{x}\dots");

 draw(root, (0,0));
 shipout(scale(2)*currentpicture.fit());
}

Thank you very much for any pointer to the solution of this error. (May be an update is required. I use MiKTeX in my installation). Please Keep Safe. Sincerely, E. Comer P.S. If there is a better channel to communicate this problem, I will appreciate very much to inform me about it.

sorawee commented 3 years ago

This seems to be an issue with the package scribble-math, not Scribble in general. So you might want to report at https://github.com/jsmaniac/scribble-math/issues instead.

soegaard commented 3 years ago

@sorawee Is right, this seems to be an issue with scribble-math.

To narrow down the problem, I saved the asymptote code to a.asy and ran asymptote. This runs without problems, so the asymptote code is fine.

The I tried runinning your example in the terminal, and that worked too. This was on macOS, so maybe the problem is Windows related?

The next step must be to examine the temporary file containing the asymptote code. And the running asy on that file manually on a Windows machine.

FWIW it worked for me with asymptote versions 2.49 and 2.68.

soegaard@mbp2 tmp % raco scribble a.scrbl 
/Users/soegaard/tmp/6228680d172f42f5b82df313abc45824
Processing 6228680d172f42f5b82df313abc45824
processing of PostScript specials is disabled (Ghostscript not found)
WARNING: 16 PostScript specials ignored. The resulting SVG might look wrong.
Wrote 6228680d172f42f5b82df313abc45824.svg
Processing 6228680d172f42f5b82df313abc45824
Wrote 6228680d172f42f5b82df313abc45824.pdf
Processing 6228680d172f42f5b82df313abc45824
Wrote 6228680d172f42f5b82df313abc45824.png
 [Output to a.html]

image

soegaard commented 3 years ago

Just now, I installed DrRacket 8.0 and TeXLive 2020 (which contains Asymptote) on a Windows 10 machine. Your example ran fine. My version of Asymptote can be seen below.

However, a little googling suggests that the error might be caused by an old version of GhostScript. My suggestion is to upgrade both Asymptote and Ghostscript.

image

encomer commented 3 years ago

Thank you @soegaard for the suggestion: I updated Asymptote (to 2.69), Ghostscript (to 9.53.3), and reinstalled MikTeX (with the packages asyfig, asymptote, and miktex-asymptote-bin-x64-2.9) and I get still the same error message:

real clock=a[4];
  ^
C:\Users\hp\AppData\Local\Programs\MiKTeX/asymptote/plain.asy: 263.3: 
reading array of length 4 with out-of-bounds index 4

Also, I tested (the same code) on another Windows 10 machine, and I get also the same error.

Because with TeXLive 2020, you run the code with no problem, then one possible action is to install TeXLive instead of MiKTeX in my Windows 10 machine. It would be great to know if someone else running also MiKTeX is able or not, to run the Asymptote code (from Scribble with scribble-math) without problem.

Thank you for any further suggestion to solve this problem for computers under Windows 10. Please Keep Safe. P.S. This option of evaluating Asymptote code within Scribble (with scribble-math) adds really a great functionality to Scribble, for writing mathematics oriented documents and notes. Thank you for supporting mathematics (and mathematics teaching) with this excellent package.

soegaard commented 3 years ago

Hi @encomer

According to https://tex.stackexchange.com/questions/583833/asymptote-figures-not-rendering-in-vs-code
another MikTeX user has the same problem. I am wondering whether reinstalling MikTeX removed your newly updated Asymptote? Or maybe you have a PATH, that finds the wrong Asympote first?

See the answer by John Bowman.

encomer commented 3 years ago

Thank you again @soegaard . Finally the problem is SOLVED. Following your suggestion and reading the observations by John Bowman, the solution in my Windows 10 machine, was:

Step 1. Create the file config.asy, with the following lines:
import settings;
texpath="C:\Users\hp\AppData\Local\Programs\MiKTeX\miktex\bin\x64";
dvips="C:\Users\hp\AppData\Local\Programs\MiKTeX\miktex\bin\x64\dvips";

Step 2. Put the file config.asy in the Asymptote folder. In my case: C:\Program Files\Asymptote.

Thank you very much for all your support. (If you like, we can close the issue) Please Keep Safe. Sincerely, Enrique Comer. P.S. What is interesting is that formerly, in previous versions of MiKTeX and Asymptote, the Asymptote code worked perfectly without the need of creating the config.asy file. May be the two steps solution above can be useful also for other people working with MiKTeX and Asymptote.