I'm typsetting emojis in xetex and I found this great library called xelatexemoji (on github). But when I use different fonts, the spacing around the included graphic changes. As I've seen in various responses, spacing changes with the font. I understand that. Here's a MWE:
\documentclass[12pt]{article}
\usepackage{graphicx}
\usepackage{fontspec}
\usepackage{xltxtra}
\usepackage{xelatexemoji}
\begin{document}
\setlength{\parindent}{0cm}
\textrm{Hello world}\\
\setmainfont{Times New Roman}
\textrm{Hello world}\\
\end{document}
Output
Notice how for the first font (default, Latin Modern I think), the spacing is fine, but when the font is changed, the spacing is wrong. (The spacing for the letters doesn't even look that different, but the included graphics spacing is!)
If you look at xelatexemoji.sty, they use \newunicodechar, which works fine, but the spacing around the inserted graphic needs to be adjusted. Snippet:
\usepackage{newunicodechar}
\usepackage{amsmath}
\providecommand{\xelatexemojipath}[1]{images/#1.pdf}
\newcommand{\xelatexemoji}[1]{
\hspace{-1em}
\raisebox{-0.15em}{
\includegraphics[height=1em]{\xelatexemojipath{#1}}
}
\hspace{-1em}
}
...
\newunicodechar{}{\xelatexemoji{1f61c}}
I tried adjusting the \hspace in the command to account for this in the second font, but look what happens when I recompile:
Is there a way to determine:
- What the currently assigned font is
- Query the properties of that font to find the relevant spacing value so that I can dynamically adjust for it by doing a bit of math in the command
I know that I could hardcode the \hspace values for each individual font I plan on using, but I'd like to make this robust. Any ideas?



xelatexemojipackage doesn't seem to be on the CTAN, and hence it isn't distributed with TeXLive. Is the package available online somewhere? – Mico May 28 '16 at 18:58%from the ends of all the lines of your definition you are inserting 6 inter word spaces for each command. – David Carlisle May 28 '16 at 20:17\\. – cfr May 28 '16 at 20:25\RequirePackage{graphicx}, too. – cfr May 28 '16 at 20:26\newunicodecharso I have at least one font with them (Segoe UI I think) – David Carlisle May 28 '16 at 20:51