9

Under certain conditions (triggered by selection of a package option) I would like to change specific environments into margin notes. However marginnote is not itself an environment, but a command that takes its contents as an argument. So what I want to do is replace

\begin{someenvironment}
...
\end{someenvironment}

with

\marginnote{
...
}

but I clearly cannot do this with something like

\renewenvironment{someenvironment}
    {\marginnote{ }
    { }}

What is the correct way to replace an environment with a command that takes the environment's contents as an argument?

10

The environ package may be of help here. You define an environment using

\NewEnviron{<env>}{%
  % environment contents
}

and the contents of the environment is available in the macro \BODY. Here's a minimal example:

enter image description here

\documentclass{article}
\usepackage{marginnote}% http://ctan.org/pkg/marginnote
\usepackage{environ}% http://ctan.org/pkg/environ
\NewEnviron{someenvironment}{%
  \marginnote{\BODY}% Place contents of <someenvironment> in a \marginnote
}
\begin{document}
Here is some text with a margin note.
\begin{someenvironment}
This is a margin note.
\end{someenvironment}
\end{document}
​

\NewEnviron has a macro-like look to it, so the usage should be fairly intuitive.

  • Thanks, that worked, thigh it ended up begin a bit more complicated in my case. I'm redefining an already defined environment, and end up with a lot of floats, so I had to \usepackage[maxfloats=36]{morefloats} and \let\existingenv ... \NewEnviron{existingenv}.... – orome Feb 21 '12 at 22:25

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.