2

I would like to have the equation number on odd pages to the right and on even pages to the left. I found this How to put equation numbers on the left or the right, depending on whether the page is odd or even but it does not seem to work with the scrbook class. Any ideas on how to modify this?

Here is a MWE:


\documentclass[12pt,a4paper]{scrbook}

\usepackage{amsmath}
\linespread{1.5}

\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@[email protected]\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


\begin{document}

\begin{equation}
   y = ax + b
\end{equation}

\begin{equation}
   a^n + b^n = c^n
\end{equation}

\end{document}

Replacing scrbook with report works fine.

1
  • 5
    How about helping us with the basics... can you set up a minimal document that starts with \documentclass and ends with \end{document} so we don't have do build everything from scratch? Can you do that? Using a package like blindtext or lipsum to build text around some equations. Also whether one should consider multi-line aligns that may span the page boundary.
    – Werner
    Commented Sep 24, 2019 at 19:18

1 Answer 1

2

I don't know about the scrbook class but perhaps the following will help, based on the changepage package provision of odd/even page checking.

%\documentclass...
\usepackage{changepage} \strictpagecheck
\newcommand{\leftright}{%
  \checkoddpage
  \ifoddpage
  % code for right eqno (which depends on your class and packages)
  \else
  % code for left eqno (which depends on your class and packages)
  \fi}
% ...
\begin{equation} \leftright
% ...
\end{equation}
% ...

If you don't want to keep adding \leftright after each \begin{equation} you can add it to the equation definition like:

\let\oldequation=\equation
\renewcommand*{\equation}{\oldequation \leftright}

and then just use \begin{equation} instead of \begin{equation} \leftright.

3
  • What code would you use for the if part? Not sure if I like the solution because it requires to change the whole (very large) document. Commented Sep 26, 2019 at 11:54
  • @diophantus7 I have extended my answer. It is up to you to decide on the code for the \if... as it will depend on the class you are using and also any maths-related packages you might be using. Perhaps you need to ask a separate question about that. Commented Sep 27, 2019 at 17:33
  • Thanks! While it looks promising and works most times, it does not work with a split environment inside a equation environment and also not with an align environment. Ideas on why this might not work? Commented Oct 1, 2019 at 11:30

You must log in to answer this question.

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