# Asymptote as a Julia package?

**URL:** https://discourse.julialang.org/t/asymptote-as-a-julia-package/907
**Category:** Community
**Created:** [December 12, 2016, 11:48pm UTC](https://discourse.julialang.org/t/asymptote-as-a-julia-package/907 "2016-12-12T23:48:26Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![mhw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mhw/32/8469_2.png) [@mhw](https://discourse.julialang.org/u/mhw)
#### Post date: [December 12, 2016, 11:48pm UTC](https://discourse.julialang.org/t/asymptote-as-a-julia-package/907/1 "2016-12-12T23:48:26Z")

</div>

Based on the follwing data type for trees

```julia
type Tree{T} 
    key:: T
    st :: Array{Tree{T},1} 
end

```

I have written a small program with plots such trees using Asymptote (based on ANDREW J. KENNEDYs algorithm for drawing trees, J. Functional Programming 6 (3): 527–534, May 1996). The program generates a sequence of draw commands, stores them as asy-file and does an external call of Asymptote for this file.  
Output can be either eps, png, pdf or svg. (Tikz is still planned. In this case Asymptote isn’t used)

As an example this is the output of a randomly generated tree:  
 ![](https://global.discourse-cdn.com/julialang/original/3X/d/9/d97357e43cd89b9fe16f5ef7ea652f67b7bc9d4a.png)

When writing this program I thought having (a reimplementation of) Asymptote as Julia package would be great (provided permission of the developers of Asymptote is given). What are your opinions?

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [December 13, 2016, 4:18am UTC](https://discourse.julialang.org/t/asymptote-as-a-julia-package/907/2 "2016-12-13T04:18:05Z")

</div>

We do have a Cairo.jl package, and there is the Compose.jl package if you want a simpler higher-level graphics interface, and GLVisualize.jl … not sure what re-implementing Asymptote would add? Certainly you would have to re-think the Asymptote syntax (which is C++ like) for Julia’s idioms.

---

<div class="post-metadata">

### Author: ![cortner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cortner/32/204_2.png) [@cortner](https://discourse.julialang.org/u/cortner)
#### Post date: [December 13, 2016, 7:15am UTC](https://discourse.julialang.org/t/asymptote-as-a-julia-package/907/3 "2016-12-13T07:15:16Z")

</div>

LaTeX typesetting of labels (or is this already in Cairo / Compose? Either way it would probably be easier to add this to existing packages.)

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [December 13, 2016, 8:59am UTC](https://discourse.julialang.org/t/asymptote-as-a-julia-package/907/4 "2016-12-13T08:59:19Z")

</div>

There is  
[https://github.com/JuliaGraphics/Cairo.jl/blob/master/src/Cairo.jl#L1103](https://github.com/JuliaGraphics/Cairo.jl/blob/master/src/Cairo.jl#L1103)  
but perhaps rewriting it to render to an intermediate format which is useful for other purposes would be a good project for a library.

---

<div class="post-metadata">

### Author: ![barche](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/barche/32/79_2.png) [@barche](https://discourse.julialang.org/u/barche)
#### Post date: [December 13, 2016, 9:05am UTC](https://discourse.julialang.org/t/asymptote-as-a-julia-package/907/5 "2016-12-13T09:05:36Z")

</div>

How does Asymptote compare to Tikz? The latter is already supported in [TikzPictures.jl](https://github.com/sisl/TikzPictures.jl) and uses latex to generate the figures.

Tools to generate inline, potentially interactive graphics in notebooks are a good thing to have for sure.

---

<div class="post-metadata">

### Author: ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)
#### Post date: [December 13, 2016, 10:20am UTC](https://discourse.julialang.org/t/asymptote-as-a-julia-package/907/6 "2016-12-13T10:20:04Z")

</div>

> [@Tamas\_Papp](#):
>
> rewriting it to render to an intermediate format

You’re volunteering? I was active for some time to find a latex-style labeling solution, but did not make real progress. It really look’s like this is missing as independent library. Mathjax looked like a solution, but then i learned, they are not outputting svg, but a special html style where you need a browser rendering entity. The Mozilla MathML project looked also promising, but access to the logic goes via Gecko and that brings in the (whole) C++ API library chaos.  
GtkMathView also is mentioned several times, but seems abandoned.

---

<div class="post-metadata">

### Author: ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)
#### Post date: [December 13, 2016, 10:34am UTC](https://discourse.julialang.org/t/asymptote-as-a-julia-package/907/7 "2016-12-13T10:34:21Z")

</div>

julia-users thread  
[https://groups.google.com/forum/?fromgroups=#!searchin/julia-users/math$20rendering|sort:relevance/julia-users/VDOPMen0mFE/bCy5ifgKi8kJ](https://groups.google.com/forum/?fromgroups=#!searchin/julia-users/math%2420rendering%7Csort:relevance/julia-users/VDOPMen0mFE/bCy5ifgKi8kJ)

---

<div class="post-metadata">

### Author: ![tawheeler](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tawheeler/32/17657_2.png) [@tawheeler](https://discourse.julialang.org/u/tawheeler)
#### Post date: [December 13, 2016, 12:12pm UTC](https://discourse.julialang.org/t/asymptote-as-a-julia-package/907/8 "2016-12-13T12:12:01Z")

</div>

There is also [TikzGraphs.jl](https://github.com/sisl/TikzGraphs.jl) which does graphs in LaTeX. It is possible that there is already a graph layout that does what you want.

---

<div class="post-metadata">

### Author: ![mhw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mhw/32/8469_2.png) [@mhw](https://discourse.julialang.org/u/mhw)
#### Post date: [December 14, 2016, 4:49pm UTC](https://discourse.julialang.org/t/asymptote-as-a-julia-package/907/9 "2016-12-14T16:49:32Z")

</div>

Thanks for all the replies.

“`There is also TikzGraphs.jl`” Unfortunately I wasn’t aware of this package (my fault! ). I like Tikz and I think this package indeed is very useful.  
Personally I believe that concerning 3D Asymptote has some advantages over Tikz. However when reading that Asymptote has more than 80.000 lines of low level C++ code (as of June 2010) I have given up the idea of a reimplementation as a Julia package.

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [December 14, 2016, 4:52pm UTC](https://discourse.julialang.org/t/asymptote-as-a-julia-package/907/10 "2016-12-14T16:52:25Z")

</div>

80,000 lines of C++ ≈ 8,000 lines of Julia

---

<div class="post-metadata">

### Author: ![barche](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/barche/32/79_2.png) [@barche](https://discourse.julialang.org/u/barche)
#### Post date: [December 14, 2016, 5:18pm UTC](https://discourse.julialang.org/t/asymptote-as-a-julia-package/907/11 "2016-12-14T17:18:47Z")

</div>

> [@StefanKarpinski](#):
>
> 80,000 lines of C++ ≈ 8,000 lines of Julia

Coming from C++, I’d say that’s about right. But what really counts is the number of hairs left on your head when you’re finished, I think there it’s the other way around 😉

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [December 14, 2016, 5:20pm UTC](https://discourse.julialang.org/t/asymptote-as-a-julia-package/907/12 "2016-12-14T17:20:59Z")

</div>

> [@StefanKarpinski](#):
>
> 80,000 lines of C++ ≈ 8,000 lines of Julia

As a corollary: years to develop in C++ is one productive weekend in Julia.

---

<div class="post-metadata">

### Author: ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)
#### Post date: [December 15, 2016, 9:39am UTC](https://discourse.julialang.org/t/asymptote-as-a-julia-package/907/13 "2016-12-15T09:39:49Z")

</div>

This function doesn’t do much more than change font sizes and styles:

```julia
julia> Cairo.tex2pango("\$ -b \\pm \\sqrt{b^2 - 4ac} \\over 2a \$", 12)
"\$ −b ±\\sqrtb<sup><span font=\"7.416407813432845\">2</span></sup> − 4ac \\over2a \$"

```

(Obvious really that it wouldn’t do LaTeX, when you think about it. :))

---

<div class="post-metadata">

### Author: ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)
#### Post date: [December 15, 2016, 10:22am UTC](https://discourse.julialang.org/t/asymptote-as-a-julia-package/907/14 "2016-12-15T10:22:47Z")

</div>

> [@cormullion](#):
>
> Obvious really that it wouldn’t do LaTeX, when you think about it.

Oh, i just learned from Chris’ message, that TeX can be redone in Julia in one productive weekend…

---

<div class="post-metadata">

### Author: ![Steven\_Sagaert](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steven_sagaert/32/29578_2.png) [@Steven\_Sagaert](https://discourse.julialang.org/u/Steven_Sagaert)
#### Post date: [December 15, 2016, 10:31am UTC](https://discourse.julialang.org/t/asymptote-as-a-julia-package/907/15 "2016-12-15T10:31:45Z")

</div>

for inline interactive figures I think D3 is much better & more modern.

---

<div class="post-metadata">

### Author: ![barche](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/barche/32/79_2.png) [@barche](https://discourse.julialang.org/u/barche)
#### Post date: [December 15, 2016, 11:27am UTC](https://discourse.julialang.org/t/asymptote-as-a-julia-package/907/16 "2016-12-15T11:27:23Z")

</div>

This one I suppose?

> **[D3 by Observable | The JavaScript library for bespoke data visualization](https://d3js.org/)**
>
> The JavaScript library for bespoke data visualization

Is it available for use from within Julia? Looking at the examples, the interface seems very low-level compared to Tikz, but I must say the results are stunning.

---

<div class="post-metadata">

### Author: ![Steven\_Sagaert](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steven_sagaert/32/29578_2.png) [@Steven\_Sagaert](https://discourse.julialang.org/u/Steven_Sagaert)
#### Post date: [December 15, 2016, 11:46am UTC](https://discourse.julialang.org/t/asymptote-as-a-julia-package/907/17 "2016-12-15T11:46:56Z")

</div>

yes.  
there is a simple julia wrapper : [https://github.com/jverzani/DThree.jl](https://github.com/jverzani/DThree.jl) but you will still need to write D3 itself.

D3 is basically 2D vector graphics (svg) programming, analog to directly programming openGL for 3D. So it’s good if you want to develop your own custom visualisations. For a stunning example of this: [A visual introduction to machine learning](http://www.r2d3.us/visual-intro-to-machine-learning-part-1/)

Now if your looking for a more high level plotting lib: use plotlyJS.jl. The 2D plots of plotly are itself based on D3.js (the 3D ones are based on webGL).

---

<div class="post-metadata">

### Author: ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)
#### Post date: [December 15, 2016, 12:13pm UTC](https://discourse.julialang.org/t/asymptote-as-a-julia-package/907/18 "2016-12-15T12:13:20Z")

</div>

How does D3 do TeX labels?

---

<div class="post-metadata">

### Author: ![Steven\_Sagaert](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steven_sagaert/32/29578_2.png) [@Steven\_Sagaert](https://discourse.julialang.org/u/Steven_Sagaert)
#### Post date: [December 15, 2016, 12:42pm UTC](https://discourse.julialang.org/t/asymptote-as-a-julia-package/907/19 "2016-12-15T12:42:20Z")

</div>

here’s one possible way [Redirecting to Google Groups](https://groups.google.com/forum/#!topic/d3-js/JzUTJmUBuKQ) [https://groups.google.com/forum/#!topic/d3-js/JzUTJmUBuKQ](https://groups.google.com/forum/#!topic/d3-js/JzUTJmUBuKQ)

---

<div class="post-metadata">

### Author: ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)
#### Post date: [December 15, 2016, 1:00pm UTC](https://discourse.julialang.org/t/asymptote-as-a-julia-package/907/20 "2016-12-15T13:00:48Z")

</div>

MathJax again → browser rendering.
