0

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:

makenote with a mathematical accent

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?

1
  • 2
    Either \protect\gravedot when in a moving argument such as \makenote, or use \DeclareRobustCommand{\gravedot}{...} instead of \newcommand.
    – egreg
    Jul 14, 2021 at 12:33

1 Answer 1

1

Per egreg's comment, the issue can be fixed by defining the \gravedot command using \DeclareRobustCommand rather than with \newcommand:

\newcommand{\genericmathaccent}[2]{%
  \vbox{\offinterlineskip\ialign{%
    ##\cr
    \hidewidth$\scriptstyle#1$\hidewidth\cr
    \noalign{\kern-.5ex}
    $#2$\cr}%
  }%
}
\newcommand{\genericmathaccenti}[2]{%
  \genericmathaccent{#1{}}{#2}%
}
\DeclareRobustCommand{\gravedot}[1]{\genericmathaccenti{\grave}{#1}}

I've tested this solution, and it indeed works.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .