10

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}

enter image description here

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

David Carlisle
  • 757,742
Tom Bombadil
  • 40,123
  • I see three notes: the first "first note", the first "second note" and the second "second note". Where did the second "first note" end up? – Gus Jun 02 '21 at 17:51

1 Answers1

11

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}
David Carlisle
  • 757,742
  • Thank you, that's what I was looking for. Your code was missing a closing } in the mathnote definition, so I took the liberty to add it. – Tom Bombadil Jul 12 '12 at 14:26
  • 1
    After reading Aleander Perlis' A complement to \smash, \llap, and \rlap, I not only use your solution, but finally do understand it. Thanks again. – Tom Bombadil Sep 28 '12 at 16:41
  • +1! But just to be sure: This solution only works for the align environment and not for the equation environment? At least it failed in what I tested. –  Jan 21 '18 at 20:35
  • @flobo equation* works if you fix the definition by adding \kern1sp before the \rlap – David Carlisle Jan 21 '18 at 20:50
  • 1
    @DavidCarlisle: Coincidentally, I was searching the answer to flobo's very question, only 24h after they asked. In any case, it seems that adding the \kern does not break \mathnote in align environments. If that does make sense, maybe it'd be better to have it defined with the \kern in your answer? Would you mind explaining what's happening with it? Cheers! – Michaël Jan 23 '18 at 19:04
  • @Michaël unlike align, equation uses the primitive tex ($$) equation number positioning, that has special rules for zero width labels (a trigger to move it after the equation) 1sp is an impossibly small length to measure, bit being non zero it forces equation to take the "normal" code path. – David Carlisle Jan 23 '18 at 19:39
  • Is there a solution to invoke the correct command based on which environment it is in, using, e.g. LaTeX's \@currenvir? See https://tex.stackexchange.com/a/18655/1362 – Gus Jun 02 '21 at 21:11