vectorgraphics / asymptote

2D & 3D TeX-Aware Vector Graphics Language
https://asymptote.sourceforge.io/
GNU General Public License v3.0
533 stars 89 forks source link

I cannot compile asymptote code to output to svg. #397

Closed jfab20 closed 9 months ago

jfab20 commented 9 months ago

I'm on Arch Linux 6.5.4-arch2-1 and I have the latest versions of asymptote and dvisvgm.

I cannot compile asymptote code to output to svg. I have a minimal file

settings.outformat="svg";

size(10cm);

draw(unitsquare);

in my test.asy file and when I compile it using asy test.asy I get the following error:

/usr/include/c++/13.2.1/bits/stl_vector.h:1125: std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = std::__cxx11::basic_string<char>; _Alloc = std::allocator<std::__cxx11::basic_string<char> >; reference = std::__cxx11::basic_string<char>&; size_type = long unsigned int]: Assertion '__n < this->size()' failed.
  _shipout(prefix,f,currentpatterns,format,wait,view,t);
          ^
/usr/share/asymptote/plain_shipout.asy: 116.11: runtime: Command exited abnormally: dvisvgm -n -v3 --optimize -otest.svg test_.dvi 

I have tried reinstalling dvisvgm, texlive and asymptote. When I change svg to pdf everything works as expected, and I get a pdf file with a square in it.

Whenever I run asy test.asy with svg output format I get a bunch of files created in the same directory like test_.aux, test_.dvi and with other extensions like .tex, .eps.

I have also created a .asy/config.asy file and added the lines

import settings;
libgs="";

with no effect. What can I do?

jfab20 commented 9 months ago

After trying to run the command dvisvgm -n -v3 --optimize -o test.svg test_.dvi manually, I found out that the --optimize flag is the problem. When running the command without it, everything works out as expected. Is this a known problem?

johncbowman commented 9 months ago

If your version of dvisvgm doesn't support the --optimize flag, it is too old. Also make sure you are running the latest git version of Asymptote, which includes this work around:

Author: John Bowman <bowman@ualberta.ca>
Date:   Sat Jul 29 23:25:54 2023 -0600

    Fix bug 388: Avoid broken dvisvgm reassign-clippaths optimization.

diff --git a/picture.cc b/picture.cc
index dea28b54..1b28ee5a 100644
--- a/picture.cc
+++ b/picture.cc
@@ -462,7 +462,7 @@ string dvisvgmCommand(mem::vector<string>& cmd, const string& outname)
   string libgs=getSetting<string>("libgs");
   if(!libgs.empty())
     cmd.push_back("--libgs="+libgs);
-  cmd.push_back("--optimize");
+  cmd.push_back("--optimize=collapse-groups,group-attributes,remove-clippaths,simplify-text,simplify-transform");
   push_split(cmd,getSetting<string>("dvisvgmOptions"));
   string outfile=stripDir(outname);
   if(!outfile.empty())
jfab20 commented 9 months ago

If your version of dvisvgm doesn't support the --optimize flag, it is too old. Also make sure you are running the latest git version of Asymptote, which includes this work around:

I have version 3.1.1 of dvisvgm, which is the latest version as far as I'm aware of. Version 2.86-3 of asymptote.

johncbowman commented 9 months ago

It works with dvisvgm 3.1 but you still need commit aa9f81bad9478bfe8b2ab5fc5376c19c6c79c708 The latest git development version is 2.87-4.