-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to render latex in pdf and png backends #120
Comments
Hello! We currently don't have support for LaTeX in the PNG and PDF backends; but it should work using SVG. Here is a Colab example that renders the code above. (Sorry for those uninformative error messages; there was a bug in the code, which should be fixed now.) |
As pointed out in #120, LaTeX SVG were uncentered. Under closer inspection this happened because the width and height estimated by `latextools` were larger with a factor of 4 / 3. This change should ensure that the LaTeX SVGs are now centered.
Thanks for the report! I think I've fixed the issue: LaTeX should be properly centered now. As for the initial code, I think it's a bit dated, as it doesn't use the latest features (in particular, the arrows functionality: e.g., from chalk import *
from colour import Color
papaya = Color("#ff9700")
black = Color("black")
SEP = 3
W = 3
H = 2
DY = -0.5
def box(t):
return rectangle(W, H).line_width(0.05).fill_color(papaya) + latex(t)
def anchor():
return circle(0.05).fill_color(black)
nodes = [
anchor().named("inp"),
box("$f$").named("f"),
box("$g$").named("g"),
anchor().named("out"),
]
d = hcat(nodes, sep=3)
d = d.connect_outside("inp", "f")
d = d.connect_outside("f", "g")
d = d.connect_outside("g", "out")
d = (
d
+ latex(r"$f'_x(g(x))$").translate(SEP / 2, DY)
+ latex(r"$f'_{g(x)}(g(x))$").translate(3 * SEP / 2 + W, DY)
+ latex(r"$1$").translate(5 * SEP / 2 + 2 * W, DY)
)
d.render_svg("examples/output/latex.svg") Of course, this is still far from perfect. Some things to improve include:
As for the Inkscape rendering, I'm not sure what's happening. I usually use the browsers to view the SVGs, and they currently look fine for me. If it's a pressing issue I can investigate that as well. |
Great! Thanks very much. As to Inkscape rendering, I lived my life up to this point without this great tool, so it's not pressing per se (I've been using TikZ for like 12 years, so I'll manage). Inkscape is the de-facto open source SVG editing tool, though, and I supervise some PhD students who could make great use of chalk to make diagrams that then get incorporated into other figures (with images, e.g.) in Inkscape. Also, this is a backdoor way to generate PDF and PNG from latex-containing SVG files since Inkscape can do that (also from the CLI if memory serves). So I do think it's important enough to investigate even if it's not urgent for me. Thanks again very much! |
Yes, the use-case you are describing makes a lot of sense! I'll keep it in mind and I'll take a look at the Inkscape issue when I get some time. Also, thank you very much for the interest in our library—it's a much needed motivational boost, since, as you might imagine, it becomes a bit of challenge to actively maintain the side projects when other responsibilities take priority 🙂 |
I just discovered this very cool library while following along with the raspy blog. Thanks for creating it!
I was unable to successfully generate latex-containing output in an SVG (no errors were shown, but all latex symbols were missing), so I slightly modified the latex.py example to instead output a PDF since I think latex-containing SVGs are generated by first generating a PDF and then calling
pdf2svg
if I understand correctly. As far as I can tell, I have installed all the prerequisites, but I can't really test that because the following code generates aTypeError
:The resulting error is as follows:
If instead I run the
d.render_png("latex.png")
line, the error is insteadThe text was updated successfully, but these errors were encountered: