I'd like to use tcolorbox to call a theorem environment. My tcolorbox is supposed to ask for an optional title, and a mandatory label, so in the xparse specification I chose O{}m. Then, in the definition I use
before upper={\begin{thm}[#1]\label{#2}},
which works great when the title is defined... but unfortunately when no title are defined this fails with error
Undefined control sequence.
\ll@thm ...t \thmtformatoptarg {\thmt@shortoptarg
}\fi
l.54 \begin{theorem}{thm:mygreatlabel}
I guess because the thm environment does not accept an empty optional argument like \begin{thm}[] ... \end{thm}. I tried to add conditions, but the brackets are considered as real characters, so I don't know how to solve this problem.
Thanks!
MWE:
\documentclass{article}
\usepackage{mathtools}
\usepackage{amssymb, amsthm, amsmath}
\usepackage{thmtools} %%
\usepackage{hyperref}
\newtheorem{thm}{Theorem}[section]
\providecommand*\thmautorefname{Theorem}
\newtheorem{corollary}[thm]{Corollary}
\providecommand*\corollaryautorefname{Corollary}
\newtheorem{lemma}[thm]{Lemma}
\providecommand*\lemmaautorefname{Lemma}
\usepackage{lipsum}
\usepackage[most]{tcolorbox}
% \tcbset{customTheorem/.style={
% }
\NewTColorBox[auto counter, number within=section]{theorem}{O{}m}{ %
blank,
breakable,
before upper={\begin{thm}[#1]\label{#2}},
after upper={\end{thm}{\itshape See \hyperref[proof:#1]{proof} on page~\pageref{proof@\thetcbcounter}}},
lowerbox=ignored,
savelowerto=theorem-\thetcbcounter.tex,
record={\string\myproof{\thetcbcounter}{theorem-\thetcbcounter.tex}{#2}},
% #1
}
\NewTotalTColorBox{\myproof}{mmm}{ %
blank,
breakable,
before upper={\begin{proof}[Proof of \autoref{#3}]\label{proof:#3}},
after upper={\end{proof}},
phantomlabel={proof@#1},
}{\input{#2}}
% \tcbset{no proof/.style={no recording,after upper=\end{thm}}}
\begin{document}
\section{Some theorems}
\tcbstartrecording % [theoremsamazing.records]
\begin{theorem}[My title]{thm:mygreatlabel}
This theorem works
\tcblower
Proof is super obvious
\end{theorem}
\begin{theorem}{thm:mygreatlabel}
This fails because the environment thm does not accept empty brackets.
\tcblower
Proof is not super obvious
\end{theorem}
See, I can refer to \autoref{thm:mygreatlabel}!
\lipsum[2]
\tcbstoprecording
\section{Some amazing theorems}
\tcbinputrecords
\end{document}
IfNoValueOrEmptyTF, but all the functions I found needed backslash that seems to be not recognized... – tobiasBora Apr 11 '19 at 12:24before upper=\IfNoValueOrEmptyTF{#1}{...}{...}– tobiasBora Apr 11 '19 at 12:31