创建自定义环境,带有可选参数和非默认标点符号

创建自定义环境,带有可选参数和非默认标点符号

这似乎应该是最基本的问题,但恐怕我无法在网站上找到一个可以理解的答案。我正在尝试定义一个定义环境,它 1) 用冒号替换默认句点 2) 允许使用带有所定义术语的括号语句的可选参数。我已经构建了执行此操作的代码,但它真的非常笨拙。有人能告诉我如何以优雅而强大的方式做同样的事情吗?感谢您的任何建议。

这是我的糟糕代码:

\documentclass{amsart}
\usepackage{amsthm}
\usepackage{xpatch}
\theoremstyle{myStyle}
\newtheoremstyle{myStyle}% name
{3pt}% space above
{3pt}% space below
{italic}% body font
{}% indent amount
{bold}% theorem head font
{:}% punctuation after theorem head
{.5em}% space after theorem head
{}% theorem head spec

%Get rid of the default period after Defn
\makeatletter
    \xpatchcmd{\@thm}{\thm@headpunct{.}}{\thm@headpunct{}}{}{}
\makeatother

\newtheorem{definition}{Defn}
\newenvironment{myDefn}[3]
    {
        \label{defn:#1}
        \begin{definition}{{\bf{(#2):}}}
         {#3}
    \end{definition}}
    {}

\newtheorem{definitionAlt}{Defn}
\newenvironment{myDefnAlt}[2]
    {
    \setcounter{definitionAlt}{\thedefinition}
     \label{defn:#1}
     \begin{definitionAlt}{{\hspace*{-0.1in} \bf :}}
     {#2}
    \end{definitionAlt}}
    {\setcounter{definition}{\thedefinitionAlt}}
\begin{document}
\begin{myDefn}
{myLabel}
{Dog}
{A dog is something that you take for a walk}
\end{myDefn}
\begin{myDefnAlt}
{myLabelAlt}
{A dog is something that you take for a walk}
\end{myDefnAlt}
\begin{myDefn}
{myLabel}
{Dog}
{A dog is something that you take for a walk}
\end{myDefn}
\begin{myDefnAlt}
{myLabelAlt}
{A dog is something that you take for a walk}
\end{myDefnAlt}
\end{document}

它的输出如下:在此处输入图片描述

答案1

您可以在这里找到:新定理风格

\documentclass{article}
\usepackage{amsthm}

\newtheoremstyle{definition}% name of the style to be used
  {\topsep}% measure of space to leave above the theorem.
  {\topsep}% measure of space to leave below the theorem.
  {\itshape}% name of font to use in the body of the theorem
  {0pt}% measure of space to indent
  {\bfseries}% name of head font
  {:}% punctuation between head and body
  { }% space after theorem head; " " = normal interword space
  {\thmname{#1}\thmnumber{ #2}\thmnote{ (#3)}} % defines the theorem heading, where:
      % #1 is the name of the given theorem
      % #2 is its number
      % #3 is the optional argument
      % \thmname, \thmnumber and \thmnote print their arguments
      %    in the style previously specified (e.g. in boldface...) 

\theoremstyle{definition}
\newtheorem{definition}{Defn}

\begin{document}

\begin{definition}[Dog]
\label{A}
A dog is something that you take for a walk
\end{definition}

\begin{definition}
\label{B}
A dog is something that you take for a walk
\end{definition}

\begin{definition}[Dog]
\label{C}
A dog is something that you take for a walk
\end{definition}

\begin{definition}
\label{D}
A dog is something that you take for a walk
\end{definition}

\end{document}

PDF 示例

请注意:

  • 只有在定义定理样式之后才可以使用它。
  • 定理、定义等已经有了您所要求的可选参数。

相关内容