You can emulate what basically utf8
does:
\documentclass{article}
\usepackage{newunicodechar}
\usepackage{xparse}
\ExplSyntaxOn
\newunicodechar{π©}{\flags_D:n}
\newunicodechar{πΊ}{\flags_U:n}
\cs_new_protected:Nn \flags_D:n
{
\str_case:nnF { #1 }
{
{πͺ}{Germany}
{π°}{Denmark}
}
{BAD}
}
\cs_new_protected:Nn \flags_U:n
{
\str_case:nnF { #1 }
{
{π°}{United~Kingdom}
{πΈ}{United~States}
}
{BAD}
}
\ExplSyntaxOff
\begin{document}
Here is π©πͺ
Here is π©π°
Here is πΊπ°
Here is πΊπΈ
\end{document}

A version that works also with pdflatex
(weird errors are to be expected if regional indicator symbols not appear in pairs.
\documentclass{article}
\usepackage{ifxetex}
\ifxetex\else
\usepackage[utf8]{inputenc}
\fi
\usepackage{newunicodechar}
\usepackage{xparse}
\ExplSyntaxOn
\newunicodechar{π©}{ \flags_print:n {D} }
\newunicodechar{πΊ}{ \flags_print:n {U} }
\bool_if:nTF { \sys_if_engine_luatex_p: || \sys_if_engine_xetex_p: }
{
\cs_new:Nn \flags_print:n
{
\flags_print_unicode:nn { #1 }
}
}
{
\cs_new:Nn \flags_print:n
{
\peek_charcode:NTF ^^f0
{
\flags_print_eightbit:nnnnn { #1 }
}
{
BAD
}
}
}
\cs_new_protected:Nn \flags_print_unicode:nn
{
\use:c { flags_#1:n } { #2 }
}
\cs_new_protected:Nn \flags_print_eightbit:nnnnn
{
\use:c { flags_#1:n } { #2#3#4#5 }
}
\cs_new_protected:Nn \flags_D:n
{
\str_case:nnF { #1 }
{
{πͺ}{Germany}
{π°}{Denmark}
}
{BAD}
}
\cs_new_protected:Nn \flags_U:n
{
\str_case:nnF {#1}
{
{π°}{United~Kingdom}
{πΈ}{United~States}
}
{BAD}
}
\ExplSyntaxOff
\begin{document}
Here is π©πͺ
Here is π©π°
Here is πΊπ°
Here is πΊπΈ
\end{document}
It would be possible to add a check on the next character also for Unicode engines, but it seems more crucial for pdflatex
.
\newcommand\DE{..}
do you need to use a form with no backslash? (which is easy of you do not use capital letters for anything else, harder otherwise. – David Carlisle Feb 22 '16 at 7:38\DeclareUnicodeCharacter
or\newunicodechar
to make it "directly" available, but I also define a macro. So the german flag for example is already accessible via\emojiflagde
. But I think it would be confusing for the users if the flags are only available via a TeX command, but every other symbol works directly. – Benjamin Feb 22 '16 at 7:46