[Tex/LaTex] No counter ‘theorem’ defined

counterstheorems

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[algosection,ruled,lined,boxed,commentsnumbered,linesnumbered,longend]{algorithm2e}
\usepackage{lineno}

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

\newcommand{\beq}{\begin{equation}}
%\newcommand{\bet}{\begin{table}}
\newcommand{\eeq}{\end{equation}}
\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}

Best Answer

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.

enter image description here

\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}