0

I want to enable the unicode modifiers for an emoji library:

apple_emoji.sty:

\usepackage{graphicx,amsmath,xparse}
\usepackage[utf8x]{inputenc}
\usepackage[export]{adjustbox}

\ProvidesPackage{apple_emoji}

\NewDocumentCommand{\privateAppleEmoji}{m G{}}
 {%
  \text{%
    \includegraphics[height=1.5em,valign=B,raise=-0.2em]{result/#1#2.png}%
  }%
 }

\DeclareUnicodeCharacter{128512}{\privateAppleEmoji{1F466}}
\DeclareUnicodeCharacter{127999}{{1F3FE}}

main.tex:

\documentclass [a4paper,12pt]{book}
\usepackage{apple_emoji}

\begin{document}
😀\privateAppleEmoji{1F466}{1F3FE}😀🏿

\end{document}

but with DeclareUnicodeCharacter it doesn't take the second argument

result

14
  • Related: github.com/alecjacobson/coloremoji.sty Jun 6, 2016 at 13:40
  • \DeclareUnicodeCharacter{127999}{{1F3FE}} just declares the character to make the text {1F3FE} so you get the output that you show. You could make the replacement text the unicode character or a call to includegraphics Jun 6, 2016 at 13:46
  • I answered but deleted as I decided I didn't understand the question but \DeclareUnicodeCharacter requires the first argument in hex not decimal so you need \DeclareUnicodeCharacter{1F600}{....} Jun 6, 2016 at 14:00
  • @Davide if I write \DeclareUnicodeCharacter{1F600} it gives me error, with the unicode codepoint in decimal it works but the macro is interpreted before the next character is decoded
    – DPD-
    Jun 6, 2016 at 14:02
  • @Henri that library doen't support modifiers
    – DPD-
    Jun 6, 2016 at 14:08

1 Answer 1

2

I don't have the images to test so I made a 1F466.png and 1F4661F3FF.png (your character was U+1F3FF, handling U+1F3FE would be similar)

here I define the macro attached to the base character to look ahead, if it sees the first byte of a 4 byte UTF8 sequence for the range of these modifiers (which is F0) then it grabs all four bytes and then either uses the alternative image if they match the uTF8 for the modifier, or uses the base emoji and just typesets the four bytes if not.

enter image description here

\documentclass [a4paper,12pt]{book}
\usepackage{graphicx,amsmath}
\usepackage[utf8]{inputenc}
\usepackage[export]{adjustbox}



\makeatletter

\def\privateAppleEmoji#1{%
 \def\baseemoji{#1}%
 \pae}

\edef\modifierbyteone{\noexpand\UTFviii@four@octets\string^^f0}
\edef\moifierlastthreebytes{\string^^9f\string^^8f\string^^bf}

\def\pae{\futurelet\tmp\paex}

\def\paex{%
\ifx\tmp\modifierbyteone
 \expandafter\getnextthreebytes
 \else
  \z\baseemoji{}%
\fi
  }

\def\getnextthreebytes#1#2#3#4{%
  \edef\tmpb{\string#2\string#3\string#4}%
  \ifx\tmpb\moifierlastthreebytes
     \z\baseemoji{1F3FF}%
  \else
     \z\baseemoji{}\modifierbyteone#2#3#4%
  \fi}


\def\z#1#2%
 {%
  \text{%
    \includegraphics[height=1.5em,valign=B,raise=-0.2em]{result/#1#2.png}%
  }%
 }

\makeatother

\DeclareUnicodeCharacter{1F600}{\privateAppleEmoji{1F466}}
\DeclareUnicodeCharacter{1F3FF}{{1F3FF}}


\begin{document}
😀
\privateAppleEmoji{1F466}🏿
😀🏿

\end{document}

Note in the middle case even though the base is given by a macro with argument the modifier must be given as a character.

2
  • Perfetto funziona, grazie mille: non sapevo si potesse leggere direttamente i byte
    – DPD-
    Jun 6, 2016 at 18:22
  • @DPD- you have to read the bytes separately: pdftex has no knowledge of Unicode or utf8 😀 is just a sequence of four characters, not a single token. Jun 6, 2016 at 18:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .