diff options
Diffstat (limited to 'Master/texmf-dist/tex/latex/emoji/emoji.sty')
-rw-r--r-- | Master/texmf-dist/tex/latex/emoji/emoji.sty | 66 |
1 files changed, 47 insertions, 19 deletions
diff --git a/Master/texmf-dist/tex/latex/emoji/emoji.sty b/Master/texmf-dist/tex/latex/emoji/emoji.sty index f010705cb4d..56f3a3c0a83 100644 --- a/Master/texmf-dist/tex/latex/emoji/emoji.sty +++ b/Master/texmf-dist/tex/latex/emoji/emoji.sty @@ -1,5 +1,5 @@ %% -%% Copyright (C) 2020 by Xiangdong Zeng <xdzeng96@gmail.com> +%% Copyright (C) 2020, 2021 by Xiangdong Zeng <xdzeng96@gmail.com> %% %% This work may be distributed and/or modified under the %% conditions of the LaTeX Project Public License, either @@ -16,7 +16,7 @@ %% The Current Maintainer of this work is Xiangdong Zeng. %% \NeedsTeXFormat{LaTeX2e}[2020/02/02] -\ProvidesExplPackage{emoji}{2020/06/27}{0.2.1}{Emoji support in (Lua)LaTeX} +\ProvidesExplPackage{emoji}{2021/07/17}{0.2.2}{Emoji support in (Lua)LaTeX} \msg_new:nnn { emoji } { require-luatex } { The~'emoji'~package~requires~LuaTeX. } @@ -25,13 +25,20 @@ \RequirePackage { fontspec } -% Set emoji font. Internally use fontspec's `\setfontface`. -% #1: option -% #2: name +% Set emoji font. When used in preamble, it will be delayed until the +% `\AtBeginDocument` hook. +% #1: name +% #2: option \NewDocumentCommand \setemojifont { m o } { \__emoji_if_preamble:TF - { \AtBeginDocument } + { + % The actual `\emoji_font:` command will be defined in the + % `\AtBeginDocument` hook, but it will precede our checking. + % So we need to "pretend" that it's defined. + \cs_set_eq:NN \emoji_font: \prg_do_nothing: + \AtBeginDocument + } { \use:n } { \IfValueTF {#2} @@ -49,6 +56,8 @@ } % Define `\emoji_font:` when used. +% #1: name +% #2: option \cs_new_protected:Npn \emoji_set_font:nn #1#2 { \setfontface \emoji_font: {#1} [ Renderer = HarfBuzz, #2 ] } \cs_new_protected:Npn \emoji_set_font:n #1 @@ -81,14 +90,6 @@ You~should~use~"\setemojifont"~to~set~a~font. } -% If the user doesn't set emoji font explicitly, then detect and set default -% fonts automatically. -\AtBeginDocument - { - \cs_if_exist_use:NF \emoji_font: - { \__emoji_detect_font: } - } - % The main command for use emoji. % #1: name \NewDocumentCommand \emoji { m } @@ -117,10 +118,12 @@ \cs_new_protected:Npn \emoji_print:n #1 { \group_begin: + \exp_args:Nv \__emoji_ltj_set_range:n { c__emoji_ #1 _tl } \emoji_font: \tl_use:c { c__emoji_ #1 _tl } \group_end: } +\cs_new_eq:NN \__emoji_ltj_set_range:n \use_none:n % Define new emoji. They are stored in tl constants internally. % For special characters (#), we first change their catcode to 12 (other), @@ -151,14 +154,17 @@ \cs_set:Npn \__emoji_subgroup:n #1 {} % Input the emoji definition file. -% This file is generated by a Python scripts from Unicode and GitHub data. +% This file is generated by a Python script from Unicode and GitHub data. \file_input:n { emoji-table.def } -% Compatibility with hyperref. -% `\emoji{...}` will be turned to a normal character sequence. +\cs_new_protected:Npn \__emoji_if_package_loaded:nT #1#2 + { \@ifpackageloaded {#1} {#2} {} } + \AtBeginDocument { - \@ifpackageloaded { hyperref } + % Compatibility with hyperref. + % `\emoji{...}` will be turned to a normal character sequence. + \__emoji_if_package_loaded:nT { hyperref } { \pdfstringdefDisableCommands { @@ -166,7 +172,29 @@ { \tl_use:c { c__emoji_ #1 _tl } } } } - {} + + % Compatibility with luatexja. + % Emoji should be "ALchar" so that the correct font can be used. + \__emoji_if_package_loaded:nT { luatexja } + { + \cs_set_protected:Npn \__emoji_ltj_set_range:n #1 + { + \tl_set:Nx \l_tmpa_tl + { \tl_map_function:nN {#1} \__emoji_encode_from_char:n } + % Range 4 means "characters usually not in Japanese fonts". + % `\ltjdefcharrange` does not accespt empty value, so we need to + % remove extra comma. + \exp_args:Nnx \ltjdefcharrange {4} { \tl_tail:N \l_tmpa_tl } + } + % 0-7F are always treated as an ALchar and can't be customized. + \cs_new:Npn \__emoji_encode_from_char:n #1 + { \int_compare:nNnF {`#1} < {"80} {,`#1} } + } + + % If the user doesn't set emoji font explicitly, then detect and set default + % fonts automatically. + \cs_if_exist:NF \emoji_font: + { \__emoji_detect_font: } } \endinput |