1

This question already has an answer here:

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]
                       $]
? 

marked as duplicate by egreg, Mico, Romain Picot, user13907, user31729 Jan 26 '16 at 10:14

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

Consider protecting the argument passed to thm by wrapping it inside {...}:

enter image description here

\documentclass{article}

\usepackage{thmtools}
\usepackage{xargs}

\declaretheorem{thm}

\newcommandx{\R}[1][1]{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}

Not the answer you're looking for? Browse other questions tagged or ask your own question.