Consider the following LaTeX code:
\documentclass{scrartcl}
\usepackage{scrlayer-scrpage,scrlayer-notecolumn}
% The rest of the preamble is taken from
% https://tex.stackexchange.com/a/421866/21685
\usepackage{amsmath,accents}
\newcommand{\genericmathaccent}[2]{%
\vbox{\offinterlineskip\ialign{%
##\cr
\hidewidth$\scriptstyle#1$\hidewidth\cr
\noalign{\kern-.5ex}
$#2$\cr}%
}%
}
\newcommand{\genericmathaccenti}[2]{%
\genericmathaccent{#1{}}{#2}%
}
\newcommand{\gravedot}[1]{\genericmathaccenti{\grave}{#1}}
\begin{document}
$\gravedot{a}$%
\makenote{$\grave{a}$}
%\makenote{$\gravedot{a}$}
\end{document}
It compiles successfully (I use LuaLaTeX), and produces the following typeset output:
However, when I move the last %
symbol to the line preceding it:
%\makenote{$\grave{a}$}
\makenote{$\gravedot{a}$}
compilation fails, and the following error message appears in the log file:
! Illegal parameter number in definition of \reserved@a.
<to be read again>
\cr
l.21 \makenote{$\gravedot{a}$}
?
! Emergency stop.
<to be read again>
\cr
l.21 \makenote{$\gravedot{a}$}
End of file on the terminal!
What causes the error? How can it be fixed?
\protect\gravedot
when in a moving argument such as\makenote
, or use\DeclareRobustCommand{\gravedot}{...}
instead of\newcommand
.