# using \marginnote inside a math environment in tufte-book

I’ve recently started using tufte-book for typesetting solutions to math problems. I like it very much that you’re encouraged to use the margin, which is very nice for giving hints, pointers and references concerning the steps of finding a solution.

Unfortunately, the sidenote and marginnote commands don’t work in math environments (not in outer par mode). Most of the time, I’m able to work around it by putting the commands after the environment, using the optional offset with a decimal value via \marginnote[-length]{content}. But this breaks when a math environment is pushed to the end of a page: the notes are then pushed to the next page, no longer appearing on the same page. This also happens if you first put the commands and then the environment.

So, is there any way to enable sidenote and marginnote in math environments?
(I thought of using the samepage environment, but this adds a lot of ugly whitespace, as the whole math environment is pushed to the next page without necessity)

\documentclass{tufte-book}
\usepackage{amsmath}
\usepackage{lipsum}
\usepackage{tikz}

\newcommand{\filler}[1][10]%
{   \foreach \x in {1,...,#1}
{   test
}
}

\begin{document}

\lipsum[1]

\begin{align*}
&\int\int\int t\ dt^3\\
=&\int\int \frac{t^2}{2}\ dt^2\\
=&\int  \frac{t^3}{6}\ dt\\
=&\frac{t^4}{24}
\end{align*}\marginnote[-3.7cm]{first note}\marginnote[-1.7cm]{second note}

\lipsum[2]
\filler[50]

\begin{align*}
&\int\int\int t\ dt^3\\
=&\int\int \frac{t^2}{2}\ dt^2\\
=&\int  \frac{t^3}{6}\ dt\\
=&\frac{t^4}{24}
\end{align*}\marginnote[-3.7cm]{first note}\marginnote[-1.7cm]{second note}

\end{document}


As you can see, the second align* is still on the first page, but the marginnotes are pushed to the second page.

#### Solutions Collecting From Web of "using \marginnote inside a math environment in tufte-book"

The AMS environments conveniently give you a hook to place text at a known position relative to the margin so I’d do

\documentclass{tufte-book}
\usepackage{amsmath}
\usepackage{lipsum}
\usepackage{tikz}

\newcommand{\filler}[1][10]%
{   \foreach \x in {1,...,#1}
{   test
}
}

\def\mathnote#1{%
\tag*{\rlap{\hspace\marginparsep\smash{\parbox[t]{\marginparwidth}{%
\footnotesize#1}}}}
}

\begin{document}

\lipsum[1]

\begin{align*}
&\int\int\int t\ dt^3\\
=&\int\int \frac{t^2}{2}\ dt^2\\
=&\int  \frac{t^3}{6}\ dt\\
=&\frac{t^4}{24}
\end{align*}\marginnote[-3.7cm]{first note}\marginnote[-1.7cm]{second note}

\lipsum[2]
\filler[50]

\begin{align*}
&\int\int\int t\ dt^3\mathnote{first note}\\
=&\int\int \frac{t^2}{2}\ dt^2\\
=&\int  \frac{t^3}{6}\ dt\\
=&\frac{t^4}{24}\mathnote{second note}
\end{align*}

\end{document}