Motivation
I want to use emojis in Manim, an animation software which uses LaTeX for rendering in the background. The pipeline is:
- generate a TeX file
- run
dvilualatex
on it to convert it to DVI - run
dvisvgm
to convert the DVI to SVG
I found out that the twemojis package imports a PDF for each emoji. While PDF cannot be imported directly, it is easy to batch-convert all the emojis to EPS, so this sounds like a reasonable approach. However, it is not as simple as it might seem – for some reason, the spacing around the imported EPS files have really weird spacing around them.
Step-by-step reproduction
- Download the twemojis package: https://mirrors.ctan.org/macros/latex/contrib/twemojis.zip
- Unzip it, go to
./pdf-twemojis
and choose one emoji – for example1f622.pdf
- Convert it to EPS using
pdftops -level3 -eps 1f622.pdf 1f622.eps
- Create a minimal
example.tex
file:
\documentclass[preview]{standalone}
\usepackage[T1]{fontenc}
\usepackage[dvisvgm]{graphicx}
\begin{document}
Hello \includegraphics[height=\baselineskip]{./1f622.eps} world.
\end{document}
- Convert it to DVI using
dvilualatex example.tex
- Convert it to SVG using
dvisvgm example.dvi
- The resulting file has a weird space:
.
This seems to be a problem with dvilualatex
, not dvisvgm
. Viewing the DVI file in Okular produces a similarly broken result:
The entire source folder of this example is available here.
Question
What is causing this weird spacing and how do I get rid of it? I could just place a large negative space after every emoji, but it feels very hacky and likely to break once I change the size of the font or the environment (eg. to equation
or align
).
Best Answer
The preview calculation appears off. If you surround it with
\fbox
to debug the size it works, even if you make the fbox rule invisibly thin: