mkrphys / ipython-tikzmagic

IPython magics for generating figures with TikZ
BSD 3-Clause "New" or "Revised" License
160 stars 44 forks source link

Generate SVG output with dvisvgm #21

Open DavidPowell opened 6 years ago

DavidPowell commented 6 years ago

In my fork I added a new output method for generating SVGs, using latex and dvisvgm (instead of pdflatex and imagemagick). It has the following advantages and issues:

You can see some generated output in my example notebook. Notice how the text is now selectable, and the box moves when mousing over due to the javascript below.

My changes to the codebase can be found here https://github.com/DavidPowell/ipython-tikzmagic/commit/d5b25b6d0d1e5f70a45f0e95534348e42b33d40a

I decided to create this issue before generating a PR, since after my changes there is definitely more spaghetti code than I would like. Note that a lot of new options were needed to get the full benefit of this approach, and some options (like the size) are now ignored. As far as I can tell the existing functionality is preserved, but I haven't tested extensively.

Is this something that would make sense to integrate into ipython-tikzmagic?

The alternative would be for me to create a cleaned-up fork project which only has the dvisvgm mode.

parthi2929 commented 5 years ago

Hi David your fork is still active because this base looks not being updated any more? (no replies for many recent issues)

DavidPowell commented 5 years ago

@parthi2929 I made some changes to incorporate dvisvgm support. I am currently using this on an almost daily basis, but I have not needed to make many changes to the code.

You may wish to try out my fork. Using the --dvisvgm option (assuming you have dvisvgm installed), the output file now scales much more logically, and it probably solves your issue #27.

Please understand that this is just a volunteer project created for the dev's on needs. Resolving everyone else's issues requires time and commitment that not everyone has.

parthi2929 commented 5 years ago

this @mkrphys base has an svg option, but when i try it fails.

DavidPowell commented 5 years ago

The standard SVG conversion option is based on generating a PDF, then extracting an SVG with imagemagick. Imagemagick needs to be installed, also this extension needs to know where to find it. Under windows the default executable name is different to what the extension is expecting, so I added a -i option to allow the filename and path of imagemagick to be specified.

The approach I added in this issue is quite different. It generates a dvi, then converts to svg using dvisvgm (which should be already installed on any modern latex distribution). I found the output is much better quality, and scaling works better. Also, this approach enables SVG ids to be added to elements of the drawing, for making them interactive with javascript.