You could use the svg
package, which does exactly what the svg-inkscape
documentation describes.
\documentclass[12pt]{article}
\usepackage{svg}
\setsvg{inkscape=inkscape -z -D,svgpath=fig/}
\begin{document}
\begin{figure}
\centering
\includesvg[width=0.5\textwidth]{my-figure}
\end{figure}
\end{document}
Now all you need to do is save your images as svg files and pdflatex
does the rest for you.
Important: Compile this with the --shell-escape
flag, e.g. pdflatex --shell-escape my-book.tex
. Have a look at this answer which may help you add this option. (TeXstudio is/was a Texmaker fork.)
A couple of points:
inkscape=inkscape -z -D
makes inkscape export the the svg drawing, not the whole page. Change it to inkscape=inkscape -z -C
if you want to export the whole page (or just remove it - it's the default behaviour).
svgpath=fig/
is the directory containing your figures. Change this as appropriate, but do not remove the trailing /
.
I take it upon myself to answer this question, based on Martin's comments and my own research.
Yes, the conversion from .dvi to non-outlined .svg is feasible. The best tool for the job is dvisvgm
by Martin Gieseking, but it works best with XeTeX. Running the XeTeX-generated .xdv file through dvisvgm
, one obtains an .svg file with embedded fonts. By deleting the preamble specifying the embedded font, and properly renaming the fonts within the .svg file, one obtains the desired result.
Except for one thing: XeTeX utilizes some glyphs which are not mapped to unicode characters directly. Specifically, this applies to big operators, which have different glyphs for \displaystyle
and \textstyle
. The \displaystyle
glyphs are "hidden" within the font. In theory, it is possible to access these glyphs from SVG using, e.g., the <glyphRef>
tag. But almost no major browsers support this feature.
The simplest and safest solution to this problem seems to be to edit the font file, and give an explicit unicode mapping to the display style glyphs. This way, the .svg file given by dvisvgm
can be used with the modified font to display math equations on the web.
Sample python script for mapping unencoded glyphs to the PUA area starting with 0xF0000, using the FontTools/TTX library:
fontFile = "C:\\Windows\\Fonts\\xits-math.otf"
outFile = "C:\\Windows\\Fonts\\xits-mod-math.otf"
font = ttLib.TTFont(fontFile,
allowVID=False,
checkChecksums=False,
recalcBBoxes=False,
recalcTimestamp=True,
lazy=True)
font['cmap']; #Load the cmap table into font.tables
all_glyphs = font.getGlyphOrder()
for i, subtable in enumerate(font.tables['cmap'].tables):
if subtable.format == 12:
encoded_glyphs = subtable.cmap.values()
unencoded_glyphs = [g for g in all_glyphs if g not in encoded_glyphs]
charcodes = range(0xF0000, 0xF0000 + len(unencoded_glyphs))
new_cmap = dict(zip(charcodes, unencoded_glyphs))
font.tables['cmap'].tables[i].cmap.update(new_cmap)
font.save(outFile, False, False)
Beware that the script overwrites possible existing mappings in the PUA area. A more complicated script can take care of this as well. And only mappings in cmap format 12 are added, it would probably make sense to add mappings to format 10 and 8 as well, if they are present in the font.
Best Answer
I had this problem as well. I was able to fix it defining the path to inkscape.