14

Is there a way to change the font, font size and so on for \marginpar with a standard LaTeX macro, i.e. without something such as \let\oldmarginpar\marginpar (cp. Problem with Customized Marginpar (in Combination With a ToMarginpar). The \marginnote package e.g. provides \marginfont.

MWE:

\documentclass{book}

\begin{document}
Text text text\marginpar{A short note.}
\end{document}
Andy
  • 6,269

2 Answers2

9

The easiest way is with \RenewDocumentCommand:

\NewCommandCopy{\oldmarginpar}{\marginpar}
\RenewDocumentCommand{\marginpar}{om}{%
  \IfNoValueTF{#1}
    {\oldmarginpar{\mymparsetup #2}}
    {\oldmarginpar[\mymparsetup #1]{\mymparsetup #2}}}

\newcommand{\mymparsetup}{\itshape}

In the \mymparsetup command you can put all customizations you want. In this way we can keep the behavior with the optional argument to \marginpar.

Note: see edit history for the older version with \let.

egreg
  • 1,121,712
  • @MarcoDaniel I don't see why: if one does the right redefinition, there's no problem. :) – egreg Jun 02 '12 at 13:01
  • 1
    I thought that using \let has the side effect of losing the ability to have optional arguments. But your \oldmarginpar can still parse the leading []? – Andy Jun 02 '12 at 13:08
  • 1
    @Andy: You can use the let operation for commands with optional argument. However a more robust way is to use \LetLtxMacro provided by the package letltxmacro. – Marco Daniel Jun 02 '12 at 13:14
  • 1
    @Andy Actually \marginpar has no argument. I'll add something to my answer. – egreg Jun 02 '12 at 13:16
7

To print out a margin the contents will be save in a savebox. So you can manipulate the default implementation of latex.ltx which is as follows:

\long\def\@ympar#1{%
  \@savemarbox\@marbox{#1}%
  \global\setbox\@currbox\copy\@marbox
  \@xympar}

The mandatory argument is the contents. So simple use:

\long\def\@ympar#1{%
  \@savemarbox\@marbox{\tiny #1}%
  \global\setbox\@currbox\copy\@marbox
  \@xympar}

Based on the special symbol @ you have to use \makeatletter...\makeatother.

Marco Daniel
  • 95,681