How to put equation numbers on the left or the right, depending on whether the page is odd or even

I'm trying to create a document that has labels on different sides on even and odd pages. I would like the labels were on the even-numbered pages on the right and on the odd-numbered pages on the left.

\documentclass[12pt,a4paper]{report}

\usepackage[cp1250]{inputenc}
\usepackage[T1,plmath]{polski}

\usepackage{indentfirst}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{mathrsfs}
\usepackage{graphicx}
%%%%%%%%%%%%%%%%%%%%%%%%%%

%stare wartości: \textheight 26cm \textwidth 17cm \topmargin -2cm \oddsidemargin -0.5cm

\textwidth 15.5cm
\textheight 23.5cm
\topmargin -1cm
\oddsidemargin 0cm
\evensidemargin 0cm

\def\dowod{D\,o\,w\,ó\,d.\,}
\newtheorem{twi}{Twierdzenie}[chapter]
\newtheorem{tw}{Twierdzenie}
\newtheorem{lem}{Lemat}
\newtheorem{dfn}{Definicja}
\newtheorem{wn}{Wniosek}
\newenvironment{dow}{\par\dowod}{}
\renewcommand{\thetw}{\Alph{tw}}

\begin{document}

$$\label{lp2} H(0,t)=ue^{-t} \sum_{i=0}^{\infty} \frac{(tu)^i}{i!} = ue^{-t(1-u)}$$

$$\label{lp3} a(j)=1-(1-u)q^j$$

\end{document}


Is it possible to do this?

• Jul 7 '13 at 10:56
• I think this could also be done with a combined application of tex.stackexchange.com/questions/8092 and the everypage package. Jul 7 '13 at 12:29
• I read the answers to these questions, but I can not apply them to my problem. This program is new to me and I am not able to write even simple condition. :( Jul 7 '13 at 16:16

A simple hack to achieve is as given below:

\makeatletter
\def\mathlabel#1{\@bsphack
\protected@write\@auxout{}%
{\string\newlabel{#1}{{\@currentlabel}{\thepage}}}%
\@esphack}
\def\eqnWrite{\@bsphack
\protected@write\@auxout{}%
{\string\EqnStat{\theequation}{\thepage}}%
\@esphack}%
\def\EqnStat#1#2{%
\expandafter\gdef\csname eqn@#1\endcsname{#2}%
}
\newcommand\@reqnnum{\hb@xt@.01\p@{}%
\rlap{\normalfont\normalcolor%
\hskip -\displaywidth(\theequation)}}
\def\equation{\let\mathlabel\label$$\refstepcounter{equation}} \def\endequation{\eqno\eqnWrite\@ifundefined{eqn@\theequation}{\hbox{\@eqnnum}}%% {\expandafter\ifodd\csname eqn@\theequation\endcsname\hbox{\@reqnnum}% \else\hbox{\@eqnnum}\fi}$$\@ignoretrue}
\def\@@eqncr{\let\reserved@a\relax%
\ifcase\@eqcnt \def\reserved@a{& & &}\or \def\reserved@a{& &}%
\or \def\reserved@a{&}\else%
\let\reserved@a\@empty%
\@latex@error{Too many columns in eqnarray environment}\@ehc\fi%
\reserved@a \if@eqnsw\eqnWrite%
\@ifundefined{eqn@\theequation}{\@eqnnum}%
{\expandafter\ifodd\csname eqn@\theequation\endcsname\@reqnnum%
\else\@eqnnum\fi}\stepcounter{equation}\fi%
\global\@eqnswtrue\global\@eqcnt\z@\cr}
\makeatother


Place this code just before \begin{document}.

• Now on the pages where the equation is at the top of the page (before the equation on the site is max one line of text), label for this equation is on the opposite side. The program does not recognize the reference to the labels \eqref{} inserts instead "(??)". Jul 7 '13 at 11:18
• Pardon me, but where is makeatother? ;) Pretty cool TeXhack! Jul 7 '13 at 12:28
• @Agnieszka I have updated the code, now cross-reference and equation appearing after pagebreak will appear correctly. Please note that you need to run twice to get the equation number appear correctly in the margins. @SeanAllred \makeatother is not a must :-) Jul 7 '13 at 16:20