Emoji in DVI? (dvilualatex, dvisvgm and twemojis)

dvidvisvgmincludegraphicsluatex

Motivation

I want to use emojis in Manim, an animation software which uses LaTeX for rendering in the background. The pipeline is:

  1. generate a TeX file
  2. run dvilualatex on it to convert it to DVI
  3. 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

  1. Download the twemojis package: https://mirrors.ctan.org/macros/latex/contrib/twemojis.zip
  2. Unzip it, go to ./pdf-twemojis and choose one emoji – for example 1f622.pdf
  3. Convert it to EPS using pdftops -level3 -eps 1f622.pdf 1f622.eps
  4. 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}
  1. Convert it to DVI using dvilualatex example.tex
  2. Convert it to SVG using dvisvgm example.dvi
  3. The resulting file has a weird space:
    SVG output

.

This seems to be a problem with dvilualatex, not dvisvgm. Viewing the DVI file in Okular produces a similarly broken result:
DVI in Okular

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:

enter image description here

\documentclass[preview]{standalone}
\usepackage[T1]{fontenc}
\usepackage[dvisvgm]{graphicx}
\setlength\fboxrule{1sp}
\begin{document}
Hello \fbox{\includegraphics[height=\baselineskip]{1f622.eps}} world.
\end{document}
Related Question