2

I'd like to change the size of my sidenote text to \footnotesize. Why can't I just redefine \sidenotetext with \footnotesize where I need it, as below?

    \documentclass{article}
    \usepackage[utf8]{inputenc}
    \usepackage{sidenotes}

\makeatletter
    \RenewDocumentCommand \sidenotetext { o o +m }
    {
        \IfNoValueOrEmptyTF{#1}
            {
            \@sidenotes@placemarginal{#2}{\textsuperscript{\thesidenote}{}~#3}
        \refstepcounter{sidenote}
    }
            {\@sidenotes@placemarginal{#2}{\footnotesize\textsuperscript{#1}\footnotesize~#3}}
    }
\makeatother    

\begin{document}

Hello\sidenote{Hi}

\end{document}
  • \IfNoValueOrEmptyTF? Ah, that's an invention by sidenotes package. You're missing a \makeatletter...\makeatother pair –  Apr 01 '17 at 15:22
  • @Dr.ManuelKuehner: I think it is because the \@sidenotes.... macros expand somewhere else so \makeatletter isn't needed actually –  Apr 01 '17 at 15:39
  • @ChristianHupfer You are right...as usual. – Dr. Manuel Kuehner Apr 01 '17 at 15:41
  • @Dr.ManuelKuehner: :D ... but \makeatletter...\makeatother does not harm here anyway. –  Apr 01 '17 at 15:42

2 Answers2

4

You should/could have mentioned that you use the original definition from the sidenotes package and try to change the definition of one of the commands using the functionality of the xparse package which is loaded automatically with the sidenotes package.

I replaced \@sidenotes@placemarginal{#2}{\textsuperscript{\thesidenote}{}~#3} with \@sidenotes@placemarginal{#2}{\textsuperscript{\thesidenote}{}~\footnotesize#3} (added \footnotesize before #3).

In addition, thanks to Christian Hupfer, you need to enclose the definition with \makeatletter...\makeatother since the code uses the @ symbol in the not literal way (see What do \makeatletter and \makeatother do?).

\documentclass{article}

\usepackage{sidenotes}
%% Loads the following packages
% marginnote
% caption
% xparse
% l3keys2e
% changepage

%%% From the sidenotes documentation
%% \sidenote
%% Uses \sidenotetext
%\NewDocumentCommand\sidenote { o o +m }
%{
%\sidenotemark[#1]
%\sidenotetext[#1][#2]{#3}
%\@sidenotes@multimarker
%}
%
%% \sidenotetext
%% Used in \sidenote
%\NewDocumentCommand \sidenotetext { o o +m }
%{
%\IfNoValueOrEmptyTF{#1}
%{
%\@sidenotes@placemarginal{#2}{\textsuperscript{\thesidenote}{}~#3}
%\refstepcounter{sidenote}
%}
%{\@sidenotes@placemarginal{#2}{\textsuperscript{#1}~#3}}
%}

% \sidenotetext
% Used in \sidenote
% Changed to meet the question of user J. Bratt (https://tex.stackexchange.com/questions/361622).
\makeatletter
\RenewDocumentCommand\sidenotetext{ o o +m }{%      
    \IfNoValueOrEmptyTF{#1}{%
        \@sidenotes@placemarginal{#2}{\textsuperscript{\thesidenote}{}~\footnotesize#3}%
        \refstepcounter{sidenote}%
    }{%
        \@sidenotes@placemarginal{#2}{\textsuperscript{#1}~#3}%
    }%
}
\makeatother

\begin{document}

Hello\sidenote{Hi}

\end{document}
dexteritas
  • 9,161
  • 1
    So do I understand that correctly, if I'm just using sidenotes, and I want to for example change the font size of a \marginpar{...} in my text, it is really that complicated? – Ela782 May 09 '17 at 17:41
  • 1
    I recommend using this in conjunction with the marginfix package, which takes care in case you have several long sidenotes that exceed the length of the page. – Praveen Aug 20 '18 at 13:30
1

I changed the logical query a little bit, using the ordinary \IfValueTF{#1}{}{}.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{sidenotes}



\makeatletter
\RenewDocumentCommand\sidenotetext{oo+m}{%
  \IfValueTF{#1}{%
    \@sidenotes@placemarginal{#2}{\footnotesize\textsuperscript{#1}\footnotesize~#3}
  }{%
    \@sidenotes@placemarginal{#2}{\textsuperscript{\thesidenote}{}~#3}%
    \refstepcounter{sidenote}%
  }%
}
\makeatother


\begin{document}

Hello\sidenote[foo]{Hi}

Hello\sidenote{Hi again}

\end{document}

enter image description here