将自定义环境的参数作为定理的参数传递

将自定义环境的参数作为定理的参数传递

我想创建一个快捷方式

\begin{sometheorem}[optional parameter]
    \leavevmode \vspace{-\baselineskip}\vspace{-\baselineskip}\vspace{3pt} %some space adjustments
    \begin{leftbar}
        some text
    \end{leftbar}
\end{sometheorem}

所以我尝试了:

\newenvironment{defi}[1]
{
\begin{definition}[#1]
\leavevmode \vspace{-\baselineskip}\vspace{-\baselineskip}\vspace{3pt}
\begin{leftbar}\noindent
}
{
\end{leftbar}
\end{definition}
}

但这让我

定理(])

可选参数]一些文本

我该怎么做才能正确传递参数?

编辑:我正在使用 framed 包来获取 leftbar 信息,并使用 amsthm 包来获取定理。

答案1

您需要根据是否给出了可选参数进行分支。

\documentclass{article}
\usepackage{framed}

\newtheorem{innertheorem}{Theorem}
\newenvironment{theorem}[1][]
 {\if\relax\detokenize{#1}\relax
    \begin{innertheorem}%
  \else
    \begin{innertheorem}[#1]%
  \fi
  \mbox{}\par\nobreak
  \vspace{-\baselineskip}\vspace{3pt}%
  \begin{leftbar}\noindent\ignorespaces}
 {\end{leftbar}\end{innertheorem}}

\begin{document}

\begin{theorem}
Some statement Some statement Some statement
Some statement Some statement Some statement
Some statement Some statement
\end{theorem}

\begin{theorem}[Something]
Some statement Some statement Some statement
Some statement Some statement Some statement
Some statement Some statement
\end{theorem}

\end{document}

在此处输入图片描述

相关内容