8

I want to number theorems by (page number).(sequential in the page). So in page 6 I would have

Thm 6.1 AAAAAABBBVVV

Thm 6.2 BBBGGSDFASFASF

Thm 6.3 AXASDFASDF

and then in page 7 it would be

Thm 7.1 AAAAAABBBVVV

Thm 7.2 BBBGGSDFASFASF

Thm 7.3 AXASDFASDF

I tried using \newtheorem{thm}{Thm}[page]. However, if Thm 7.1 is at the top of page 7, sometimes it would get numbered as Thm 6.4. I assume that this happens because \thepage is called before the actual new page was set. Is there an easy fix for this?

3
  • 1
    Theorem numbers are used for reference, maybe in other documents; using this approach would invalidate all references in case a new edition of your document is printed where added or removed text changes the placement of theorems.
    – egreg
    Commented Oct 10, 2013 at 11:47
  • Thank you for your concern. I am not writing a work for reference. Just some lecture notes in a local language. On the other hand, I find it very useful to have such numeration because it helps searching for things very easily.
    – someone
    Commented Oct 10, 2013 at 19:08
  • I think numbering theorems by page would be the best: whenever I read a book, and I see a reference to a theorem, the fastest way for me to find the theorem would be if I knew which page it is on. I don't understand the comment about different editions or outside references. When a theorem is referenced as "Theorem 123.4 in The Elements" and the appropriate edition of the Elements is cited, I can go, open that edition of the Elements, and find the theorem on page 123. Commented Nov 3, 2016 at 17:30

1 Answer 1

10

You need a \label and \pageref mechanism to fix up the page references on a later run.

enter image description here

\documentclass{article}

\setlength\textheight{4cm}

\newcounter{thminternal}
\newtheorem{thm}{Thm}
\let\zzthm\thm
\makeatletter
\def\@begintheorem#1#2{\trivlist
   \item[%
\protected@edef\zz{\pageref{thm-\thethminternal}}%
        \stepcounter{thminternal}%
\protected@edef\zzz{\pageref{thm-\thethminternal}}%
\ifx\zz\zzz\else\setcounter{thm}{0}\refstepcounter{thm}\fi
\label{thm-\thethminternal}%
        \hskip \labelsep{\bfseries #1\ \pageref{thm-\thethminternal}.#2}]\itshape}



\begin{document}

\begin{thm}aaaa\end{thm} zzz

\begin{thm}bbb\end{thm} \begin{thm}ccc\end{thm}

zzz

\begin{thm}aaaa\end{thm} zzz

\begin{thm}bbb\end{thm} \begin{thm}ccc\end{thm}
\begin{thm}bbb\end{thm} \begin{thm}ccc\end{thm}

zzz
\begin{thm}bbb\end{thm} \begin{thm}ccc\end{thm}
\begin{thm}bbb\end{thm} \begin{thm}ccc\end{thm}

zzz


\end{document}
2
  • Thanks! This nearly does it. The \ifx starts having problems when the pages get double digits, but that should be easily fixable.
    – someone
    Commented Oct 13, 2013 at 19:24
  • @someone hmm double digits should work, if it doesn't work for you you could put an example and ping me here Commented Oct 13, 2013 at 19:43

You must log in to answer this question.

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