1

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?

Thanks in advance

  • You'll want to try \renewcommand{\marginpar}[2][]{}. The first optional argument gives the number of arguments the (re)defined command has. If there is a second optional argument to \(re)newcommand the first argument of the (re)defined command is optional. You may leave out the first optional argument (it is optional after all), but if it is present it must be a number. \marginpar has two arguments: An optional one and a mandatory one in that order, hence [2][] does what you need. – moewe Nov 21 '18 at 16:32
  • tex.stackexchange.com/q/117358/107497 and tex.stackexchange.com/q/280527/107497 are similar questions about \newcommand. \renewcommand has the same syntax. – Teepeemm Nov 21 '18 at 16:32
  • @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
2

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

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

The exact syntax of \(re)newcommand has been explained elsewhere (for example in \newcommand argument confusion) far better than I could, so let me just recap shortly that the usual syntax for \(re)newcommand is

\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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.