heliosdrm / GRUtils.jl

Tools for using the GR framework in Julia
Other
31 stars 6 forks source link

Using low level LaTeX renderer #81

Closed schneiderfelipe closed 3 years ago

schneiderfelipe commented 3 years ago

Hi @heliosdrm,

I'm looking for a simple way of generating PNGs from LaTeX expressions in Julia, and I just learned that GR is capable of interpreting a subset of LaTeX. Is it possible to do it? I couldn't find anything in the documentation of GRUtils.jl (I believe this is the right package for the job, not GR.jl; please correct me if I'm wrong).

heliosdrm commented 3 years ago

Hi, attributes with text like titles, axis guides and legends accept strings with UTF-8 characters and LaTeX expressions both in GR and GRUtils. Notice that writing LaTeX expressions in strings may be a bit cumbersome because backslashes and the $ must be escaped; to lessen the burden, you can use the package LaTeXStrings

schneiderfelipe commented 3 years ago

I was looking for a tool to generate standalone PNGs from LaTeX formulas. LaTeXString does not support outputting single PNGs with single formulas (see stevengj/LaTeXStrings.jl#43). Can this be done with GRUtils.jl?

kojix2 commented 3 years ago

Hello. GRUtils is a high-level API built on top of GR. If you don't mind using GR, the following example is the simplest one.

import GR

GR.beginprint("sample.png")
GR.setcharheight(0.1)
GR.mathtex(0.2, 0.5, "E=mc^2")
GR.updatews()
GR.endprint()

https://github.com/jheinen/GR.jl/blob/master/examples/math_bbox.jl

You may be able to do something similar using GRUtils text or savefig. For a better way to use GRUtils, I think @heliosdrm will answer your question.

heliosdrm commented 3 years ago

A @kojix2 mentioned, that is a task for GR. GRUtils is meant to produce figures with axes, etc., using the lower level functions of GR.