1

I wrote the following piece of code in order to define custom environments for propositions, corollaries, remarks, definitions, examples, lemmas,...etc .

\newcounter{mthm}
\newtheorem{mthmitalic}[mthm]{\mthmname}
\theoremstyle{definition}
\newtheorem{mthmroman}[mthm]{\mthmname}
\newcommand{\mthmname}{}

\newcommand{\varnewtheorem}[3]{%
\newenvironment{#1}[1]{%
\renewcommand{\mthmname}{#2}%
\renewcommand{\themthm}{##1}%
\csname mthm#3\endcsname
 }{\csname endmthm#3\endcsname}%
}

\varnewtheorem{theorem}{Theorem}{italic}
\varnewtheorem{corollary}{Corollary}{italic}
\varnewtheorem{definition}{Definition}{roman}
\varnewtheorem{example}{Example}{roman}
\varnewtheorem{examples}{Examples}{roman}
\varnewtheorem{proposition}{Proposition}{italic}
\varnewtheorem{remark}{Remark}{roman}

Every environment (e.g, \begin{corollary}{num} \end{corollary}) takes another argument for providing the numbering of the corollary or whatever. My questions is: can this piece of code be modified in order to provide a subsequent automatic numbering such that all environments are dependent on each other. This means that if I have a Definition 1 and a theorem after the definition, then the theorem is automatically labeled by 2.

I also want the modification to work properly whether there is a partitioning of the articles into sections and subsection or not.

I hope I revealed what I want to have pretty well.

Thanks in advanceز

1
  • 1
    Well, you just don't need that apparatus, which was devised because you wanted to do manual numbering.
    – egreg
    Commented Feb 21, 2022 at 23:09

1 Answer 1

2

That machinery was needed because you asked for manual numbering.

Automatic numbering works out of the box.

\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}

\newtheorem{theorem}{Theorem}[section]
\newtheorem{corollary}[theorem]{Corollary}
% declare here other similar environments with text in italic

% from now on the defined environments will have the text in upright type
\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{example}[theorem]{Example}

\newcommand{\s}{\oplus}
\newcommand{\ds}{\leq^{\oplus}}
\DeclareMathOperator{\im}{im}

\begin{document}

\section{Title}

\begin{definition}
This is a definition of $X\ds Y$.
\end{definition}

\begin{theorem}\label{theoremC3}
Let $M_R$ be a $C3$-module. If $M=X\s Y$ and $f:X\to Y$ is a homomorphism with 
$\ker f \ds X$, then $\im f \ds Y$.
\end{theorem}

An immediate consequence of Theorem \ref{theoremC3} is the following corollary.

\begin{corollary}\label{corollaryeasy}
Corollaries are easy.
\end{corollary}

And we can even give examples.

\begin{example}
This is an example related to Corollary~\ref{corollaryeasy}
\end{example}

\end{document}

enter image description here

If you want the numbering to be independent of the sectios, just remove [section] from the first \newtheorem declaration.

2
  • There is a one single problem: How can I make the propositions and lemmas in italic? Commented Feb 22, 2022 at 19:38
  • @HusseinEid The environments you declare before \theoremstyle{definition} will have the text in italics.
    – egreg
    Commented Feb 22, 2022 at 22:33

You must log in to answer this question.

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