When I include a svg as an image, the text in the svg is correctly rendered as set in my document. But if I add “$” before and after the text, it is not rendered in math mode, but the “$” are shown as normal. Is it possible to add math to svgs?
Hey, when saying “the text is rendered as set” you are talking about the text attributes like font family or size?
The math rendering is likely not being applied because Typst handles the SVG still as an encapsulated and immutable image type.
The reason why the text attributes take effect are that the text is being embedded in the SVG as string-element and Typst renders it in the documents context.
You could try “insert” just the math-piece into your image, f.e. by placing the math over the image.
Or you create the math with your vector image program.
But i guess the most accurate solution would be using a package like CeTZ to create your diagram.
Yes, by set I mean font, size etc. I was hoping this was possible, as using CeTZ is (imo) magnitudes slower than something like InkScape. I’ll investigate just placing math over the image, that could be a compromise.
Thank you for your answer :)
I have been using the following two alternative solutions.
-
Add math formulae in Inkscape
TexText - Re-editable LaTeX and typst graphics for Inkscape. It is an open-source 18-year-old python extension supporting both LaTeX and Typst.
-
CeTZ overlay
Replace
image(…)
with{image(…); place(cetz.canvas(…))}
. Itplace
s thecanvas
over the image.Details
- Fix the
width
of theimage
. - Adjust
dx
,dy
of theplace
, so that the grid is aligned with the top-left corner of the image. - (Optional) Change the
length
ofcetz.canvas
and the coordinates ofgrid
as you wish. - Add
stroke: none
togrid
. - Draw here.
#figure( { image(…, width: 2em) import "@preview/cetz:0.3.1" set math.equation(numbering: none) place( top + left, dx: 0.5em, dy: 0.5em, cetz.canvas( length: 5em, { import cetz.draw: * // Define the plot range grid((-2, -2), (2, 2), step: 1) // Draw here content(…, $…$) }, ), ) }, caption: […], )
- Fix the
Hope they help!