1

Is there a way to simplify the following newtheorem environment

\newtheorem{definition}[theorem]{Definition}

instead of using it as follows

\begin{definiton}[xxx]
   yyy
\end{definiton}

is it possible to use it as follows

\definiton[xxx]{
   yyy
 }
3
  • is it possible to shorten an environment by getting rid of begin and end as in my example above?
    – user547654
    Commented Jan 8, 2022 at 16:26
  • most latex editors will let you add \begin{definition} \end{definition} with just three or four keystrokes, there really isn't any advantage in the command form. I deleted my first comment after your edit. Commented Jan 8, 2022 at 17:07
  • The environment for is much easier to manage: the \begin and \end tags are much more prominent than just \definition{ and } (particularly for the end).
    – egreg
    Commented Jan 8, 2022 at 17:13

1 Answer 1

1

You can define a command that wraps its argument in your definition environment.

\documentclass{article}
\usepackage{etoolbox}
\newtheorem{theorem}{Theorem}
\newtheorem{definitionenv}[theorem]{Definition}
\NewDocumentCommand{\definition}{o m}{%
    \IfNoValueTF{#1}{%
        \begin{definitionenv}
            #2
        \end{definitionenv}%
    }{%
        \begin{definitionenv}[#1]
            #2
        \end{definitionenv}%
    }%
}
\begin{document}
\begin{definitionenv}
    yyy
\end{definitionenv}

\begin{definitionenv}[xxx]
    yyy
\end{definitionenv}

\definition{
    yyy
}

\definition[xxx]{
    yyy
}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .