# How to modify fonts in sidenotes?

I want to change how the font of the sidenotes appears. For this I modified \marginfont and I am getting the desired results. In particular, this works well with \marginnote{} and with \sidenote{} but with a caveat. It only works with the sidenotes when I give a concrete offset value. That is it the formatting of text works only if I give \sidenote[][0cm]{}.

If I do not provide an offset in a given sidenote, it reverts to the normal font, and a new numbering is started. I would like to know why this is happening and how can one set formatting for sidenotes without offset too.

MWE is appended below

\documentclass{article}

\usepackage{sidenotes}

\renewcommand*{\marginfont}{\small\sffamily}

\begin{document}

Furthermore, they were emboldened to play a game of  hide and seek with the imperialists whom they harassed incessantly by plundering their convoys and by interrupting their lines of communication. Status quo came from or how it should be changed. \sidenote[1][0pt]{This is a sidenote, which is set with offset of 0pt. And the formatting is correct.}

Furthermore, they were emboldened to play a game of  hide and seek with the imperialists whom they harassed incessantly by plundering their convoys and by interrupting their lines of communication. Status quo came from or how it should be changed.

Furthermore, they were emboldened to play a game of  hide and seek with the imperialists whom they harassed incessantly by plundering their convoys and by interrupting their lines of communication. Status quo came from or how it should be changed. \sidenote{This is a sidenote with no offset, and the formatting doesn't work here, neither does the numbering.}

Furthermore, they were emboldened to play a game of  hide and seek with the imperialists whom they harassed incessantly by plundering their convoys and by interrupting their lines of communication. Status quo came from or how it should be changed.Furthermore, they were emboldened to play a game of  hide and seek with the imperialists whom they harassed incessantly by plundering their convoys and by interrupting their lines of communication. Status quo came from or how it should be changed.

Furthermore, they were emboldened to play a game of  hide and seek with the imperialists whom they harassed incessantly by plundering their convoys and by interrupting their lines of communication. Status quo came from or how it should be changed.\marginnote{This is a margin note with correct formatting.}

Furthermore, they were emboldened to play a game of  hide and seek with the imperialists whom they harassed incessantly by plundering their convoys and by interrupting their lines of communication. Status quo came from or how it should be changed.\sidenote{This is a sidenote with no offset, and the formatting doesn't work here, and this has its own numbering.}

Furthermore, they were emboldened to play a game of  hide and seek with the imperialists whom they harassed incessantly by plundering their convoys and by interrupting their lines of communication. Status quo came from or how it should be changed.

Furthermore, they were emboldened to play a game of  hide and seek with the imperialists whom they harassed incessantly by plundering their convoys and by interrupting their lines of communication. Status quo came from or how it should be changed.\sidenote[][1cm]{This is a side note with offset again and formatting works.}

\end{document}


This may be a bug of sidenotes package, v1.00.

• If the second optional argument of \sidenote is not given or empty, then \sidenote expands to \marginpar, which is defined by latex2e format.
• Otherwise, \sidenote expands to \marginnote, which is defined by marginnote package.
• \marginfont is used by \marginnote, but not \marginpar. Therefore the font of \sidenote{...} or \sidenote[...][]{...} is not effected by \marginfont.

The following lines make \sidenote uniformly use \marginnote, hence fixes the problem:

\makeatletter
\ExplSyntaxOn
\RenewDocumentCommand \@sidenotes@placemarginal { m m }
{
\IfNoValueOrEmptyTF{#1}
% substitue \marginnote from marginnote pkg for \marginpar
% from latex2e format
{\marginnote{#2}}
{\marginnote{#2}[#1]}
}
\ExplSyntaxOff
\makeatother

• Nice! Good catch – DG' Mar 11 at 22:12

Disclaimer: I am the author of the sidenotespackage and certainly biased ;)

I was facing the same issue some time ago and asked a similar question here. However, the answer was intentionally not included in the sidenotes package, since it manipulates a LaTeX macro with possible side effects. Always using \marginnote only works for scarcely populated margins. Otherwise, they will start to overlap. Invoking the marginfix package is always a good idea as well.

However, the example caesar.cls is included in the sidenotes package. If you use \documentclass{caesar_book} you can see, if it addresses your issue (it does in this case). Afterwards, you can decide whether you want to copy the code fragment.

On a sidenote (pun intended), you might want to consider the xparse solution. From todays perspective, I would prefer it and might change it in the next version of caesar.cls.

Copy of the relevant code from the other answer (credit to egreg):

\usepackage{xparse}
\let\oldmarginpar\marginpar
\RenewDocumentCommand{\marginpar}{om}{%
\IfNoValueTF{#1}
{\oldmarginpar{\mymparsetup #2}}
{\oldmarginpar[\mymparsetup #1]{\mymparsetup #2}}}

\newcommand{\mymparsetup}{\itshape}