7

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:

Bourbaki's bend symbol with the theorem environment

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.

2
+50

This is a rather hacking solution. The implementation of theorem uses trivlist, which starts a new line. Basically what I did is to use \patchcmd to remove trivlist and redefine the \item command to make sure the output is consistent.

enter image description here

\documentclass{scrartcl}
\usepackage{tikz}
\usepackage{etoolbox}

\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}

\makeatletter
\patchcmd{\@begintheorem}{\trivlist\item}{\bgroup\myitem}{}{\GenericError{}{unable to patch command}{}{}}

\patchcmd{\@opargbegintheorem}{\trivlist\item}{\bgroup\myitem}{}{\GenericError{}{unable to patch command}{}{}}

\def\@endtheorem{\egroup}
\def\@opargendtheorem{\egroup}
\def\myitem[#1]{#1~}
\makeatother



\begin{document}


\begin{mydanger}{A}
\lipsum[1]
\end{mydanger}

\vspace{1cm}

\begin{mydanger}{A}
\begin{theorem}
\lipsum[1]
\end{theorem}
\end{mydanger}

\begin{mydanger}{B}
\begin{theorem}[Test Theorem]
\lipsum[1]
\end{theorem}
\end{mydanger}

\end{document}
\documentclass{scrartcl}
\usepackage{tikz}
\usepackage{etoolbox}
\usepackage{adjustbox}

\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}
     \hspace*{3mm}
  }%       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}

\makeatletter
\patchcmd{\@begintheorem}{\trivlist\item}{\bgroup\myitem}{}{\GenericError{}{unable to patch command}{}{}}
\patchcmd{\@opargbegintheorem}{\trivlist\item}{\bgroup\myitem}{}{\GenericError{}{unable to patch command}{}{}}

% also remove the spacing before Theorem
\patchcmd{\@begintheorem}{\hskip\labelsep}{}{}{\GenericError{}{unable to patch command}{}{}}
\patchcmd{\@opargbegintheorem}{\hskip\labelsep}{}{}{\GenericError{}{unable to patch command}{}{}}

\def\@endtheorem{\egroup}
\def\@opargendtheorem{\egroup}
\def\myitem[#1]{\noindent {#1}~}
\makeatother



\begin{document}

\makeatletter
\meaning\@begintheorem
\makeatother

\begin{mydanger}{A}
\lipsum[1]
\end{mydanger}

\vspace{1cm}

\begin{mydanger}{A}
\begin{theorem}
\lipsum[1]
\end{theorem}
\end{mydanger}

\begin{mydanger}{B}
\begin{theorem}[Test Theorem]
\lipsum[1]
\end{theorem}
\end{mydanger}

\end{document}
9
  • Thank you. I can't test it right now, since I'm not near a computer with a TeX installation. One thing, though. In your solution tthe text flows jaggedly round the sign. Compare this to the way the paragraph flows evenly round the sign in the TeXbook, here, Could you emulate this even flow?
    – Evan Aad
    Jul 16 at 16:17
  • 1
    I also included a second version below, which emulates the TeX book layout.
    – Alan Xiang
    Jul 16 at 17:08
  • Thank you! I'll test it tomorrow.
    – Evan Aad
    Jul 16 at 18:07
  • Why does the second piece of code print a strange first line?
    – Evan Aad
    Jul 18 at 9:10
  • 1
    I used \meaning to analyze the command. Just forgot about it, you can simply delete it in the document body.
    – Alan Xiang
    Jul 18 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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