# Missing number, treated as zero when using renewcommand

I am trying to temporarily get read of marginpars in my paper.

I tried to simply \renewcommand{\marginpar}[]{} but I get:

! Missing number, treated as zero.<to be read again>} \renewcommand{\marginpar}[]{}

I don't know why I am getting this error since it usually compiles my pdf without errors. Do you guys have any idea?

• @moewe that did it. Thanks for that. Please post as an answer with the explanations. Will accept right away :) – LBes Nov 21 '18 at 16:43

In order to get rid of \marginpar properly (assuming its usual definition) you will want to try

\renewcommand{\marginpar}[2][]{}


\newcommand{<command>}[<number of arguments>][<optional value>]{<definition>}

where the both arguments in square brackets are optional - if there is only one optional argument it is interpreted as the first optional argument.

<number of arguments> gives the number of arguments <command> accepts and must be a number if it is present. That is what caused the error in your example, it is not acceptable to leave the square brackets empty. If additional <optional value> is present, the first argument of <command> becomes optional and is assumed to be <optional value> if it is not present (optional arguments are commonly given in square brackets, mandatory arguments in curly brackets).

This means that commands defined with \(re)newcommand will always have one of the following argument structures

\foo                    % no argument at all
\foo{m_1}               % one mandatory argument
\foo[o_1]               % one optional argument
\foo{m_1}{m_2}...{m_n}  % n \leq 9, two to nine mandatory arguments
\foo[o_1]{m_1}...{m_n}  % n \leq 8, one optional argument and one to eight mandatory arguments

Other argument structures are possible in (La)TeX, but they have to be coded differently. Ironically, \newcommand itself uses a very different structure.

\marginpar has the following argument specification

\marginpar[<LTEXT>]{<RTEXT>}

which means that its structure can be redefined with \renewcommand directly as a macro with two arguments of which the first is optional.

Ulrich Diez made a good point in the comments that one needs to be careful about the spacing. The default definition of \marginpar uses \@bsphack...\@esphack to avoid unwanted white space, see How to make a command completely empty / invisible / non-existent?. If you want to replicate that behaviour to not change spacing when you disable \marginpar, you'll need the more involved

\makeatletter
\renewcommand{\marginpar}[2][]{\@bsphack\@esphack}
\makeatother

Whether or not that is necessary will depend on how exactly you used \marginpar and what your requirements and intentions are for disabling it. If it's just for a quick test you needn't bother, if it's for the final print version that's a different matter.

• Thanks for the recap. Very nice answer. Answer accepted! – LBes Nov 21 '18 at 17:01
• @UlrichDiez Ah yes, thanks for the hint. Added a short edit. – moewe Nov 21 '18 at 21:30