I've modified answer of this post for new blocks as follow but when I put an displayed equation as first line it produce error Extra }, or forgotten $. ^^I\end{frame} and when I put it after an empty line the error goes away. What exactly is the problem?
What I figured out this problem is related to Copenhagen theme!
P.s. 1 Mathematical align environment produce a different error!
P.s. 2 usual block has no such problem!
\documentclass[]{beamer}
\usetheme{Copenhagen}
\newenvironment<>{theorem}[2][Theorem]{%
\setbeamercolor{block title}{fg=white,bg= red!90!blue}%
\begin{block}{#1}#3{#2}}{\end{block}}
\begin{document}
\begin{frame}
\begin{theorem}
this is OK!
\end{theorem}
\begin{theorem}%<-- error
\[x^2=y^2+z^2\]
\end{theorem}
\begin{theorem}%<-- OK
\[x^2=y^2+z^2\]
\end{theorem}
\begin{block}{theorem}%<-- OK
\[x^2=y^2+z^2\]
\end{block}
\end{frame}
\end{document}
My goal is to have an theorem block with one optional argument when is not empty this become the block title something like as follow:
\begin{theorem}
\[x^2=y^2+z^2\]
\end{theorem}
\begin{theorem}[MY TITLE]
\[x^2=y^2+z^2\]
\end{theorem}



theoremenv take two arguments on one optional and one mandatory. And you are not giving the mandatory one – daleif Mar 21 '23 at 10:14\newenvironment<>{theorem}[2][Theorem]the[2]says this takes two arguments.[Theorem]says the first is optional. – daleif Mar 21 '23 at 10:22Copenhagentheme is not related. (2) if you use\begin{theorem}{test}the it compiles just fine. Your problem with not specifying the mandatory arg is thatbegin{theorem}then tries to use\[as its argument and then math fails. You might just want to change[2]to[1]– daleif Mar 21 '23 at 10:24[1], where did that[2]come from? – daleif Mar 21 '23 at 10:25[2]and just using linked post? – C.F.G Mar 21 '23 at 10:26