This is a follow up question to this comment. How can I make campa's code for TeXbook's bend symbol work with the theorem environment?
Consider the following LaTeX code which I saved in a file called test.tex:
\documentclass{scrartcl}
\usepackage{tikz}
\newenvironment{mydanger}[1]{%
\sbox0{%
\begin{tikzpicture}[scale=.3]
\draw[rounded corners=.1] (-.05,-1.5)--++(0,2.55)--++(.1,0)--++(0,-2.55);
\draw[fill=white,rounded corners=1] (0,1)--(1,0)--(0,-1)--(-1,0)--cycle;
\draw[very thick](-.3,-1.5)--(.3,-1.5);
\node at (0,0) {\small#1};
\end{tikzpicture}
}% this space ^^^ is here for a reason!
\par\medskip \noindent
\hangindent\wd0
\parindent\hangindent
\hangafter=-2
\setbox0=\hbox to0pt{\hss\lower3ex\box0}%
\dp0=0pt
\box0
\small
\ignorespaces
}{\par\smallskip}
\newtheorem{theorem}{Theorem}
\usepackage{lipsum}
\begin{document}
\begin{mydanger}{A}
\lipsum[1]
\end{mydanger}
\vspace{1cm}
\begin{mydanger}{A}
\begin{theorem}
\lipsum[1]
\end{theorem}
\end{mydanger}
\end{document}
When I run this code with lualatex test, the following output is typeset:
I'd like the theorem paragraph to flow around the bend symbol like the regular paragraph above it.
Important requirement
The solution must be consistent with the possibility of adding margin notes via \marginpar inside the theorem. Therefore, for instance, a solution that encapsulates the theorem inside an invisible tcolorbox will not be an acceptable solution; see here.


\meaningto analyze the command. Just forgot about it, you can simply delete it in the document body. – Alan Xiang Jul 18 '21 at 13:56\mydangercommand in the body of the document, causes the compilation to fail with the error messageunable to patch command. Unfortunately, I don't have the time currently to debug it. – Evan Aad Jul 19 '21 at 08:54\patchcmddoesn't work, you can simply extract the definition of\@begintheoremand manually redefine it with\renewcommand– Alan Xiang Jul 19 '21 at 20:42\patchcmddoesn't not work because of some changes to the definition of\theorem. – Alan Xiang Jul 21 '21 at 22:21