Equations in the margin: automatic flush right or left?
If you do not need numbered equations, then use a simple array
\documentclass[twoside]{scrartcl}
\usepackage{amsmath}
\usepackage{lipsum}
\usepackage{marginnote}
\newenvironment{Array}
{\arraycolsep=1.4pt\par$\array{rl}}
{\endarray$}
\begin{document}
\lipsum[1]
\marginnote{Is flush left (manually)
\begin{Array}
a&=1 \\
b&=1
\end{Array}}
\lipsum[2]
\marginnote{How to make flush left automatically?
\begin{Array}
a&=1\\
b&=1
\end{Array}}
\lipsum[3-6]
\marginnote{Is flush right (manually):
\begin{Array}
a&=1\\
b&=1
\end{Array}}
\lipsum[7]
\marginnote{How to make flush right automatically?
\begin{Array}
a&=1\\
b&=1
\end{Array}}
\lipsum[8-9]
\end{document}
This is what I would call semi-automatic.
The everyshi
package provides a hook into the page shipout routine by means of the \EveryShipout
macro. As such, the code
\usepackage{everyshi}% http://ctan.org/pkg/everyshi
\def\flusheqnL{&} \def\flusheqnR{}%
\EveryShipout{%
\ifodd\value{page}
\gdef\flusheqnL{} \gdef\flusheqnR{&&}%
\else
\gdef\flusheqnL{&} \gdef\flusheqnR{}%
\fi
}%
defines \flusheqnL
and \flusheqnR
to have default values of &
and {}
, respectively, and alters these values based on the page number \value{page}
at shipout. If the page number is odd, the values are swapped to {}
and &&
, respectively, to accommodate a different alignment on the following (even) page. In fact, these macros are used as hooks for alignment characters in the flalign*
environment. However, this requires you to typeset your marginnote
equations using the following format:
\marginnote{...
\begin{flalign*}
\flusheqnR ...&... \flusheqnL \\
\flusheqnR ...&... \flusheqnL
\end{flalign*}}
Here's an example of the output:
\documentclass[twoside]{scrartcl}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{marginnote}% http://ctan.org/pkg/marginnote
\usepackage{everyshi}% http://ctan.org/pkg/everyshi
\def\flusheqnL{&} \def\flusheqnR{}%
\EveryShipout{%
\ifodd\value{page}
\gdef\flusheqnL{} \gdef\flusheqnR{&&}%
\else
\gdef\flusheqnL{&} \gdef\flusheqnR{}%
\fi
}%
\begin{document}
\lipsum[1]
\marginnote{Is flush left (manually)
\begin{flalign*}
a&=1 &\\
b&=1 &
\end{flalign*}}
\lipsum[2]
\marginnote{How to make flush left automatically?
\begin{flalign*}
\flusheqnR a&=1 \flusheqnL \\
\flusheqnR b&=1 \flusheqnL
\end{flalign*}}
\lipsum[3-6]
\marginnote{Is flush right (manually):
\begin{flalign*}
&& a&=1\\
&& b&=1
\end{flalign*}}
\lipsum[7]
\marginnote{How to make flush right automatically?
\begin{flalign*}
\flusheqnR a&=1 \flusheqnL \\
\flusheqnR b&=1 \flusheqnL
\end{flalign*}}
\lipsum[8-9]
\end{document}
The redefinition of \flusheqnL
and \flusheqnR
has to be made global (via \gdef
) in order for it to hold outside the group (within \EveryShipout
).