2

In the example below (sorry, I don't know how to make it smaller), I try to include the page number in the equation numbering, but on top of a new page, the equation gets numbered by the previous page not by the page it is actually on. I indicate where the problem occurs with a sentence that references the incorrectly numbered equation. As you can see, on top of page 3, all 4 equations in the align environment get numbered by the previous page.

I see the same problem with any theorem-like environment.

Motivation: it is much easier to find an equation (or any theoremlike structure) in a large article or book if the reference indicates the page number instead of the section or anything else.)

\documentclass[12pt,letterpaper]{amsart}
\numberwithin{equation}{page}
\begin{document}
\begin{equation}
  \frac12=\frac24\label{eq:1}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:2}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:3}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:4}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:5}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:6}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:7}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:8}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:9}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:10}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:11}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:12}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:13}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:14}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:15}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:16}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:17}  
\end{equation}
Equation \eqref{eq:17} is on page \pageref{eq:17}, not on the
previous page.
\begin{equation}
  \frac12=\frac24\label{eq:18}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:19}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:20}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:21}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:22}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:23}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:24}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:25}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:26}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:27}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:28}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:29}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:30}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:31}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:32}  
\end{equation}
\begin{align}
  \frac12&=\frac24\label{eq:33} \\
  \frac12&=\frac24\\
  \frac12&=\frac24\\
  \frac12&=\frac24
\end{align}
Equation \eqref{eq:33} is on page \pageref{eq:33}, not on the previous
page.
\begin{equation}
  \frac12=\frac24\label{eq:34}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:35}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:36}  
\end{equation}


\end{document}

Added (thanks!!!): The perpage package worked perfectly. One remark: it requires an extra run of latex. I could even use it for theoremlike environments. Here is what I needed to do to have all theorems be numbered by page. Note that the counter redefinition had to be done after the definition of the thm environment since the counter thm counter doesn't exist before.

\mdtheorem[style=theorem]{thm}{Theorem}
\let\origthethm\thethm
\MakePerPage{thm}
\renewcommand{\thethm}{\theperpage.\origthethm}
  • The page counter is increased at shipout of the page, i.e. at the end, not at the beginning of a page – user31729 Jan 20 '17 at 19:52
  • I hope the \label{eq:1} system is only used to track the equations here in demonstration, not in your real document – user31729 Jan 20 '17 at 20:08
  • 1
    you can never refer to the page counter in the body of the document as page breaking happens later after all macros have been expanded, you always need to refer to it indirectly eg via \pageref – David Carlisle Jan 20 '17 at 20:26
  • Basically any real setup of a sophisticated document with LateX requires two or more runs. – user31729 Jan 22 '17 at 18:33
5

Use the perpage package, which is designed for such per - page activities. The correct page value can be retrieved with the \theperpage macro.

\documentclass[12pt,letterpaper]{amsart}

\let\origtheequation\theequation

\usepackage{perpage}

\MakePerPage{equation}


\renewcommand{\theequation}{\theperpage.\origtheequation}



\begin{document}
\begin{equation}
  \frac12=\frac24\label{eq:1}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:2}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:3}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:4}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:5}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:6}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:7}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:8}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:9}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:10}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:11}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:12}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:13}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:14}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:15}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:16}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:17}  
\end{equation}
Equation \eqref{eq:17} is on page \pageref{eq:17}, not on the
previous page.
\begin{equation}
  \frac12=\frac24\label{eq:18}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:19}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:20}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:21}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:22}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:23}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:24}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:25}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:26}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:27}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:28}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:29}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:30}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:31}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:32}  
\end{equation}
\begin{align}
  \frac12&=\frac24\label{eq:33} \\
  \frac12&=\frac24\\
  \frac12&=\frac24\\
  \frac12&=\frac24
\end{align}
Equation \eqref{eq:33} is on page \pageref{eq:33}, not on the previous
page.
\begin{equation}
  \frac12=\frac24\label{eq:34}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:35}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:36}  
\end{equation}


\end{document}

enter image description here

  • example would be more compelling if the visual showed two pages, with the xref on the first page to an equation on the second. (the code is solid, but if someone just looks at the present visual, it looks "manufactured".) maybe use geometry to set a shorter page. – barbara beeton Jan 20 '17 at 21:18
2

You can use the zref package, in particular its perpage module.

Note the usage of \thezpage for getting the correct page number, which is not the same as \thepage in some circumstances: the problem is that TeX typesets things further before realizing it has to eject a page; this is done in order to find the optimal page break point according to its rules.

\documentclass[12pt]{amsart}

\usepackage{zref-perpage}

\usepackage[a6paper]{geometry} % just for the example

\zmakeperpage{equation}
\renewcommand{\theequation}{\thezpage.\arabic{equation}}

\begin{document}
\begin{equation}
  \frac12=\frac24\label{eq:1}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:2}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:3}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:4}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:5}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:6}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:7}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:8}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:9}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:10}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:11}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:12}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:13}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:14}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:15}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:16}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:17}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:18}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:19}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:20}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:21}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:22}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:23}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:24}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:25}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:26}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:27}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:28}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:29}  
\end{equation}
\begin{equation}
  \frac12=\frac24\label{eq:30}  
\end{equation}
\end{document}

The geometry package has been used just for reducing the amount of code and for showing several pages in a small picture.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.