# Why is \scshape not changing in XeLaTeX?

I'm trying to alter \scshape in XeLaTeX, but for some reason, three reasonable attempts (xpatch, \def, and \renewcommand) seem to have no effect whatsoever (only in XeLaTeX). A nonworking example is below (note that the 5 em space is just to make it clear when the redefinition is working, and obviously not intended for use in a real document):

\documentclass{article}
\usepackage{xpatch}
\xapptocmd{\scshape}
{\spaceskip=5em}
{}{}
%\let\myscshape\scshape
%\def\scshape{\spaceskip=5em\myscshape}
%\renewcommand{\scshape}{\myscshape\spaceskip=5em}

\begin{document}
\noindent\textsc{Test thing test}\\
\scshape Test thing test\\
\scshape\spaceskip=5em Test thing test
\end{document}

• The given code doesn't change anything in lualatex either. \scshape might be protected. If you append to a hook (parameterless macro), \appto{\xscshape}{\spaceskip=5em >>\color{red}}, it works; if you append to an unprotected macro, \newcommand\xscshape{\scshape}\xapptocmd{\xscshape} {\spaceskip=5em >>\color{red}} {}{}, it also works. The prepends also work. If you pre/append to a command (=parametered macro, like \textsc), the replacement text is per/appended to as expected. Jun 24 at 3:39

Do the patch at begin document.

\documentclass{article}
\usepackage{xpatch}
\usepackage{fontspec}

\AtBeginDocument{%
\xapptocmd{\scshape}
{\spaceskip=5em}
{}{}%
}

\begin{document}

\textsc{Test thing test}

\scshape Test thing test

\end{document}


• Brilliant—many thanks! Jun 24 at 15:14
• Out of intellectual curiousity, why does using \AtBeginDocument make it work? Jun 24 at 15:15
• @ezgranet A great part of font setup is done at begin document; different font packages may have different ideas about how to realize small caps. Jun 24 at 15:47
• thank you—very interesting. Jun 24 at 16:57