# No counter 'theorem' defined

I'm getting the error No counter 'theorem' defined Heres my code below

\documentclass[12pt]{article}

\newcommand{\package}[1]{\textbf{#1}} % package names in bold text
\newcommand{\cmmd}[1]{\textbackslash\texttt{#1}} % command name in tt font
\newcommand{\href}[1]{#1}

\usepackage{float}
\restylefloat{table}
\usepackage{bbm}
\usepackage{exscale}
\usepackage{tabularx}
\usepackage{syntonly}
\usepackage{lineno}

%\usepackage{algorithmic}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{latexsym}
\usepackage{makeidx}
\usepackage{longtable}
\makeindex

\newcommand{\real}{\mathbb{R}} %IMPORTANT

\newtheorem{lem}[theorem]{Lemma}
\newtheorem{thm}[theorem]{Theorem}
\newtheorem{cor}[theorem]{Corollary}
\newtheorem{rem}[theorem]{Remark}
\newtheorem{remark}[theorem]{Remark}
\newtheorem{conj}[theorem]{Conjecture}

• Your example is not compilable, but you don't have the theorem environment defined. Quick workaround: \newcounter{theorem} – user31729 Apr 10 '17 at 15:43
• The statement \newtheorem{thm}[theorem]{Theorem} doesn't make much sense. Use \newtheorem{theorem}{Theorem} instead -- and place this instruction before \newtheorem{lem}[theorem]{Lemma}. – Mico Apr 10 '17 at 16:01
• you might benefit from reading the amsthm package documentation -- texdoc amdthm. the use of counters is explained pretty clearly there. – barbara beeton Apr 10 '17 at 20:05

Rearrange the \newtheorems as follows, and use [thm] instead of [theorem].

\newtheorem{thm}{Theorem}
\newtheorem{lem}[thm]{Lemma}
\newtheorem{cor}[thm]{Corollary}
\newtheorem{rem}[thm]{Remark}
\newtheorem{remark}[thm]{Remark}
\newtheorem{conj}[thm]{Conjecture}


This means that the thm environment will use a counter thm, and all the other theorem-like environments will use the same counter thm.

Here is a complete example.

\documentclass{article}
\newtheorem{thm}{Theorem}
\newtheorem{lem}[thm]{Lemma}
\newtheorem{cor}[thm]{Corollary}
\newtheorem{rem}[thm]{Remark}
\newtheorem{remark}[thm]{Remark}
\newtheorem{conj}[thm]{Conjecture}
\begin{document}
\begin{thm}
Some theorem.
\end{thm}
\begin{lem}
Some lemma.
\end{lem}
\begin{conj}
A conjecture.
\end{conj}
\end{document}

• I'm having trouble getting this to work still getting environment lemma undefined btw what difference does changing the theorem to thm do? \documentclass[11pt]{article} \usepackage{amsthm} %\newtheorem{theorem}{Theorem} \newtheorem{thm}{Theorem} \newtheorem{lem}[thm]{lemma} %\newtheorem{theorem}{Theorem} \begin{document} %\begin{theorem} %adfasdfadsf %\end{theorem} \begin{lemma} adasd \end{lemma} \end{document} – Hao S Apr 10 '17 at 16:13
• @HaoSun I've added an example. Check whether it works for you. – gernot says Reinstate Monica Apr 10 '17 at 16:23
• @HaoSun, you can refer to the counter created by the first \newtheorem{}{} you use. \newtheorem{thm}{Theorem} creates a counter named thm. – Sigur Apr 10 '17 at 16:27
• Okay I see lem is the thing your suppose to enter not lemma I didn't really understand the code thanks everyone – Hao S Apr 10 '17 at 16:47