我想为表情符号库启用 unicode 修饰符:
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}}
主要.tex:
\documentclass [a4paper,12pt]{book}
\usepackage{apple_emoji}
\begin{document}
答案1
我没有图像可以测试,所以我制作了 1F466.png 和 1F4661F3FF.png(你的角色是 U+1F3FF,处理 U+1F3FE 会类似)
在这里我定义了附加到基本字符的宏来提前查看,如果它看到这些修饰符范围的 4 字节 UTF8 序列的第一个字节(即 F0),那么它会抓取所有四个字节,然后如果它们与修饰符的 uTF8 匹配则使用替代图像,如果不匹配则使用基本表情符号并仅排版四个字节。
\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}