In the following code, I want to produce a coloured shape, for example a \rule{1em}{1em}. If I use the \rule as is, it works as expected. However, putting it in an \sbox somehow breaks colouring and I get a black box.
\documentclass{standalone}
\usepackage{xcolor}
\newsavebox\myrule
\sbox\myrule{\rule{1em}{1em}}
\begin{document}
\color{red}
\usebox\myrule % this gives me a black square
\rule{1em}{1em} % this gives me a red square
\end{document}
Could someone kindly explain the reason for this behaviour? I know that the box could also be put in a macro definition instead, I'm just a bit confused why it doesn't work with \usebox. Moreover, is there some straightforward way to enable my \usebox\myrule to take on the current text colour, so that it can be basically be used like a usual glyph?
