# Command … unavailable in encoding EU1 when using unicode-math

Because I cannot be dependent on a particular package (drm), I need to emulate it as best as possible, which works fine until I decide to load unicode-math. Please consider this MWE which is cut so it only shows the error:

\documentclass{article}
%\usepackage{fontspec}
\usepackage{unicode-math}
\newcommand*{\drmsym}[1]%
{\fontspec{drmsym10.otf}%
[SizeFeatures=%
{{Size={-7},Font=drmsym7.otf},
{Size={8},Font=drmsym8.otf},
{Size={9},Font=drmsym9.otf},
{Size={10-12},Font=drmsym10.otf},
{Size={12-14},Font=drmsym12.otf},
{Size={14-17},Font=drmsym14.otf},
{Size={17-24},Font=drmsym17.otf},
{Size={24-},Font=drmsym24.otf}}]%
{#1}}

\providecommand*{\textdied}%
{\drmsym{\char'144}}
\begin{document}
\textdied
\end{document}


When you compile this document using XeLaTeX you receive the error message Command \textdied unavailable in encoding EU1. When I decide not to load unicode-math and only load fontspec the code works as expected, which seems to indicate that the former package alters the fontencoding somewhere. Does anyone know how to solve this issue while retaining the unicode-math package?

You should use neither \fontspec nor \providecommand:

• using \fontspec is not recommended, because very inefficient;
• \textdied already has a definition as a TS1 command when unicode-math is loaded, so \providecommand does nothing
\documentclass{article}
\usepackage{fontspec}
\usepackage{unicode-math}

\newfontface{\drmfont}{drmsym10}[
Extension=.otf,
SizeFeatures={
{Size={-7.5},Font=drmsym7},
{Size={7.5-8.5},Font=drmsym8},
{Size={8.5-9.5},Font=drmsym9},
{Size={9.5-11},Font=drmsym10},
{Size={11-13},Font=drmsym12},
{Size={13-15},Font=drmsym14},
{Size={15-21},Font=drmsym17},
{Size={21-},Font=drmsym24}
}
]
\DeclareTextFontCommand{\drmsym}{\normalfont\drmfont}
\UndeclareTextCommand{\textdied}{TS1}
\DeclareRobustCommand{\textdied}{\drmsym{\symbol{'144}}}

\begin{document}

\textdied

\end{document}


I have changed the size choices, but it's not very important.

The \UndeclareTextCommand is used in order to avoid the original definition to kick in; \normalfont` ensures shape and weight parameters are reset, so in an italic or boldface context the symbol will print anyway.