# The best way for math in epub - font or SVG? (tex4ebook)

with some math as HTML it doesn't display well on some readers. How can I include a specific font to epub for this badly displayed math? Or is there any option to convert all math to picture (SVG)?

Regarding math, there are always some readers that doesn't do it well. And also other things. Some readers probably don't support svg (only really old, I hope). Some don't support css well.

Image math is always wrong, because different font than normal text is used (even if you add custom fonts, they may not be supported or turned off by the user), they may have different size, wrong baseline, etc. Correct solution is to use epub3 with mathml:

 tex4ebook -f epub3 filename "mathml"


the problem is that AFAIK no e-ink reader support epub3, only Ipad and some Android apps do. This is the chicken and egg problem, there is just few epub3 math ebooks, so there is no much demand for epub3 readers, and there is just few epub3 ebooks, because you can't read them.

if you really want to make epub with math as svg images, you can take inspiration from this question

Make a configuration file, myconfig.cfg:

 \Preamble{xhtml,pic-align,pic-m,}
\Configure{Picture}{.svg}
\makeatletter
\Configure{graphics*}
{svg}
{
{\Configure{Needs}{File: \Gin@base.svg}\Needs{}}
\Picture[\csname a:GraphicsAlt\endcsname]{\csname Gin@base\endcsname.svg
\csname a:Gin-dim\endcsname}
}
\begin{document}
\EndPreamble


and then a build file for efficient svg creation, named as your TeX file, but with .mk4 suffix:

Make:add("dvisvgm","dvisvgm -n -TS1.25,1.25 -c 1.2,1.2 -p 1- ${input}.idv") local max_count = 5 local image_format = "${input}-${zeroes}${page}.${ext}" local oneimage_format = "${input}.${ext}" local function file_exists(fn) local f = io.open(fn,"r") if f == nil then return false else f:close() return true end end local function locate_file(par,ext, count) local count = count or 0 par.ext = ext local zeroes = string.rep("0",count) par.zeroes = zeroes if count > max_count then local one = oneimage_format % par if file_exists(one) then return one else return false, "max_count exceeded" end end local fn = image_format % par if file_exists(fn) then return fn else return locate_file(par, ext, count+1) end end Make:htlatex{} Make:htlatex{} Make:htlatex{} Make:tex4ht{} Make:t4ht{} Make:dvisvgm{} Make:image("svg$",function(arg)
arg.input = arg.source:gsub(".idv$","") local fn,msg = locate_file(arg, "svg") if not fn then print("Image processing error: "..msg) else arg.filename = fn local cmd = "mv${filename} \${output}" % arg
print(cmd)
os.execute(cmd)
end
end
)


description of the build file is in this answer of mine.

Now compile with:

tex4ebook -c myconfig.cfg filename