We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I had to add a equation to my code. So, I typed out the equation in tex. And rendered the file using xelatex
and then used pdfcrop
to remove the extra spacing and the converted it into a SVG file using pdf2svg
. I put the SVG file in the data directory of my sketch. Now when I loadShape()
the SVG into a PShape and run the sketch I get nothing. I am sure that there is nothing wrong with the SVG file because Firefox and Inkscape can open them correctly.
So, some please tell me how can I get the SVG to display or better yet, tell me how to add a TEX equation into Processing and save me from a xelatex eqn.tex && pdfcrop eqn.pdf && pdf2svg eqn-crop.pdf eqn.svg && cp eqn.svg data/
loop every time I update a equation.
Answers
I tried this code with an SVG and it worked:
Is there another way you can generate a svg image? An idea will be to try an online image converter. If using Linux, you could use imagemagick.
Kf
this kind of problem is impossible to debug without access to the svg file in question
if it's not too big you can post it here, formatted as code (highlight the source, press ctrl-o)
Here is the svg.
This SVG doesn't work. And do you know any other way to embed a tex equation into Processing?
ok, when i run that i get two warnings in the console beneath the source
and given that ALL your svg code is in symbol tags or use tags then it's ignoring a lot.
please remember the svg specification is large and complicated and i guess P3's implementation isn't that complete.
Yes. The console gives that error. So, what am I supposed to do now? How can I insert LATEX equation into my sketch?
This is the answer unfortunately. I tried what you are doing too and had to resort to export the equation as a bitmap image.
Bitmaps suck big time. You cannot do animations on them and also, they slow down the code. Adding bitmaps will decrease the frameRate to like 10-15. Did you find any other way to get LATEX code into Processing?
Decreasing the framerate like that should not happen, unless you do something wrong like load the images in draw() or accidentally use way too large images.
If you feel adventurous and if you are disgruntled enough Processing can't do this already, you can try to implement the missing tags yourself.
The symbol tag defines a glyph with a specific path (shape) and a name.
The use tag places this glyph based on the symbol name somewhere on an x and an y coordinate.
https://www.w3.org/TR/SVG/struct.html#UseElement
This tells you how to read the path:
https://www.w3.org/TR/SVG/paths.html#DAttribute
Processing has this already implemented in its loadShape() method: https://github.com/processing/processing/blob/master/core/src/processing/core/PShapeSVG.java#L467
I'll let you figure out the rest.
@ayatana --
What does this mean? How can you "do animations" on SVG in ways that you can't on a transparent PNG file? Are you dynamically changing the contents of the SVG text and reloading it during a running sketch?
Once you load in an SVG you can have it as a PShape in the sketch, which is a collection of curves defined by points which positions you can change on runtime. I guess that is what OP is after.
Ah, that makes sense. I was thrown off by the example of typesetting a mathematical equation and wasn't imagining it in terms of dynamic typography.
i am surprised that they aren't using a third party library to parse and render svg files. there must be one. Batik for instance. (Ah, it says it uses Batik for writing).
I've seen a few things now that say they use svg for animation, the OP-1 for instance, but i'd've thought the final rendering of them would be overly expensive.
Mathjax is meant to be capable of going directly from Tex to svg but I haven't been able to try it and there's no guarantee that processing will parse the result.
Been there done that. Mathjax spits out a svg similar to the one I created and with the same problem. I am going mad now. Atleast, if Processing could prase MathML. That would have been great.