# Typesetting lemmas in latex with shadethm package

I am trying to get the shadethm package to typeset lemmas in shaded boxes, but am failing so far.

The following document produces

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[margin=0.75in]{geometry}
\usepackage{blindtext}
\setlength{\parindent}{20pt}
\usepackage{amsthm}
\usepackage{shadethm}
\renewcommand\qedsymbol{$\blacksquare$}

\newshadetheorem{theorem}{Theorem}
\newshadetheorem{corollary}{Corollary}[theorem]

\title{\vspace{-1.5cm}Test Document}
\begin{document}

\maketitle

\blindtext

\begin{theorem}
This is a theorema about right triangles and can be summarised in the next
equation
$x^2 + y^2 = z^2$
\end{theorem}

\section{New Section}

\begin{theorem}[Pythagorean theorem]
\label{pythagorean}
This is a theorema about right triangles and can be summarised in the next
equation
$x^2 + y^2 = z^2$
\end{theorem}

\begin{proof}
To prove it by contradiction try and assume that the statemenet is false,
proceed from there and at some point you will arrive to a contradiction.
\end{proof}

\blindtext

\begin{corollary}
This is a theorema about right triangles and can be summarised in the next
equation
$x^2 + y^2 = z^2$

\end{corollary}
\end{document} However, when I try to typeset lemmas as theorems as \newshadetheorem{lemma}[theorem]{Lemma} (following overleaf) and then using \begin{lemma}...\end{lemma}

I get the compilation error

 [long compilation output]
! TeX capacity exceeded, sorry [input stack size=5000].
\cl@theorem ->\cl@theorem
\@elt {shadecorollary}
l.57 \begin{lemma}

!  ==> Fatal error occurred, no output PDF file produced!
Transcript written on test.log.


Where am I going wrong? I would like Theorems and Lemmas to be labelled together sequentially like Theorem 1, Lemma 2, Lemma 3, Theorem 4 irrespective of the section number they are in.

• I don't think that you doing something wrong, it is probably a bug in the package. I would suggest to check the tcolorbox package, it has many options to create framed math environments. – Ulrike Fischer Apr 17 at 18:49

## 2 Answers

You might be interested in giving a try at the ntheorem package, which enables you to fully customise the layout of theorems. For shaded theorems, it relies on the framed package. Note the automatic placement of the ‘end-of-proof’ symbol, even when the proof ends with an equation (two compilations required):

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[margin=0.75in]{geometry}
\usepackage{graphicx}
\usepackage[svgnames]{xcolor}
\usepackage[normalem]{ulem}
\usepackage{amsmath, amssymb, nccmath}
\usepackage{blindtext}
\setlength{\parindent}{20pt}

\usepackage{framed}
\usepackage[framed, thmmarks]{ntheorem}
\colorlet{shadecolor}{Gainsboro!50!Lavender}
\def\theoremframecommand{\colorbox{shadecolor}}
\theoreminframepreskip{\medskipamount}
\theoreminframepostskip{\medskipamount}
\theoremseparator{.}
\newshadedtheorem{theorem}{Theorem}
\newshadedtheorem{corollary}{Corollary}[theorem]
\newshadedtheorem{lemma}{Lemma}[theorem]

\theoremstyle{nonumberplain}
\theoremheaderfont{\itshape}
\theorembodyfont{\upshape}
\theoremseparator{:}
\theoremsymbol{\ensuremath{\blacksquare}}
\newtheorem{proof}{Proof}

\title{\vspace{-1.5cm}Test Document}
\author{My Self}
\date{}

\begin{document}

\maketitle

\blindtext

\begin{theorem}
This is a theorema about right triangles and can be summarised in the next
equation\useshortskip
$x^2 + y^2 = z^2$
\end{theorem}

\begin{lemma}
This lemma doesn’t provoke a general panic.
\end{lemma}

\section{New Section}

\begin{theorem}[Pythagorean theorem]
\label{pythagorean}
This is a theorema about right triangles and can be summarised in the next
equation
$x^2 + y^2 = z^2$
\end{theorem}

\begin{proof}
To prove it by contradiction try and assume that the statement is false,
proceed from there and at some point you will arrive to a contradiction. Hence
$a^2 = b^2 + c^2.$%
\end{proof}

\blindtext

\begin{corollary}
This is a theorema about right triangles and can be summarised in the next
equation
$x^2 + y^2 = z^2$

\end{corollary}

\end{document} • Thank you! This was exactly what I wanted! – smilingbuddha Apr 18 at 2:40

It is not very clear from the manual, but the source file (shadethm.sty) has some more information (from line 180 onwards):

The invocation possibilities are:
\newshadetheorem{NAME}{TEXT}[COUNTER]
e.g., \newshadetheorem{theorem}{Theorem}[section] meaning to allow
one to say \begin{theorem} $e=mc^2$ \end{theorem} to produce
Theorem 1.1.1 e=mc2
shaded and numbered by section.
\newshadetheorem{NAME}[OLDNAME]{TEXT}
e.g., \newshadetheorem{remark}[theorem]{Remark} meaning to allow
one to say \begin{remark} Obvious. \end{remark} to produce
Remark 1.1.2  Obvious.
shaded and numbered with the same counter used for theorems.


So when you want the theorems to be counted using an external counter then you put the argument after the theorem name, and when you want to use an internal counter then you put the argument in the middle.

There seems to be a bug when you want to use the same counter both externally and internally. If you want to do this a possible solution is to create a separate counter for the new environment by not using the optional argument, and then prefix this counter with the theorem counter by redefining the display macro (here \theshadecorollary).

MWE:

\documentclass[11pt]{article}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{shadethm}
\renewcommand\qedsymbol{$\blacksquare$}

\newshadetheorem{theorem}{Theorem}
\newshadetheorem{corollary}{Corollary}
\newshadetheorem{lemma}[theorem]{Lemma}
% redefine display of corollary counter
\def\theshadecorollary{\arabic{shadetheorem}.\arabic{shadecorollary}}
% reset corollary counter when theorem counter is increased
\makeatletter
\@addtoreset{shadecorollary}{shadetheorem}
\makeatother

\title{Test Document}
\begin{document}

\maketitle
\begin{lemma}
This is a lemma
\end{lemma}

\begin{theorem}
This is a theorema about right triangles and can be summarised in the next
equation
$x^2 + y^2 = z^2$
\end{theorem}

\section{New Section}

\begin{theorem}[Pythagorean theorem]
\label{pythagorean}
This is a theorema about right triangles and can be summarised in the next
equation
$x^2 + y^2 = z^2$
\end{theorem}

\begin{proof}
To prove it by contradiction try and assume that the statement is false,
proceed from there and at some point you will arrive to a contradiction.
\end{proof}

\begin{corollary}
This is a theorema about right triangles and can be summarised in the next
equation
$x^2 + y^2 = z^2$

\end{corollary}

\begin{corollary}[Pythagorean theorem]
The following also holds:
$a^2 + b^2 = c^2$
\end{corollary}
\end{document}


Result: 