I am using thmtools to create theorems, and I sometimes want the theorem name to include math symbols. In this particular project, I have used xargs to create a command that uses an optional argument, however, an error compiles whenever I attempt to pass the optional argument through for the theorem name.
I have included a MWE below:
\documentclass{article}
\usepackage{amsfonts}
\usepackage{thmtools}
\usepackage{xargs}
\declaretheorem{thm}
\newcommandx{\R}[1][1]{\mathbb{R}^{#1}}
\begin{document}
\begin{thm}[$\R$]
This theorem works.
\end{thm}
\begin{thm}[$\R[n]$]
This theorem does not work.
\end{thm}
\end{document}
Any ideas about what is causing this problem and how I can pass the argument through the theorem name?
In the log file, I get the following report:
! Argument of \\R has an extra }.
<inserted text>
\par
l.21 \begin{thm}[$\R[n]
$]
?
