# Prevent marginnote from creating extra paragraph

I use the marginnote package to create, well, margin notes. However, I observe some unwanted behavior when adding a note directly after a section heading, or between section headings. It seems like the command creates an empty paragraph, which is undesired, since it leads to extra whitespace or indentation.

MWE:

\documentclass{article}
\usepackage{marginnote}

\begin{document}

\section{Testsection}
\marginnote{Oops! Some extra whitespace.}
\subsection{Testsubsection}
But at least no indentation.

\section{Testsection2}
\subsection{Testsubsection2}
\marginnote{hi there!}Some extra indentation

\section{Testsection3}
\subsection{Testsubsection3}
Nothing \marginnote{Move along.} to see here.

\section{Testsection4}
\subsection{Testsubsection4}
\leavevmode\marginnote{Move along.}This also works.

\end{document}


Creates

I have read \marginnote leads to paragraph indentation, so I know about the \leavevmode solution. However, this does not fix the first case (adding extra whitespace when between section headings).

Is there a way to define a command that will always keep marginnote from creating extra paragraphs, so I can use it where I want without thinking about it?

• This kludge will fix it: \section[Testsection]{Testsection\protect\marginnote{\normalsize\mdseries No extra whitespace.}} – Steven B. Segletes Jun 17 '16 at 13:38

It seems like marginnote really wants to be used mid paragraph, but this works:

\documentclass{article}
\usepackage{marginnote}

\begin{document}

\section[Testsection]{Testsection\marginnote{\normalsize\normalfont
Oops! Some extra whitespace.}}
\subsection{Testsubsection}
But at least no indentation.

\section{Testsection2}
\subsection{Testsubsection2}
%a marginpar bug \marginnote{hi there!}Some extra indentation
Some\marginnote{hi there!} extra indentation

\section{Testsection3}
\subsection{Testsubsection3}
Nothing \marginnote{Move along.} to see here.

\section{Testsection4}
\subsection{Testsubsection4}
\leavevmode\marginnote{Move along.}This also works.

\end{document}

• I beat you by a minute with my comment, but +1 anyhow – Steven B. Segletes Jun 17 '16 at 13:40
• Thanks, but I'd rather do \newcommand{\robustmarginnote}[1]{\domagic\marginnote{#1}}, so I can use robustmarginnote wherever I want. But maybe domagic doesn't exist, in which case your answer is of course correct. – Dion Jun 17 '16 at 13:45