# Undefined control sequence \accentset when using todonotes package

I'm trying to use todonotes together with the accent package, but the following code:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{accents}
\usepackage{todonotes}

\begin{document}
\todo{$\accentset{\circ}{x}$}
\end{document}


gives the error:

! Undefined control sequence.
\accentset #1#2->\begingroup \def \cc@a
{#1}\let \math@bgroup \@empty \def \...
l.7 \todo{$\accentset{\circ}{x}$}


There seems to be a problem with using \accentset inside \todo, but I really don't know what is wrong. Any help would be appreciated!

You need to protect \accentset.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{accents}
\usepackage{todonotes}

\begin{document}
\todo{$\protect\accentset{\circ}{x}$}{$y$}
\end{document}


However, this is not specific to \todo, e.g. \section and the like have the same issue.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{accents}
\usepackage{todonotes}

\begin{document}
%\section{$\accentset{\circ}{x}$} % throws an error
\section{$\protect\accentset{\circ}{x}$}  % fine
%\todo{$\accentset{\circ}{x}$}{$y$} % throws an error
\todo{$\protect\accentset{\circ}{x}$}{$y$} % fine
\end{document}