# Numbering theorems etc. consecutively but not starting at 1

Suppose I am creating, say, 50 individual LaTeX files (one for each lecture).

I wish to label all my theorems/propositions in the first file as 1.1, 1.2, etc. but then in the second file I want them all labelled as 2.1, 2.2, etc., up until the 50th lecture, where everything would be labelled as 50.1, 50.2 etc.

In other words, each individual LaTeX file has everything numbers consecutively, but (apart from the first file), the numbering won't start at 1. What is the easiest way to accomplish this?

Second question: at the end of the semester I will glue the 50 files together (so the students get one combined file). Ideally the solution to the previous question will involve minimal fuss when the files are pasted together.

• You can define each lecture file as a \chapter which are \include-d into the general one. And compile this one with \includeonly option for each individual chapter. This way, each lecture will keep its own number. – Ignasi Jan 12 '17 at 16:40

It depends on how you define your "lecture" environment. However, the following would suffice and allow you to merge them together at the end:

\documentclass{article}

%\usepackage{hyperref}

\newtheorem{theorem}{Theorem}

\newcommand{\settheoremprefix}[1]{%
\setcounter{theorem}{0}%
\renewcommand{\thetheorem}{#1.\arabic{theorem}}%
}

\begin{document}

\settheoremprefix{1}

\begin{theorem}\end{theorem}
\begin{theorem}\end{theorem}
\begin{theorem}\end{theorem}

\settheoremprefix{2}

\begin{theorem}\end{theorem}
\begin{theorem}\end{theorem}
\begin{theorem}\end{theorem}

\settheoremprefix{3}

\begin{theorem}\end{theorem}
\begin{theorem}\end{theorem}
\begin{theorem}\end{theorem}

\end{document}


\settheoremprefix{<stuff>} prepends <stuff>. to every theorem number. If you're loading hyperref, care is taken to ensure correct hyperlink jumps will result by also updating \theHtheorem - a hyperref-specific counter.

A more generic version \setcounterprefix{<counter>}{<stuff>} can also be used

\newcommand{\setcounterprefix}[2]{%
\setcounter{#1}{0}%

\setcounterprefix{theorem}{2}