fmarotta / kaobook

A LaTeX class for books, reports or theses based on https://github.com/kenohori/thesis and https://github.com/Tufte-LaTeX/tufte-latex.
https://github.com/fmarotta/kaobook
LaTeX Project Public License v1.3c
858 stars 184 forks source link

vertical alignment of `marginnote` on display equation #151

Closed goretkin closed 3 years ago

goretkin commented 3 years ago

Prerequisites

Description

The vertical alignment of a \marginnote with a display equation is unexpected.

Minimal Working Example

\documentclass{kaobook}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{kaobiblio}
\usepackage{kaotheorems}
\usepackage{kaorefs}

\begin{document}

\title{Bug Report}
\author{Author}
\date{\today}

\frontmatter

\KOMAoptions{twoside=semi}
\maketitle
\KOMAoptions{twoside=false}

\mainmatter
\setchapterstyle{kao}

This sentence ends with math:
\begin{equation*}
    V(P)[i] = V(P)[i-1] \cup V(P[i]) \,, i = 1, \cdots, n \,.
\end{equation*}
\marginnote{a marginnote}

This sentence ends with math:
\begin{equation*}
    V(P)[i] = V(P)[i-1] \cup V(P[i]) \,, i = 1, \cdots, n \,.
\end{equation*}
\marginpar{a marginpar}

This sentence ends with math:
\begin{equation*}
    V(P)[i] = \frac{1}{2} \sum_{i=1}^{n} x_{i} \,.
\end{equation*}
\marginnote{taller equation}

% https://tex.stackexchange.com/questions/63012/using-marginnote-inside-a-math-environment-in-tufte-book
\def\mathnotealign#1{%
  \tag*{\rlap{\hspace\marginparsep\smash{\parbox[t]{\marginparwidth}{%
  \footnotesize#1}}}}
}

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

This sentence ends with math:
\begin{equation*}
    V(P)[i] = \frac{1}{2} \sum_{i=1}^{n} x_{i} \,.
    \mathnoteeqn{a note within}
\end{equation*}

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

The same two environments, but with the notes messed up:

\begin{equation*}
    V(P)[i] = \frac{1}{2} \sum_{i=1}^{n} x_{i} \,.
    \mathnotealign{a note within}
\end{equation*}

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

\end{document}

Expected behavior: The margin note begins on the same line as the equation environment.

Actual behavior: The margin note begins after the end of the equation environment:

image

Additional Information

This issue also occurs with \documentclass{article} and \usepackage{marginnote}, so it is not specific to kaobook or KOMA-script, but it would be nice to have a solution.

I copied the \mathnoteeqn and \mathnotealign definitions from tex.stackexchange. Ideally one definition would suffice, but the comments on the answer suggest using two different definitions depending on which environment the note is in.

fmarotta commented 3 years ago

Hi, if the problem occurs with the article class as well, I think tex.stackexchange.com would be a better place for this question :)