6

At the moment I thinking about the following think. When I use the twoside mode to write a book I want to print the number of the equation outer.

I can modify it manually with these two commands:

\makeatletter
\def\LEFTTAG{\tagsleft@true}\def\RIGHTTAG{\tagsleft@false}
\makeatother

This solution is bad.

Here a minimal example:

\documentclass[a4paper]{book}
\usepackage{multido,lipsum,showframe}
\usepackage{amsmath}
\begin{document}
\chapter{foo}
\multido{\iA=0+1}{10}{%
\lipsum[1]
\begin{align}
x+y
\end{align}}
\end{document}

How can I modify the default environments to print the tags outer?

EDIT In relation to the answers of Werner and the following code the possibilities doesn't work well:

\usepackage{scrextend,etoolbox}
\makeatletter
\preto\set@field{%
 \ifthispageodd{\global\tagsleft@false}{\global\tagsleft@true}%
}
\makeatother
4
  • 1
    Don't; equation numbers are not like page numbers.
    – egreg
    Commented Aug 29, 2011 at 7:46
  • @egreg: What do you mean? Commented Aug 29, 2011 at 8:08
  • 1
    you can redefine the equation environments and then set for every equation an internal label. Then you can have a reference to \ifodd\pageref{eqn:label}
    – user2478
    Commented Aug 29, 2011 at 8:11
  • 2
    I mean that equation numbers must go on the same side always. Page numbers can go on the outer side because they are used in a different way, when thumbing through the book for finding a page; equation numbers are looked at by following the text and it's immaterial what page they are in.
    – egreg
    Commented Aug 29, 2011 at 8:16

1 Answer 1

4

As a first attempt at solving this, the everyshi package is of great help. In the definition below, a choice between left/right tag is made based on whether the page number is odd/even:

\usepackage{everyshi}% http://ctan.org/pkg/everyshi
\usepackage{xifthen}% http://ctan.org/pkg/xifthen
...
\makeatletter
\EveryShipout{%
  \ifthenelse{\isodd{\value{page}}}% Test page number
    {\global\tagsleft@true}% Following page will have left-tagged equations
    {\global\tagsleft@false}% Following page will have right-tagged equations
}
\makeatother

There's one minor hiccup. Whenever typesetting an equation at the bottom of a page that does not entirely fit and has to be broken/flushed to the next, the \EveryShipout command is "too late" in modifying the tag location (either left or right). One remedy for this is some manual intervention to make sure the equation is pushed to the next page after the page is shipped out (for example, by issuing a manual \break or perhaps using the needspace package). The latter, perhaps more elegant and automated approach, requires the definition of a new environment (using the environ package):

\usepackage{needspace}% http://ctan.org/pkg/needspace
\usepackage{environ}% http://ctan.org/pkg/environ
...
\NewEnviron{altalign}{% Alternating tag align \begin{altalign} ... \end{altalign}
  \setbox0=\hbox{% Store contents in box0
    \begin{minipage}{\linewidth}\begin{align*}% Unnumbered align
      \BODY
    \end{align*}\end{minipage}
  }%
  \Needspace{\ht0}% Need exactly height of box0 at the bottom of the page
  \begin{align}
    \BODY% Typeset regular tagged align
  \end{align}
}

The use of the environ package \NewEnviron is essential here, since the body/contents of an environment needs to be captured in order to use it (\BODY in this case). In essence, the provided altalign environment typesets the contents of the required align in an align* environment (that is, without equation numbers), embedded in a minipage of width \linewidth, and stores everything in a box (box0). Then, \Needspace is issued to either do nothing if there is enough space (\ht0) on the page, or \break if not. Subsequently, the equations are typeset in the traditional align (numbered) environment, this time with the correct addition of EveryShipout. The solution works since the align environment does not break across pages/columns and can therefore be treated as a single block/box.

Alternating equation numbers based on page number

2
  • Thanks for the inspiration. I tried it. Unfortunately this solution isn't enough for me ;-). During my test I tried something like: \usepackage{scrextend} \usepackage{etoolbox} \makeatletter \preto\set@field{% \ifthispageodd{\global\tagsleft@false}{\global\tagsleft@true}% } \makeatother but with the same result. Commented Aug 28, 2011 at 17:24
  • @Marco: I've updated my answer to correct for this unwanted, yet TeX-correct, behaviour. I've also included a description of the solution method.
    – Werner
    Commented Aug 30, 2011 at 6:40

You must log in to answer this question.

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