Is there a general way to find the depth of a macro evaluation? For example, consider the following script,
\documentclass{beamer}
\usepackage{mathtools}
\usepackage{calc}
\begin{document}
\begin{frame}
\newcommand*{\ofSize}[2]{\hphantom{####2}\llap{####1}}
x \alt<1>{\ofSize{apples}{oranges}}{oranges} \uncover<1-2>{done.}
\end{frame}
\end{document}
I wanted to alternate between two expressions so that it would not cause surrounding text to move around during animations, with a more general solution then that given in Animated equation in Beamer. As you can see, I needed to escape the first argument, #1, three more times (####1) to get this to work.
The process I used was arbitrary; I just added # till it stopped giving me an error. Clearly, this could fail with horrendous side-effects if #1 is a meaningful expansion in a "deeper" nested macro level. Is there a best practice / methodology when writing such commands?
#. – percusse Jun 12 '13 at 07:47beamerreads the frame's contents as an argument, which makes####into##; then it sees a definition in this argument and by general rules this wants##instead of#. It's really better to put such\newcommandinstructions in the preamble. – egreg Jun 12 '13 at 07:54