如何使定理环境围绕 campa 的代码流动以实现 TeXbook 的弯曲符号?

如何使定理环境围绕 campa 的代码流动以实现 TeXbook 的弯曲符号?

这是一个后续问题此评论。如何让 campa 的 TeXbook 弯曲符号代码与环境协同工作theorem

请考虑以下我在名为的文件中保存的 LaTeX 代码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}

当我使用 运行此代码时lualatex test,将排版以下输出:

布尔巴基弯曲符号与定理环境

我希望定理段落能够像其上方的常规段落一样围绕弯曲符号流动。


重要要求

\marginpar解决方案必须与在定理内部添加边注的可能性相一致。因此,例如,将定理封装在不可见部分中的解决方案tcolorbox将不是可接受的解决方案;参见这里

答案1

theorem这是一个相当 hack 的解决方案。使用的实现trivlist,它开始一个新行。基本上我所做的就是使用\patchcmd来删除trivlist并重新定义\item命令以确保输出一致。

在此处输入图片描述

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

相关内容